Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Side by Side Diff: Lib/imaplib.py

Issue 4972: context managerment support in imaplib, smtplib, ftplib
Patch Set: Created 7 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_imaplib.py » ('j') | Lib/test/test_imaplib.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """IMAP4 client. 1 """IMAP4 client.
2 2
3 Based on RFC 2060. 3 Based on RFC 2060.
4 4
5 Public class: IMAP4 5 Public class: IMAP4
6 Public variable: Debug 6 Public variable: Debug
7 Public functions: Internaldate2tuple 7 Public functions: Internaldate2tuple
8 Int2AP 8 Int2AP
9 ParseFlags 9 ParseFlags
10 Time2Internaldate 10 Time2Internaldate
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 raise self.error('server not IMAP4 compliant') 221 raise self.error('server not IMAP4 compliant')
222 222
223 223
224 def __getattr__(self, attr): 224 def __getattr__(self, attr):
225 # Allow UPPERCASE variants of IMAP4 command methods. 225 # Allow UPPERCASE variants of IMAP4 command methods.
226 if attr in Commands: 226 if attr in Commands:
227 return getattr(self, attr.lower()) 227 return getattr(self, attr.lower())
228 raise AttributeError("Unknown IMAP4 command: '%s'" % attr) 228 raise AttributeError("Unknown IMAP4 command: '%s'" % attr)
229 229
230 def __enter__(self):
231 """Context management protocol. Returns self."""
232 return self
230 233
234 def __exit__(self, *args):
235 """Context management protocol.
236 logout() will close properly even if not logged in."""
237 self.logout()
231 238
232 # Overridable methods 239 # Overridable methods
233 240
234 241
235 def _create_socket(self): 242 def _create_socket(self):
236 return socket.create_connection((self.host, self.port)) 243 return socket.create_connection((self.host, self.port))
237 244
238 def open(self, host = '', port = IMAP4_PORT): 245 def open(self, host = '', port = IMAP4_PORT):
239 """Setup connection to remote server on "host:port" 246 """Setup connection to remote server on "host:port"
240 (default: localhost:standard IMAP4 port). 247 (default: localhost:standard IMAP4 port).
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 except: 1521 except:
1515 print('\nTests failed.') 1522 print('\nTests failed.')
1516 1523
1517 if not Debug: 1524 if not Debug:
1518 print(''' 1525 print('''
1519 If you would like to see debugging output, 1526 If you would like to see debugging output,
1520 try: %s -d5 1527 try: %s -d5
1521 ''' % sys.argv[0]) 1528 ''' % sys.argv[0])
1522 1529
1523 raise 1530 raise
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_imaplib.py » ('j') | Lib/test/test_imaplib.py » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+