MCPcopy Index your code
hub / github.com/RustPython/RustPython / __enter__

Method __enter__

Lib/imaplib.py:1444–1485  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1442 self._saved_state = None
1443
1444 def __enter__(self):
1445 imap = self._imap
1446 assert not imap._idle_responses
1447 assert not imap._idle_capture
1448
1449 if __debug__ and imap.debug >= 4:
1450 imap._mesg(f'idle start duration={self._duration}')
1451
1452 # Start capturing untagged responses before sending IDLE,
1453 # so we can deliver via iteration any that arrive while
1454 # the IDLE command continuation request is still pending.
1455 imap._idle_capture = True
1456
1457 try:
1458 self._tag = imap._command('IDLE')
1459 # As with any command, the server is allowed to send us unrelated,
1460 # untagged responses before acting on IDLE. These lines will be
1461 # returned by _get_response(). When the server is ready, it will
1462 # send an IDLE continuation request, indicated by _get_response()
1463 # returning None. We therefore process responses in a loop until
1464 # this occurs.
1465 while resp := imap._get_response():
1466 if imap.tagged_commands[self._tag]:
1467 typ, data = imap.tagged_commands.pop(self._tag)
1468 if typ == 'NO':
1469 raise imap.error(f'idle denied: {data}')
1470 raise imap.abort(f'unexpected status response: {resp}')
1471
1472 if __debug__ and imap.debug >= 4:
1473 prompt = imap.continuation_response
1474 imap._mesg(f'idle continuation prompt: {prompt}')
1475 except BaseException:
1476 imap._idle_capture = False
1477 raise
1478
1479 if self._duration is not None:
1480 self._deadline = time.monotonic() + self._duration
1481
1482 self._saved_state = imap.state
1483 imap.state = 'IDLING'
1484
1485 return self
1486
1487 def __exit__(self, exc_type, exc_val, exc_tb):
1488 imap = self._imap

Callers

nothing calls this directly

Calls 6

_mesgMethod · 0.80
_commandMethod · 0.80
_get_responseMethod · 0.80
popMethod · 0.45
errorMethod · 0.45
abortMethod · 0.45

Tested by

no test coverage detected