1313# Author: Piers Lauder <[email protected] > December 1997. 1414#
1515# Authentication code contributed by Donn Cave <[email protected] > June 1998. 16+ # String method conversion by ESR, February 2001.
1617
17- __version__ = "2.39 "
18+ __version__ = "2.40 "
1819
19- import binascii , re , socket , string , time , random , sys
20+ import binascii , re , socket , time , random , sys
2021
2122__all__ = ["IMAP4" , "Internaldate2tuple" ,
2223 "Int2AP" , "ParseFlags" , "Time2Internaldate" ]
@@ -167,7 +168,7 @@ def __init__(self, host = '', port = IMAP4_PORT):
167168 self ._simple_command (cap )
168169 if not self .untagged_responses .has_key (cap ):
169170 raise self .error ('no CAPABILITY response from server' )
170- self .capabilities = tuple (string . split ( string . upper ( self .untagged_responses [cap ][- 1 ]) ))
171+ self .capabilities = tuple (self .untagged_responses [cap ][- 1 ]. upper (). split ( ))
171172
172173 if __debug__ :
173174 if self .debug >= 3 :
@@ -185,7 +186,7 @@ def __init__(self, host = '', port = IMAP4_PORT):
185186 def __getattr__ (self , attr ):
186187 # Allow UPPERCASE variants of IMAP4 command methods.
187188 if Commands .has_key (attr ):
188- return eval ("self.%s" % string .lower (attr ))
189+ return eval ("self.%s" % attr .lower ())
189190 raise AttributeError ("Unknown IMAP4 command: '%s'" % attr )
190191
191192
@@ -224,7 +225,7 @@ def response(self, code):
224225
225226 (code, [data]) = <instance>.response(code)
226227 """
227- return self ._untagged_response (code , [None ], string .upper (code ))
228+ return self ._untagged_response (code , [None ], code .upper ())
228229
229230
230231 def socket (self ):
@@ -278,7 +279,7 @@ def authenticate(self, mechanism, authobject):
278279 It should return None if the client abort response '*' should
279280 be sent instead.
280281 """
281- mech = string .upper (mechanism )
282+ mech = mechanism .upper ()
282283 cap = 'AUTH=%s' % mech
283284 if not cap in self .capabilities :
284285 raise self .error ("Server doesn't allow %s authentication." % mech )
@@ -537,7 +538,7 @@ def uid(self, command, *args):
537538
538539 Returns response appropriate to 'command'.
539540 """
540- command = string .upper (command )
541+ command = command .upper ()
541542 if not Commands .has_key (command ):
542543 raise self .error ("Unknown IMAP4 UID command: %s" % command )
543544 if self .state not in Commands [command ]:
@@ -729,7 +730,7 @@ def _get_response(self):
729730
730731 # Read literal direct from connection.
731732
732- size = string . atoi (self .mo .group ('size' ))
733+ size = int (self .mo .group ('size' ))
733734 if __debug__ :
734735 if self .debug >= 4 :
735736 _mesg ('read literal size %s' % size )
@@ -832,8 +833,8 @@ def _checkquote(self, arg):
832833
833834 def _quote (self , arg ):
834835
835- arg = string .replace (arg , '\\ ' , '\\ \\ ' )
836- arg = string .replace (arg , '"' , '\\ "' )
836+ arg = arg .replace ('\\ ' , '\\ \\ ' )
837+ arg = arg .replace ('"' , '\\ "' )
837838
838839 return '"%s"' % arg
839840
@@ -920,7 +921,7 @@ def Internaldate2tuple(resp):
920921 zonen = mo .group ('zonen' )
921922
922923 for name in ('day' , 'year' , 'hour' , 'min' , 'sec' , 'zoneh' , 'zonem' ):
923- exec "%s = string.atoi (mo.group('%s'))" % (name , name )
924+ exec "%s = int (mo.group('%s'))" % (name , name )
924925
925926 # INTERNALDATE timezone must be subtracted to get UT
926927
@@ -966,7 +967,7 @@ def ParseFlags(resp):
966967 if not mo :
967968 return ()
968969
969- return tuple (string . split ( mo .group ('flags' )))
970+ return tuple (mo .group ('flags' ). split ( ))
970971
971972
972973def Time2Internaldate (date_time ):
@@ -1010,8 +1011,7 @@ def _dump_ur(dict):
10101011 l = dict .items ()
10111012 if not l : return
10121013 t = '\n \t \t '
1013- j = string .join
1014- l = map (lambda x ,j = j :'%s: "%s"' % (x [0 ], x [1 ][0 ] and j (x [1 ], '" "' ) or '' ), l )
1014+ l = map (lambda x :'%s: "%s"' % (x [0 ], x [1 ][0 ] and '" "' .join (x [1 ]) or '' ), l )
10151015 _mesg ('untagged responses dump:%s%s' % (t , j (l , t )))
10161016
10171017 _cmd_log = [] # Last `_cmd_log_len' interactions
@@ -1048,7 +1048,7 @@ def print_log():
10481048 host = args [0 ]
10491049
10501050 USER = getpass .getuser ()
1051- PASSWD = getpass .getpass ("IMAP password for %s on %s" % (USER , host or "localhost" ))
1051+ PASSWD = getpass .getpass ("IMAP password for %s on %s: " % (USER , host or "localhost" ))
10521052
10531053 test_mesg = 'From: %s@localhost\n Subject: IMAP4 test\n \n data...\n ' % USER
10541054 test_seq1 = (
@@ -1093,7 +1093,7 @@ def run(cmd, args):
10931093 for ml in run ('list' , ('/tmp/' , 'yy%' )):
10941094 mo = re .match (r'.*"([^"]+)"$' , ml )
10951095 if mo : path = mo .group (1 )
1096- else : path = string .split (ml )[- 1 ]
1096+ else : path = ml .split ()[- 1 ]
10971097 run ('delete' , (path ,))
10981098
10991099 for cmd ,args in test_seq2 :
@@ -1102,7 +1102,7 @@ def run(cmd, args):
11021102 if (cmd ,args ) != ('uid' , ('SEARCH' , 'ALL' )):
11031103 continue
11041104
1105- uid = string . split ( dat [- 1 ])
1105+ uid = dat [- 1 ]. split ( )
11061106 if not uid : continue
11071107 run ('uid' , ('FETCH' , '%s' % uid [- 1 ],
11081108 '(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)' ))
0 commit comments