MCPcopy Index your code
hub / github.com/python/cpython / _pop

Method _pop

Lib/imaplib.py:1527–1575  ·  view source on GitHub ↗
(self, timeout, default=('', None))

Source from the content-addressed store, hash-verified

1525 return self
1526
1527 def _pop(self, timeout, default=('', None)):
1528 # Get the next response, or a default value on timeout.
1529 # The timeout arg can be an int or float, or None for no timeout.
1530 # Timeouts require a socket connection (not IMAP4_stream).
1531 # This method ignores self._duration.
1532
1533 # Historical Note:
1534 # The timeout was originally implemented using select() after
1535 # checking for the presence of already-buffered data.
1536 # That allowed timeouts on pipe connetions like IMAP4_stream.
1537 # However, it seemed possible that SSL data arriving without any
1538 # IMAP data afterward could cause select() to indicate available
1539 # application data when there was none, leading to a read() call
1540 # that would block with no timeout. It was unclear under what
1541 # conditions this would happen in practice. Our implementation was
1542 # changed to use socket timeouts instead of select(), just to be
1543 # safe.
1544
1545 imap = self._imap
1546 if imap.state != 'IDLING':
1547 raise imap.error('_pop() only works during IDLE')
1548
1549 if imap._idle_responses:
1550 # Response is ready to return to the user
1551 resp = imap._idle_responses.pop(0)
1552 if __debug__ and imap.debug >= 4:
1553 imap._mesg(f'idle _pop({timeout}) de-queued {resp[0]}')
1554 return resp
1555
1556 if __debug__ and imap.debug >= 4:
1557 imap._mesg(f'idle _pop({timeout}) reading')
1558
1559 if timeout is not None:
1560 if timeout <= 0:
1561 return default
1562 timeout = float(timeout) # Required by socket.settimeout()
1563
1564 try:
1565 imap._get_response(timeout) # Reads line, calls _append_untagged()
1566 except IMAP4._responsetimeout:
1567 if __debug__ and imap.debug >= 4:
1568 imap._mesg(f'idle _pop({timeout}) done')
1569 return default
1570
1571 resp = imap._idle_responses.pop(0)
1572
1573 if __debug__ and imap.debug >= 4:
1574 imap._mesg(f'idle _pop({timeout}) read {resp[0]}')
1575 return resp
1576
1577 def __next__(self):
1578 imap = self._imap

Callers 2

__next__Method · 0.95
burstMethod · 0.95

Calls 4

_mesgMethod · 0.80
_get_responseMethod · 0.80
errorMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected