当前位置: 首页>>代码示例>>Python>>正文


Python LineReceiver.dataReceived方法代码示例

本文整理汇总了Python中twisted.protocols.basic.LineReceiver.dataReceived方法的典型用法代码示例。如果您正苦于以下问题:Python LineReceiver.dataReceived方法的具体用法?Python LineReceiver.dataReceived怎么用?Python LineReceiver.dataReceived使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.protocols.basic.LineReceiver的用法示例。


在下文中一共展示了LineReceiver.dataReceived方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dataReceived

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
    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()
开发者ID:amuntner,项目名称:pappy-proxy,代码行数:9,代码来源:proxy.py

示例2: APRSProcessProtocol

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
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
开发者ID:gstark307,项目名称:shinysdr,代码行数:34,代码来源:multimon.py

示例3: RTL433ProcessProtocol

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
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)
开发者ID:bitglue,项目名称:shinysdr,代码行数:30,代码来源:rtl_433.py

示例4: dataReceived

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
 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()
开发者ID:onizenso,项目名称:pappy-proxy,代码行数:10,代码来源:proxy.py

示例5: PostgresMonitor

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
class PostgresMonitor(ProcessProtocol):
    """
    A monitoring protocol which watches the postgres subprocess.
    """
    log = Logger()

    def __init__(self, svc=None):
        self.lineReceiver = LineReceiver()
        self.lineReceiver.delimiter = '\n'
        self.lineReceiver.lineReceived = self.lineReceived
        self.svc = svc
        self.isReady = False
        self.completionDeferred = Deferred()


    def lineReceived(self, line):
        if self.svc is None:
            return
        if not self.isReady:
            if _MAGIC_READY_COOKIE in line:
                self.svc.ready()

    disconnecting = False


    def connectionMade(self):
        self.lineReceiver.makeConnection(self)


    def outReceived(self, out):
        for line in out.split("\n"):
            if line:
                self.log.info("{message}", message=line)
        # self.lineReceiver.dataReceived(out)


    def errReceived(self, err):
        for line in err.split("\n"):
            if line:
                self.log.error("{message}", message=line)
        self.lineReceiver.dataReceived(err)


    def processEnded(self, reason):
        self.log.info(
            "pg_ctl process ended with status={status}",
            status=reason.value.status
        )
        # If pg_ctl exited with zero, we were successful in starting postgres
        # If pg_ctl exited with nonzero, we need to give up.
        self.lineReceiver.connectionLost(reason)

        if reason.value.status == 0:
            self.completionDeferred.callback(None)
        else:
            self.log.error("Could not start postgres; see postgres.log")
            self.completionDeferred.errback(reason)
开发者ID:red-hood,项目名称:calendarserver,代码行数:59,代码来源:subpostgres.py

示例6: dataReceived

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
    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)
开发者ID:MahaKoala,项目名称:pappy-proxy,代码行数:12,代码来源:proxy.py

示例7: CommandReceiver

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
class CommandReceiver(channel.ChannelReceiver):

    def __init__(self):
        self.lineReceiver = LineReceiver()
        self.lineReceiver.lineReceived = self.lineReceived

    def lineReceived(self, line):
        cmd, data = line.split(':', 1)
        self.commandReceived(cmd.strip(), data.strip())

    def commandReceived(self, cmd, data):
        raise NotImplementedError

    def sendCommand(self, cmd, data):
        return self.send(self.cmd_channel, '%s: %s\r\n' % (cmd, data))

    def channeReceived(self, channel, type, data):
        if channel == self.cmd_channel:
            self.lineReceiver.dataReceived(data)
开发者ID:scottietie,项目名称:nowin_core,代码行数:21,代码来源:command.py

