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

Class StreamReader

Lib/asyncio/streams.py:410–773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408 warnings.warn(f"unclosed {self!r}", ResourceWarning)
409
410class StreamReader:
411
412 _source_traceback = None
413
414 def __init__(self, limit=_DEFAULT_LIMIT, loop=None):
415 # The line length limit is a security feature;
416 # it also doubles as half the buffer limit.
417
418 if limit <= 0:
419 raise ValueError('Limit cannot be <= 0')
420
421 self._limit = limit
422 if loop is None:
423 self._loop = events.get_event_loop()
424 else:
425 self._loop = loop
426 self._buffer = bytearray()
427 self._eof = False # Whether we're done.
428 self._waiter = None # A future used by _wait_for_data()
429 self._exception = None
430 self._transport = None
431 self._paused = False
432 if self._loop.get_debug():
433 self._source_traceback = format_helpers.extract_stack(
434 sys._getframe(1))
435
436 def __repr__(self):
437 info = ['StreamReader']
438 if self._buffer:
439 info.append(f'{len(self._buffer)} bytes')
440 if self._eof:
441 info.append('eof')
442 if self._limit != _DEFAULT_LIMIT:
443 info.append(f'limit={self._limit}')
444 if self._waiter:
445 info.append(f'waiter={self._waiter!r}')
446 if self._exception:
447 info.append(f'exception={self._exception!r}')
448 if self._transport:
449 info.append(f'transport={self._transport!r}')
450 if self._paused:
451 info.append('paused')
452 return '<{}>'.format(' '.join(info))
453
454 def exception(self):
455 return self._exception
456
457 def set_exception(self, exc):
458 self._exception = exc
459
460 waiter = self._waiter
461 if waiter is not None:
462 self._waiter = None
463 if not waiter.cancelled():
464 waiter.set_exception(exc)
465
466 def _wakeup_waiter(self):
467 """Wakeup read*() functions waiting for data or EOF."""

Callers 3

open_connectionFunction · 0.70
factoryFunction · 0.70
open_unix_connectionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…