/
usr
/
lib
/
python3
/
dist-packages
/
twisted
/
internet
/
/usr/lib/python3/dist-packages/twisted/internet
mkdir
upload
Name
Size
Mode
Actions
iocpreactor/
-
0755
rm
test/
-
0755
rm
__pycache__/
-
0755
rm
abstract.py
19295
0644
edit
dl
rm
address.py
5244
0644
edit
dl
rm
asyncioreactor.py
11131
0644
edit
dl
rm
base.py
47392
0644
edit
dl
rm
cfreactor.py
17499
0644
edit
dl
rm
default.py
1893
0644
edit
dl
rm
defer.py
85654
0644
edit
dl
rm
endpoints.py
77440
0644
edit
dl
rm
epollreactor.py
8941
0644
edit
dl
rm
error.py
13482
0644
edit
dl
rm
fdesc.py
3237
0644
edit
dl
rm
gireactor.py
4620
0644
edit
dl
rm
glib2reactor.py
1115
0644
edit
dl
rm
gtk2reactor.py
3640
0644
edit
dl
rm
gtk3reactor.py
1527
0644
edit
dl
rm
inotify.py
14396
0644
edit
dl
rm
interfaces.py
98048
0644
edit
dl
rm
kqreactor.py
10818
0644
edit
dl
rm
main.py
1006
0644
edit
dl
rm
pollreactor.py
5974
0644
edit
dl
rm
posixbase.py
27604
0644
edit
dl
rm
process.py
38516
0644
edit
dl
rm
protocol.py
27391
0644
edit
dl
rm
pyuisupport.py
843
0644
edit
dl
rm
reactor.py
1816
0644
edit
dl
rm
selectreactor.py
6102
0644
edit
dl
rm
serialport.py
2272
0644
edit
dl
rm
ssl.py
8643
0644
edit
dl
rm
stdio.py
1000
0644
edit
dl
rm
task.py
33608
0644
edit
dl
rm
tcp.py
54980
0644
edit
dl
rm
testing.py
29232
0644
edit
dl
rm
threads.py
3812
0644
edit
dl
rm
tksupport.py
1971
0644
edit
dl
rm
udp.py
18619
0644
edit
dl
rm
unix.py
22508
0644
edit
dl
rm
utils.py
8682
0644
edit
dl
rm
win32eventreactor.py
15266
0644
edit
dl
rm
wxreactor.py
5315
0644
edit
dl
rm
wxsupport.py
1305
0644
edit
dl
rm
_baseprocess.py
2003
0644
edit
dl
rm
_dumbwin32proc.py
12776
0644
edit
dl
rm
_glibbase.py
12706
0644
edit
dl
rm
_idna.py
1422
0644
edit
dl
rm
_newtls.py
9157
0644
edit
dl
rm
_pollingfile.py
8791
0644
edit
dl
rm
_posixserialport.py
2081
0644
edit
dl
rm
_posixstdio.py
4996
0644
edit
dl
rm
_producer_helpers.py
3909
0644
edit
dl
rm
_resolver.py
8465
0644
edit
dl
rm
_signals.py
2670
0644
edit
dl
rm
_sslverify.py
72796
0644
edit
dl
rm
_threadedselect.py
11582
0644
edit
dl
rm
_win32serialport.py
4914
0644
edit
dl
rm
_win32stdio.py
3140
0644
edit
dl
rm
__init__.py
521
0644
edit
dl
rm
Edit:
/usr/lib/python3/dist-packages/twisted/internet/_producer_helpers.py
(3909B)
# -*- test-case-name: twisted.test.test_producer_helpers -*- # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Helpers for working with producers. """ from typing import List from zope.interface import implementer from twisted.internet.interfaces import IPushProducer from twisted.internet.task import cooperate from twisted.python import log from twisted.python.reflect import safe_str # This module exports nothing public, it's for internal Twisted use only. __all__: List[str] = [] @implementer(IPushProducer) class _PullToPush: """ An adapter that converts a non-streaming to a streaming producer. Because of limitations of the producer API, this adapter requires the cooperation of the consumer. When the consumer's C{registerProducer} is called with a non-streaming producer, it must wrap it with L{_PullToPush} and then call C{startStreaming} on the resulting object. When the consumer's C{unregisterProducer} is called, it must call C{stopStreaming} on the L{_PullToPush} instance. If the underlying producer throws an exception from C{resumeProducing}, the producer will be unregistered from the consumer. @ivar _producer: the underling non-streaming producer. @ivar _consumer: the consumer with which the underlying producer was registered. @ivar _finished: C{bool} indicating whether the producer has finished. @ivar _coopTask: the result of calling L{cooperate}, the task driving the streaming producer. """ _finished = False def __init__(self, pullProducer, consumer): self._producer = pullProducer self._consumer = consumer def _pull(self): """ A generator that calls C{resumeProducing} on the underlying producer forever. If C{resumeProducing} throws an exception, the producer is unregistered, which should result in streaming stopping. """ while True: try: self._producer.resumeProducing() except BaseException: log.err( None, "%s failed, producing will be stopped:" % (safe_str(self._producer),), ) try: self._consumer.unregisterProducer() # The consumer should now call stopStreaming() on us, # thus stopping the streaming. except BaseException: # Since the consumer blew up, we may not have had # stopStreaming() called, so we just stop on our own: log.err( None, "%s failed to unregister producer:" % (safe_str(self._consumer),), ) self._finished = True return yield None def startStreaming(self): """ This should be called by the consumer when the producer is registered. Start streaming data to the consumer. """ self._coopTask = cooperate(self._pull()) def stopStreaming(self): """ This should be called by the consumer when the producer is unregistered. Stop streaming data to the consumer. """ if self._finished: return self._finished = True self._coopTask.stop() def pauseProducing(self): """ @see: C{IPushProducer.pauseProducing} """ self._coopTask.pause() def resumeProducing(self): """ @see: C{IPushProducer.resumeProducing} """ self._coopTask.resume() def stopProducing(self): """ @see: C{IPushProducer.stopProducing} """ self.stopStreaming() self._producer.stopProducing()
Save
cmd:
run