Changeset 90:5ac3ccadb5fc

Show
Ignore:
Timestamp:
12/18/09 17:17:30 (9 months ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

use double quotes instead of single quotes in triple-quoted strings to keep Emacs happy

Location:
imapclient
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • imapclient/imapclient.py

    r87 r90  
    2525 
    2626class IMAPClient(object): 
    27     ''' 
     27    """ 
    2828    A Pythonic, easy-to-use IMAP client class. 
    2929 
     
    5757    These are aliases for the imaplib.IMAP4 exceptions of the same name. Socket 
    5858    errors may also be raised in the case of network errors. 
    59     ''' 
     59    """ 
    6060 
    6161    Error = imaplib.IMAP4.error 
     
    6969 
    7070    def __init__(self, host, port=None, use_uid=True, ssl=False): 
    71         '''Initialise object instance and connect to the remote IMAP server. 
     71        """Initialise object instance and connect to the remote IMAP server. 
    7272 
    7373        @param host: The IMAP server address/hostname to connect to. 
     
    7575        @param use_uid: Should message UIDs be used (default is True). 
    7676        @param ssl: Make an SSL connection (default is False) 
    77         ''' 
     77        """ 
    7878        if ssl: 
    7979            ImapClass = imaplib.IMAP4_SSL 
     
    9292    
    9393    def login(self, username, password): 
    94         '''Perform a simple login 
    95         ''' 
     94        """Perform a simple login 
     95        """ 
    9696        typ, data = self._imap.login(username, password) 
    9797        self._checkok('login', typ, data) 
     
    100100 
    101101    def logout(self): 
    102         '''Perform a logout 
    103         ''' 
     102        """Perform a logout 
     103        """ 
    104104        typ, data = self._imap.logout() 
    105105        self._checkbye('logout', typ, data) 
     
    108108 
    109109    def capabilities(self): 
    110         '''Returns the server capability list 
    111         ''' 
     110        """Returns the server capability list 
     111        """ 
    112112        return self._imap.capabilities 
    113113 
    114114 
    115115    def has_capability(self, capability): 
    116         '''Checks if the server has the given capability. 
     116        """Checks if the server has the given capability. 
    117117 
    118118        @param capability: capability to test (eg 'SORT') 
    119         ''' 
     119        """ 
    120120        # FIXME: this will not detect capabilities that are backwards 
    121121        # compatible with the current level. For instance the SORT 
     
    129129 
    130130    def get_folder_delimiter(self): 
    131         '''Determine the folder separator used by the IMAP server. 
     131        """Determine the folder separator used by the IMAP server. 
    132132 
    133133        @return: The folder separator. 
    134134        @rtype: string 
    135         ''' 
     135        """ 
    136136        typ, data = self._imap.namespace() 
    137137        self._checkok('namespace', typ, data) 
     
    145145 
    146146    def list_folders(self, directory="", pattern="*"): 
    147         '''Get a listing of folders on the server. 
     147        """Get a listing of folders on the server. 
    148148 
    149149        The default behaviour (no args) will list all folders for the logged in 
     
    157157            decoding). If the folder_encode attribute is False, no decoding 
    158158            will be performed and only ordinary strings will be returned. 
    159         ''' 
     159        """ 
    160160        typ, data = self._imap.list(directory, pattern) 
    161161        self._checkok('list', typ, data) 
     
    177177 
    178178    def list_sub_folders(self, directory="", pattern="*"): 
    179         '''Get a listing of subscribed folders on the server. 
     179        """Get a listing of subscribed folders on the server. 
    180180 
    181181        The default behaviour (no args) will list all subscribed folders for the 
     
    186186            names matching this pattern will be returned. Wildcards accepted. 
    187187        @return: A list of folder names. As per the return of list_folders(). 
    188         ''' 
     188        """ 
    189189        typ, data = self._imap.lsub(directory, pattern) 
    190190        self._checkok('lsub', typ, data) 
     
    200200 
    201201    def select_folder(self, folder): 
    202         '''Select the current folder on the server. Future calls to methods 
     202        """Select the current folder on the server. Future calls to methods 
    203203        such as search and fetch will act on the selected folder. 
    204204 
     
    206206        @return: Number of messages in the folder. 
    207207        @rtype: long int 
    208         ''' 
     208        """ 
    209209        typ, data = self._imap.select(self._encode_folder_name(folder)) 
    210210        self._checkok('select', typ, data) 
     
    213213 
    214214    def folder_status(self, folder, what=None): 
    215         '''Requests the status from folder. 
     215        """Requests the status from folder. 
    216216 
    217217        @param folder: The folder name. 
     
    221221            the items specified in the what parameter. 
    222222        @rtype: dict 
    223         ''' 
     223        """ 
    224224        if what is None: 
    225225            what = ('MESSAGES', 'RECENT', 'UIDNEXT', 'UIDVALIDITY', 'UNSEEN') 
     
    245245 
    246246    def close_folder(self): 
    247         '''Close the currently selected folder. 
     247        """Close the currently selected folder. 
    248248 
    249249        @return: Server response. 
    250         ''' 
     250        """ 
    251251        typ, data = self._imap.close() 
    252252        self._checkok('close', typ, data) 
     
    255255 
    256256    def create_folder(self, folder): 
    257         '''Create a new folder on the server. 
     257        """Create a new folder on the server. 
    258258 
    259259        @param folder: The folder name. 
    260260        @return: Server response. 
    261         ''' 
     261        """ 
    262262        typ, data = self._imap.create(self._encode_folder_name(folder)) 
    263263        self._checkok('create', typ, data) 
     
    266266 
    267267    def delete_folder(self, folder): 
    268         '''Delete a new folder on the server. 
     268        """Delete a new folder on the server. 
    269269 
    270270        @param folder: Folder name to delete. 
    271271        @return: Server response. 
    272         ''' 
     272        """ 
    273273        typ, data = self._imap.delete(self._encode_folder_name(folder)) 
    274274        self._checkok('delete', typ, data) 
     
    277277 
    278278    def folder_exists(self, folder): 
    279         '''Determine if a folder exists on the server. 
     279        """Determine if a folder exists on the server. 
    280280 
    281281        @param folder: Full folder name to look for. 
    282282        @return: True if the folder exists. False otherwise. 
    283         ''' 
     283        """ 
    284284        typ, data = self._imap.list('', self._encode_folder_name(folder)) 
    285285        self._checkok('list', typ, data) 
     
    288288 
    289289    def subscribe_folder(self, folder): 
    290         '''Subscribe to a folder. 
     290        """Subscribe to a folder. 
    291291 
    292292        @param folder: Folder name to subscribe to. 
    293293        @return: Server response message. 
    294         ''' 
     294        """ 
    295295        typ, data = self._imap.subscribe(self._encode_folder_name(folder)) 
    296296        self._checkok('subscribe', typ, data) 
     
    299299 
    300300    def unsubscribe_folder(self, folder): 
    301         '''Unsubscribe a folder. 
     301        """Unsubscribe a folder. 
    302302 
    303303        @param folder: Folder name to unsubscribe. 
    304304        @return: Server response message. 
    305         ''' 
     305        """ 
    306306        typ, data = self._imap.unsubscribe(self._encode_folder_name(folder)) 
    307307        self._checkok('unsubscribe', typ, data) 
     
    332332 
    333333    def sort(self, sort_criteria, criteria='ALL', charset='UTF-8' ): 
    334         '''Returns a list of messages sorted by sort_criteria. 
     334        """Returns a list of messages sorted by sort_criteria. 
    335335 
    336336        Note that this is an extension to the IMAP4: 
    337337        http://www.ietf.org/internet-drafts/draft-ietf-imapext-sort-19.txt 
    338         ''' 
     338        """ 
    339339        if not criteria: 
    340340            raise ValueError('no criteria specified') 
     
    361361 
    362362    def get_flags(self, messages): 
    363         '''Return the flags set for messages 
     363        """Return the flags set for messages 
    364364 
    365365        @param messages: Message IDs to check flags for 
    366366        @return: As for add_f 
    367367            { msgid1: [flag1, flag2, ... ], } 
    368         ''' 
     368        """ 
    369369        response = self.fetch(messages, ['FLAGS']) 
    370370        return self._flatten_dict(response) 
     
    372372 
    373373    def add_flags(self, messages, flags): 
    374         '''Add one or more flags to messages 
     374        """Add one or more flags to messages 
    375375 
    376376        @param messages: Message IDs to add flags to 
     
    378378        @return: The flags set for each message ID as a dictionary 
    379379            { msgid1: [flag1, flag2, ... ], } 
    380         ''' 
     380        """ 
    381381        return self._store('+FLAGS', messages, flags) 
    382382 
    383383 
    384384    def remove_flags(self, messages, flags): 
    385         '''Remove one or more flags from messages 
     385        """Remove one or more flags from messages 
    386386 
    387387        @param messages: Message IDs to remove flags from 
    388388        @param flags: Sequence of flags to remove 
    389389        @return: As for get_flags. 
    390         ''' 
     390        """ 
    391391        return self._store('-FLAGS', messages, flags) 
    392392 
    393393 
    394394    def set_flags(self, messages, flags): 
    395         '''Set the flags for messages 
     395        """Set the flags for messages 
    396396 
    397397        @param messages: Message IDs to set flags for 
    398398        @param flags: Sequence of flags to set 
    399399        @return: As for get_flags. 
    400         ''' 
     400        """ 
    401401        return self._store('FLAGS', messages, flags) 
    402402 
    403403 
    404404    def delete_messages(self, messages): 
    405         '''Short-hand method for deleting one or more messages 
     405        """Short-hand method for deleting one or more messages 
    406406 
    407407        @param messages: Message IDs to mark for deletion. 
    408408        @return: Same as for get_flags. 
    409         ''' 
     409        """ 
    410410        return self.add_flags(messages, DELETED) 
    411411 
    412412 
    413413    def fetch(self, messages, parts): 
    414         '''Retrieve selected data items for one or more messages. 
     414        """Retrieve selected data items for one or more messages. 
    415415 
    416416        @param messages: Message IDs to fetch. 
     
    420420            INTERNALDATE parts will be returned as datetime objects converted 
    421421            to the local machine's time zone. 
    422         ''' 
     422        """ 
    423423        if not messages: 
    424424            return {} 
     
    438438 
    439439    def append(self, folder, msg, flags=(), msg_time=None): 
    440         '''Append a message to a folder 
     440        """Append a message to a folder 
    441441 
    442442        @param folder: Folder name to append to. 
     
    451451        @return: The append response returned by the server. 
    452452        @rtype: str 
    453         ''' 
     453        """ 
    454454        if msg_time: 
    455455            time_val = '"%s"' % datetime_to_imap(msg_time) 
     
    473473 
    474474    def getacl(self, folder): 
    475         '''Get the ACL for a folder 
     475        """Get the ACL for a folder 
    476476 
    477477        @param folder: Folder name to get the ACL for. 
    478478        @return: A list of (who, acl) tuples 
    479         ''' 
     479        """ 
    480480        typ, data = self._imap.getacl(folder) 
    481481        self._checkok('getacl', typ, data) 
     
    491491 
    492492    def setacl(self, folder, who, what): 
    493         '''Set an ACL for a folder 
     493        """Set an ACL for a folder 
    494494 
    495495        @param folder: Folder name to set an ACL for. 
     
    497497        @param what: A string describing the ACL. Set to '' to remove an ACL. 
    498498        @return: Server response string. 
    499         ''' 
     499        """ 
    500500        typ, data = self._imap.setacl(folder, who, what) 
    501501        self._checkok('setacl', typ, data) 
     
    504504 
    505505    def _check_resp(self, expected, command, typ, data): 
    506         '''Check command responses for errors. 
     506        """Check command responses for errors. 
    507507 
    508508        @raise: Error if a command failed. 
    509         ''' 
     509        """ 
    510510        if typ != expected: 
    511511            raise self.Error('%s failed: %r' % (command, data[0])) 
     
    521521 
    522522    def _store(self, cmd, messages, flags): 
    523         '''Worker function for flag manipulation functions 
     523        """Worker function for flag manipulation functions 
    524524 
    525525        @param cmd: STORE command to use (eg. '+FLAGS') 
     
    528528        @return: The flags set for each message ID as a dictionary 
    529529            { msgid1: [flag1, flag2, ... ], } 
    530         ''' 
     530        """ 
    531531        if not messages: 
    532532            return {} 
     
    563563 
    564564class FetchParser(object): 
    565     ''' 
     565    """ 
    566566    Parse an IMAP FETCH response and convert the return values to useful Python 
    567567    values. 
    568     ''' 
     568    """ 
    569569 
    570570    def parse(self, response): 
     
    634634 
    635635    def do_INTERNALDATE(self, arg): 
    636         '''Process an INTERNALDATE response 
     636        """Process an INTERNALDATE response 
    637637 
    638638        @param arg: A quoted IMAP INTERNALDATE string 
    639639            (eg. " 9-Feb-2007 17:08:08 +0000") 
    640640        @return: datetime.datetime instance for the given time (in UTC) 
    641         ''' 
     641        """ 
    642642        arg = 'INTERNALDATE "%s"' % arg 
    643643        mo = imaplib.InternalDate.match(arg) 
     
    669669 
    670670class FetchTokeniser(object): 
    671     ''' 
     671    """ 
    672672    General response tokenizer and converter 
    673     ''' 
     673    """ 
    674674 
    675675    QUOTED_STRING = '(?:".*?")' 
     
    691691 
    692692    def process_pairs(self, s): 
    693         '''Break up and convert a string of FETCH response pairs 
     693        """Break up and convert a string of FETCH response pairs 
    694694 
    695695        @param s: FETCH response string eg. "FOO 12 BAH (1 abc def "foo bar")" 
    696696        @return: Tokenised and converted input return as (name, data) pairs. 
    697         ''' 
     697        """ 
    698698        out = [] 
    699699        for m in strict_finditer(self.PAIR_RE, s): 
     
    703703 
    704704    def process_list(self, s): 
    705         '''Break up and convert a string of data items 
     705        """Break up and convert a string of data items 
    706706 
    707707        @param s: FETCH response string eg. "(1 abc def "foo bar")" 
    708708        @return: A list of converted items. 
    709         ''' 
     709        """ 
    710710        if s == '': 
    711711            return [] 
     
    731731 
    732732class Literal(object): 
    733     ''' 
     733    """ 
    734734    Simple class to represent a literal token in the fetch response 
    735735    (eg. "{21}") 
    736     ''' 
     736    """ 
    737737 
    738738    def __init__(self, length): 
     
    747747 
    748748def strict_finditer(regex, s): 
    749     '''Like re.finditer except the regex must match from exactly where the 
     749    """Like re.finditer except the regex must match from exactly where the 
    750750    previous match ended and all the entire input must be matched. 
    751     ''' 
     751    """ 
    752752    i = 0 
    753753    matched = False 
     
    767767 
    768768def messages_to_str(messages): 
    769     '''Convert a sequence of messages ids or a single message id into an 
     769    """Convert a sequence of messages ids or a single message id into an 
    770770    message ID list for use with IMAP commands. 
    771771 
     
    773773        (eg. [1,4,5,7,8]) 
    774774    @return: Message list string (eg. "1,4,5,6,8") 
    775     ''' 
     775    """ 
    776776    if isinstance(messages, (str, int, long)): 
    777777        messages = (messages,) 
     
    782782 
    783783def seq_to_parenlist(flags): 
    784     '''Convert a sequence into parenthised list for use with IMAP commands 
     784    """Convert a sequence into parenthised list for use with IMAP commands 
    785785 
    786786    @param flags: Sequence to process (eg. ['abc', 'def']) 
    787787    @return: IMAP parenthenised list (eg. '(abc def)') 
    788     ''' 
     788    """ 
    789789    if isinstance(flags, str): 
    790790        flags = (flags,) 
     
    795795 
    796796def datetime_to_imap(dt): 
    797     '''Convert a datetime instance to a IMAP datetime string 
     797    """Convert a datetime instance to a IMAP datetime string 
    798798 
    799799    If timezone information is missing the current system timezone is used. 
    800     ''' 
     800    """ 
    801801    if not dt.tzinfo: 
    802802        dt = dt.replace(tzinfo=FixedOffset.for_system()) 
  • imapclient/test/test_FetchParser.py

    r87 r90  
    33# Please see http://en.wikipedia.org/wiki/BSD_licenses 
    44 
    5 ''' 
     5""" 
    66Unit tests for the FetchTokeniser and FetchParser classes 
    7 ''' 
     7""" 
    88 
    99import unittest 
     
    9494 
    9595    def testCharacterCase(self): 
    96         '''Test handling of varied case in the response type name 
    97         ''' 
     96        """Test handling of varied case in the response type name 
     97        """ 
    9898        self._parse_test( 
    9999            [r'2 (flaGS (\Deleted Foo \Seen))'], 
     
    131131 
    132132    def testMultipleTypes(self): 
    133         '''Test multiple response types''' 
     133        """Test multiple response types""" 
    134134        self._parse_test( 
    135135            [r'2 (FLAGS (\Deleted Foo \Seen) INTERNALDATE " 9-Feb-2007 17:08:08 +0000")'], 
     
    144144 
    145145    def testMultipleMessages(self): 
    146         '''Test with multple messages in the response 
    147         ''' 
     146        """Test with multple messages in the response 
     147        """ 
    148148        self._parse_test( 
    149149            [ 
     
    158158 
    159159    def testLiteral(self): 
    160         '''Test literal handling 
    161         ''' 
     160        """Test literal handling 
     161        """ 
    162162        self._parse_test( 
    163163            [('1 (RFC822 {21}', 'Subject: test\r\n\r\nbody'), ')'], 
     
    212212 
    213213    def testUID(self): 
    214         '''Test UID handling. The UID is returned instead of the given message 
     214        """Test UID handling. The UID is returned instead of the given message 
    215215        ID if present. 
    216         ''' 
     216        """ 
    217217        self._parse_test( 
    218218            ['1 (UID 8)'],