示例8: _PostgresMonitor

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
class _PostgresMonitor(ProcessProtocol):
    """
    A monitoring protocol which watches the postgres subprocess.
    """

    def __init__(self, svc=None):
        self.lineReceiver = LineReceiver()
        self.lineReceiver.delimiter = '\n'
        self.lineReceiver.lineReceived = self.lineReceived
        self.svc = svc
        self.isReady = False
        self.completionDeferred = Deferred()


    def lineReceived(self, line):
        if self.svc is None:
            return
        if not self.isReady:
            if _MAGIC_READY_COOKIE in line:
                self.svc.ready()

    disconnecting = False


    def connectionMade(self):
        self.lineReceiver.makeConnection(self)


    def outReceived(self, out):
        log.msg("received postgres stdout %r" % (out,))
        # self.lineReceiver.dataReceived(out)


    def errReceived(self, err):
        log.msg("received postgres stderr %r" % (err,))
        self.lineReceiver.dataReceived(err)


    def processEnded(self, reason):
        log.msg("postgres process ended %r" % (reason,))
        result = (reason.value.status == 0)
        self.lineReceiver.connectionLost(reason)
        self.completionDeferred.callback(result)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:45,代码来源:subpostgres.py

示例9: LineBuffer

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
class LineBuffer(object):
    """
    A line-buffering wrapper for L{GreenletTransport}s (or any other object
    with C{read} and C{write} methods). Call L{readLine} to get the next line,
    call L{writeLine} to write a line.
    """
    def __init__(self, transport, delimiter="\r\n"):
        """
        @param transport: The transport from which to read bytes and to which
            to write them!
        @type transport: L{GreenletTransport}
        @param delimiter: The line delimiter to split lines on.
        @type delimiter: C{str}
        """
        self.delimiter = delimiter
        self.transport = transport
        self.receiver = LineReceiver()
        self.receiver.delimiter = delimiter
        self.lines = []
        self.receiver.lineReceived = self.lines.append

    def writeLine(self, data):
        """
        Write some data to the transport followed by the delimiter.
        """
        self.transport.write(data + self.delimiter)

    def readLine(self):
        """
        Return a line of data from the transport.
        """
        while not self.lines:
            self.receiver.dataReceived(self.transport.read())
        return self.lines.pop(0)

    def __iter__(self):
        """
        Yield the result of L{readLine} forever.
        """
        while True:
            yield self.readLine()
开发者ID:radix,项目名称:corotwine,代码行数:43,代码来源:protocol.py

示例10: _ControllerProtocol

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
class _ControllerProtocol(Protocol):
    def __init__(self):
        self.__line_receiver = LineReceiver()
        self.__line_receiver.delimiter = b';'
        self.__line_receiver.lineReceived = self.__lineReceived
    
    def connectionMade(self):
        """overrides Protocol"""
        # TODO: Report success
    
    def connectionLost(self, reason=None):
        """overrides Protocol"""
        # TODO: Report loss to user
    
    def dataReceived(self, data):
        """overrides Protocol"""
        self.__line_receiver.dataReceived(data)
    
    def __lineReceived(self, line):
        print line
    
    def send(self, cmd):
        self.transport.write(cmd)
开发者ID:thefinn93,项目名称:shinysdr,代码行数:25,代码来源:controller.py

示例11: dataReceived

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
 def dataReceived(self, data):
     # translate '\r' into '\n'
     return LineReceiver.dataReceived(self, data.replace('\r', '\n'))
开发者ID:telegraphic,项目名称:hipsr_core,代码行数:5,代码来源:core.py

示例12: dataReceived

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
	def dataReceived(self, data):
		self.resetTimeout()
		LineReceiver.dataReceived(self, data)
开发者ID:ckx,项目名称:pyBurlyBot,代码行数:5,代码来源:client.py

示例13: dataReceived

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
 def dataReceived(self, data):
     LineReceiver.dataReceived(self, data)
     if data == "\x04":
         self.transport.loseConnection()
开发者ID:hagna,项目名称:simplebb,代码行数:6,代码来源:shell.py

