本文整理汇总了Python中twisted.protocols.basic.LineReceiver类的典型用法代码示例。如果您正苦于以下问题:Python LineReceiver类的具体用法?Python LineReceiver怎么用?Python LineReceiver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LineReceiver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connectionLost
def connectionLost(self, why):
self.connected = 0
self.script_hashes.clear()
self.factory.delConnection(self)
LineReceiver.connectionLost(self, why)
while self.replyQueue.waiting:
self.replyReceived(ConnectionError("Lost connection"))
示例2: dataReceived
def dataReceived(self, *args, **kwargs):
# receives the data then checks if the request is complete.
# if it is, it calls full_Request_received
LineReceiver.dataReceived(self, *args, **kwargs)
if self._request_obj.complete:
self.full_request_received()
示例3: sendLine
def sendLine(self, line):
"""
Override sendLine to add a timeout to response.
"""
if not self._current:
self.setTimeout(self.persistentTimeOut)
LineReceiver.sendLine(self, line)
示例4: APRSProcessProtocol
class APRSProcessProtocol(ProcessProtocol):
def __init__(self, target):
self.__target = target
self.__line_receiver = LineReceiver()
self.__line_receiver.delimiter = '\n'
self.__line_receiver.lineReceived = self.__lineReceived
self.__last_line = None
def outReceived(self, data):
# split lines
self.__line_receiver.dataReceived(data)
def errReceived(self, data):
# we should inherit stderr, not pipe it
raise Exception('shouldn\'t happen')
def __lineReceived(self, line):
if line == '': # observed glitch in output
pass
elif line.startswith('Enabled demodulators:'):
pass
elif line.startswith('$ULTW') and self.__last_line is not None: # observed glitch in output; need to glue to previous line, I think?
ll = self.__last_line
self.__last_line = None
self.__target(ll + line)
elif line.startswith('APRS: '):
line = line[len('APRS: '):]
self.__last_line = line
self.__target(line)
else:
# TODO: Log these properly
print 'Not APRS line: %r' % line
示例5: RTL433ProcessProtocol
class RTL433ProcessProtocol(ProcessProtocol):
def __init__(self, target):
self.__target = target
self.__line_receiver = LineReceiver()
self.__line_receiver.delimiter = '\n'
self.__line_receiver.lineReceived = self.__lineReceived
def outReceived(self, data):
"""Implements ProcessProtocol."""
# split lines
self.__line_receiver.dataReceived(data)
def errReceived(self, data):
"""Implements ProcessProtocol."""
# we should inherit stderr, not pipe it
raise Exception('shouldn\'t happen')
def __lineReceived(self, line):
# rtl_433's JSON encoder is not perfect (e.g. it will emit unescaped newlines), so protect against parse failures
try:
message = json.loads(line)
except ValueError:
log.msg('bad JSON from rtl_433: %s' % line)
return
log.msg('rtl_433 message: %r' % (message,))
# rtl_433 provides a time field, but when in file-input mode it assumes the input is not real-time and generates start-of-file-relative timestamps, so we can't use them.
wrapper = RTL433MessageWrapper(message, time.time())
self.__target(wrapper)
示例6: sendLine
def sendLine(self, line):
if self.onXMLReceived:
raise FoneworxException, "onXMLReceived already initialized before sending"
self.onXMLReceived = Deferred()
log.msg("Sending line: %s" % line, logLevel=logging.DEBUG)
LineReceiver.sendLine(self, line)
return self.onXMLReceived
示例7: connectionLost
def connectionLost(self, reason):
"""
Cause any outstanding commands to fail.
"""
self._disconnected = True
self._cancelCommands(reason)
LineReceiver.connectionLost(self, reason)
示例8: dataReceived
def dataReceived(self, data):
if self.factory.stream_response and self.stream_response:
self.factory.return_transport.write(data)
LineReceiver.dataReceived(self, data)
if not self.completed:
if self._response_obj.complete:
self.completed = True
self.handle_response_end()
示例9: __init__
def __init__(self):
self.state = self.State.ANNOUNCE
self.session = None
self.nonce = None
self.seq = 0
LineReceiver.setRawMode(self)
global video_server_connection
video_server_connection = self
示例10: connectionLost
def connectionLost(self, reason):
""" ups... stop reactor """
LineReceiver.connectionLost(self, reason)
print "Connection lost: ", reason.getErrorMessage()
try:
reactor.stop()
except ReactorNotRunning:
print " - reactor not running, so we are not stopping it"
示例11: connectionMade
def connectionMade(self):
ProcessProtocol.connectionMade(self)
LineReceiver.connectionMade(self)
self.transport.disconnecting = False #erm. Needs this to fix a bug in Twisted?
self.send_to_client("hello", [self.communicator.mod.name])
if not self.messages_not_acknowledged:
self.client_started_processing_at = time.time()
self.messages_not_acknowledged += 1
示例12: connectionMade
def connectionMade(self):
"""
Notify our factory that we're ready to accept connections.
"""
LineReceiver.connectionMade(self)
if self.factory.deferred is not None:
self.factory.deferred.callback(self)
self.factory.deferred = None
示例13: dataReceived
def dataReceived(self, *args, **kwargs):
# receives the data then checks if the request is complete.
# if it is, it calls full_Request_received
LineReceiver.dataReceived(self, *args, **kwargs)
if self._request_obj.complete:
try:
self.full_request_received()
except PappyException as e:
print str(e)
示例14: create_request
def create_request(self):
channel = LineReceiver()
channel.site = PixelatedSite(mock())
request = PixelatedSite.requestFactory(channel=channel, queued=True)
request.method = "GET"
request.uri = "localhost"
request.clientproto = 'HTTP/1.1'
request.prepath = []
request.postpath = request.uri.split('/')[1:]
request.path = "/"
return request
示例15: sendLine
def sendLine(self, line):
if isinstance(line, str):
if six.PY3:
super(StringLineReceiver, self).sendLine(line.encode())
else:
LineReceiver.sendLine(self, line.encode())
elif isinstance(line, bytes):
if six.PY3:
super(StringLineReceiver, self).sendLine(line)
else:
LineReceiver.sendLine(self, line)
else:
raise RuntimeError("Only str and bytes are allowed.")