Changeset 223:0cc6ebc4c1bd for imapclient
- Timestamp:
- 18/04/11 23:34:14 (13 months ago)
- Branch:
- default
- Files:
-
- 1 modified
-
imapclient/imapclient.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
imapclient/imapclient.py
r221 r223 6 6 import response_lexer 7 7 from operator import itemgetter 8 import select 8 9 import socket 9 import time10 10 import warnings 11 11 … … 112 112 port = default_port 113 113 114 self.use_uid = use_uid 115 self.ssl = ssl 116 self.folder_encode = True 114 117 self._imap = ImapClass(host, port) 115 self.use_uid = use_uid116 self.folder_encode = True117 118 self._idle_tag = None 118 119 … … 341 342 By default, this method will block until an IDLE response is 342 343 received. If timeout is provided, the call will block for at 343 most this number of seconds (approximately) while waiting for 344 an IDLE response. 344 most this number of seconds while waiting for an IDLE response. 345 345 346 346 The return value is a list of received IDLE responses. These … … 348 348 example: 349 349 350 [(1, 'EXISTS'), 351 ('OK', 'Still here'), 352 (1, 'FETCH', ('FLAGS', ('\NotJunk',))), 353 (0, 'EXPUNGE')] 354 355 An attempt is made to group responses that were sent together 356 by the server by waiting for a little longer after the first 357 IDLE response is received. 358 """ 359 timeouts = 0 360 resps = [] 361 start_t = time.time() 362 363 def blocking_done(): 364 # Wait for one timed out read to try group IDLE responses 365 # that were sent together 366 return resps and timeouts > 1 367 368 if timeout is None: 369 done = blocking_done 370 else: 371 def done(): 372 return blocking_done() or (time.time() - start_t >= timeout) 373 350 [('OK', 'Still here'), 351 (1, 'EXISTS'), 352 (1, 'FETCH', ('FLAGS', ('\\NotJunk',)))] 353 """ 374 354 # make the socket non-blocking so the timeout can be 375 355 # implemented for this call 376 self._imap.sock.settimeout(0.1) 356 if self.ssl: 357 sock = self._imap.sslobj 358 else: 359 sock = self._imap.sock 360 sock.setblocking(0) 377 361 try: 378 while not done(): 379 try: 380 line = self._imap._get_line() 381 except socket.timeout: 382 timeouts += 1 383 else: 384 resps.append(_parse_idle_response(line)) 362 resps = [] 363 rs, _, _ = select.select([sock], [], [], timeout) 364 if rs: 365 while True: 366 try: 367 line = self._imap._get_line() 368 except (socket.timeout, socket.error): 369 break 370 else: 371 resps.append(_parse_idle_response(line)) 385 372 return resps 386 373 finally: 387 s elf._imap.sock.settimeout(None)374 sock.setblocking(1) 388 375 389 376 def idle_done(self):