示例14: _HamlibClientProtocol

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
class _HamlibClientProtocol(Protocol):
    def __init__(self, server_name, connected_deferred):
        self.__proxy_obj = None
        self.__server_name = server_name
        self.__connected_deferred = connected_deferred
        self.__line_receiver = LineReceiver()
        self.__line_receiver.delimiter = '\n'
        self.__line_receiver.lineReceived = self.__lineReceived
        self.__waiting_for_responses = []
        self.__receive_cmd = None
        self.__receive_arg = None
    
    def connectionMade(self):
        self.__connected_deferred.callback(self)
    
    def connectionLost(self, reason):
        # pylint: disable=signature-differs
        if self.__proxy_obj is not None:
            self.__proxy_obj._clientConnectionLost(reason)
    
    def dataReceived(self, data):
        self.__line_receiver.dataReceived(data)
    
    def __lineReceived(self, line):
        if self.__receive_cmd is None:
            match = re.match(r'^(\w+):\s*(.*)$', line)
            if match is not None:
                # command response starting line
                self.__receive_cmd = match.group(1)
                self.__receive_arg = match.group(2)
                return
            log.err('%s client: Unrecognized line (no command active): %r' % (self.__server_name, line))
        else:
            match = re.match(r'^RPRT (-?\d+)$', line)
            if match is not None:
                # command response ending line
                return_code = int(match.group(1))
                
                waiting = self.__waiting_for_responses
                i = 0
                for i, (wait_cmd, wait_deferred) in enumerate(waiting):
                    if self.__receive_cmd != wait_cmd:
                        log.err("%s client: Didn't get a response for command %r before receiving one for command %r" % (self.__server_name, wait_cmd, self.__receive_cmd))
                    else:
                        # TODO: Consider 'parsing' return code more here.
                        if return_code != 0:
                            self.__proxy_obj._clientError(self.__receive_cmd, return_code)
                        wait_deferred.callback(return_code)
                        break
                self.__waiting_for_responses = waiting[i + 1:]
                
                self.__receive_cmd = None
                self.__receive_arg = None
                return
            if self.__receive_cmd == 'get_level':
                # Should be a level value
                match = re.match(r'^-?\d+\.?\d*$', line)
                if match:
                    self.__proxy_obj._clientReceivedLevel(self.__receive_arg, line)
                    return
            match = re.match(r'^([\w ,/-]+):\s*(.*)$', line)
            if match is not None:
                # Command response
                if self.__proxy_obj is not None:
                    self.__proxy_obj._clientReceived(self.__receive_cmd, match.group(1), match.group(2))
                    return
            match = re.match(r'^\t', line)
            if match is not None and self.__receive_cmd == 'dump_caps':
                # Sub-info from dump_caps, not currently used
                return
            match = re.match(r'^Warning--', line)
            if match is not None:
                # Warning from dump_caps, not currently used
                return
            match = re.match(r'^$', line)
            if match is not None:
                return
            log.err('%s client: Unrecognized line during %s: %r' % (self.__server_name, self.__receive_cmd, line))
    
    def _set_proxy(self, proxy):
        self.__proxy_obj = proxy
    
    def rc_send(self, cmd, argstr=''):
        if not re.match(r'^\w+$', cmd):  # no spaces (stuffing args in), no newlines (breaking the command)
            raise ValueError('Syntactically invalid command name %r' % (cmd,))
        if not re.match(r'^[^\r\n]*$', argstr):  # no newlines
            raise ValueError('Syntactically invalid arguments string %r' % (cmd,))
        self.transport.write('+\\' + cmd + ' ' + argstr + '\n')
        d = defer.Deferred()
        self.__waiting_for_responses.append((cmd, d))
        return d
开发者ID:bitglue,项目名称:shinysdr,代码行数:93,代码来源:__init__.py

示例15: dataReceived

# 需要导入模块: from twisted.protocols.basic import LineReceiver [as 别名]
# 或者: from twisted.protocols.basic.LineReceiver import dataReceived [as 别名]
 def dataReceived(self, data):
     if data == "\r":
         data = "\r\n"
     return LineReceiver.dataReceived(self, data)
开发者ID:mat128,项目名称:fake-switches,代码行数:6,代码来源:telnet_service.py


注:本文中的twisted.protocols.basic.LineReceiver.dataReceived方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。