Changeset 391 for python/trunk/Lib/imaplib.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/imaplib.py
r2 r391 23 23 __version__ = "2.58" 24 24 25 import binascii, random, re, socket, subprocess, sys, time25 import binascii, errno, random, re, socket, subprocess, sys, time 26 26 27 27 __all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", … … 249 249 """Close I/O established in "open".""" 250 250 self.file.close() 251 self.sock.close() 251 try: 252 self.sock.shutdown(socket.SHUT_RDWR) 253 except socket.error as e: 254 # The server might already have closed the connection 255 if e.errno != errno.ENOTCONN: 256 raise 257 finally: 258 self.sock.close() 252 259 253 260 … … 752 759 name = 'UID' 753 760 typ, dat = self._simple_command(name, command, *args) 754 if command in ('SEARCH', 'SORT' ):761 if command in ('SEARCH', 'SORT', 'THREAD'): 755 762 name = command 756 763 else: … … 884 891 885 892 def _command_complete(self, name, tag): 886 self._check_bye() 893 # BYE is expected after LOGOUT 894 if name != 'LOGOUT': 895 self._check_bye() 887 896 try: 888 897 typ, data = self._get_tagged_response(tag) … … 891 900 except self.error, val: 892 901 raise self.error('command: %s => %s' % (name, val)) 893 self._check_bye() 902 if name != 'LOGOUT': 903 self._check_bye() 894 904 if typ == 'BAD': 895 905 raise self.error('%s command error: %s %s' % (name, typ, data)) … … 1149 1159 self.sock = socket.create_connection((host, port)) 1150 1160 self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) 1161 self.file = self.sslobj.makefile('rb') 1151 1162 1152 1163 1153 1164 def read(self, size): 1154 1165 """Read 'size' bytes from remote.""" 1155 # sslobj.read() sometimes returns < size bytes 1156 chunks = [] 1157 read = 0 1158 while read < size: 1159 data = self.sslobj.read(min(size-read, 16384)) 1160 read += len(data) 1161 chunks.append(data) 1162 1163 return ''.join(chunks) 1166 return self.file.read(size) 1164 1167 1165 1168 1166 1169 def readline(self): 1167 1170 """Read line from remote.""" 1168 line = [] 1169 while 1: 1170 char = self.sslobj.read(1) 1171 line.append(char) 1172 if char in ("\n", ""): return ''.join(line) 1171 return self.file.readline() 1173 1172 1174 1173 … … 1186 1185 def shutdown(self): 1187 1186 """Close I/O established in "open".""" 1187 self.file.close() 1188 1188 self.sock.close() 1189 1189 … … 1213 1213 Instantiate with: IMAP4_stream(command) 1214 1214 1215 where "command" is a string that can be passed to Subprocess.Popen()1215 where "command" is a string that can be passed to subprocess.Popen() 1216 1216 1217 1217 for more documentation see the docstring of the parent class IMAP4. … … 1312 1312 1313 1313 def Internaldate2tuple(resp): 1314 """Convert IMAP4 INTERNALDATE to UT. 1315 1316 Returns Python time module tuple. 1314 """Parse an IMAP4 INTERNALDATE string. 1315 1316 Return corresponding local time. The return value is a 1317 time.struct_time instance or None if the string has wrong format. 1317 1318 """ 1318 1319 … … 1381 1382 def Time2Internaldate(date_time): 1382 1383 1383 """Convert 'date_time' to IMAP4 INTERNALDATE representation. 1384 1385 Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"' 1384 """Convert date_time to IMAP4 INTERNALDATE representation. 1385 1386 Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'. The 1387 date_time argument can be a number (int or float) representing 1388 seconds since epoch (as returned by time.time()), a 9-tuple 1389 representing local time (as returned by time.localtime()), or a 1390 double-quoted string. In the last case, it is assumed to already 1391 be in the correct format. 1386 1392 """ 1387 1393
Note:
See TracChangeset
for help on using the changeset viewer.