"Fossies" - the Fresh Open Source Software Archive

Member "getmail-5.16/getmailcore/compatibility.py" (31 Oct 2021, 2442 Bytes) of package /linux/misc/getmail-5.16.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "compatibility.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.15_vs_5.16.

    1 #!/usr/bin/env python2
    2 '''Compatibility class declarations used elsewhere in the package.
    3 
    4 '''
    5 
    6 __all__ = [
    7     'set',
    8     'frozenset',
    9 ]
   10 
   11 import sys
   12 import imaplib
   13 import new
   14 
   15 
   16 if sys.version_info < (2, 4, 0):
   17     # set/frozenset not built-in until Python 2.4
   18     import sets
   19     set = sets.Set
   20     frozenset = sets.ImmutableSet
   21 set = set
   22 frozenset = frozenset
   23 
   24 
   25 if sys.version_info < (2, 5, 0):
   26     # Python < 2.5.0 has a bug with the readonly flag on imaplib's select().
   27     # Monkey-patch it in.
   28 
   29     def py25_select(self, mailbox='INBOX', readonly=False):
   30         """Select a mailbox.
   31 
   32         Flush all untagged responses.
   33 
   34         (typ, [data]) = <instance>.select(mailbox='INBOX', readonly=False)
   35 
   36         'data' is count of messages in mailbox ('EXISTS' response).
   37 
   38         Mandated responses are ('FLAGS', 'EXISTS', 'RECENT', 'UIDVALIDITY'), so
   39         other responses should be obtained via <instance>.response('FLAGS') etc.
   40         """
   41         self.untagged_responses = {}    # Flush old responses.
   42         self.is_readonly = readonly
   43         if readonly:
   44             name = 'EXAMINE'
   45         else:
   46             name = 'SELECT'
   47         typ, dat = self._simple_command(name, mailbox)
   48         if typ != 'OK':
   49             self.state = 'AUTH'     # Might have been 'SELECTED'
   50             return typ, dat
   51         self.state = 'SELECTED'
   52         if 'READ-ONLY' in self.untagged_responses \
   53                 and not readonly:
   54             if __debug__:
   55                 if self.debug >= 1:
   56                     self._dump_ur(self.untagged_responses)
   57             raise self.readonly('%s is not writable' % mailbox)
   58         return typ, self.untagged_responses.get('EXISTS', [None])
   59 
   60     imaplib.IMAP4.select = new.instancemethod(py25_select, None, imaplib.IMAP4)
   61 
   62 
   63 if sys.version_info < (2, 5, 3):
   64     # A serious imaplib bug (http://bugs.python.org/issue1389051) was
   65     # fixed in 2.5.3.  Earlier Python releases need a work-around.
   66     # Monkey-patch it in.
   67     def fixed_read(self, size):
   68         """Read 'size' bytes from remote."""
   69         # sslobj.read() sometimes returns < size bytes
   70         chunks = []
   71         read = 0
   72         while read < size:
   73             data = self.sslobj.read(min(size-read, 16384))
   74             read += len(data)
   75             chunks.append(data)
   76         return ''.join(chunks)
   77 
   78     imaplib.IMAP4_SSL.read = new.instancemethod(fixed_read, None, 
   79                                                 imaplib.IMAP4_SSL)