當前位置: 首頁>>代碼示例>>Python>>正文


Python protocol.Protocol類代碼示例

本文整理匯總了Python中protocol.Protocol的典型用法代碼示例。如果您正苦於以下問題:Python Protocol類的具體用法?Python Protocol怎麽用?Python Protocol使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Protocol類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_load_non_existant_protocol

def test_load_non_existant_protocol():
    """
    test loading protocol file that doesn't exist
    """
    Protocol.load(path(__file__).parent /
                   path('protocols') /
                   path('no protocol'))
開發者ID:ryanfobel,項目名稱:microdrop,代碼行數:7,代碼來源:test_protocol.py

示例2: __init__

 def __init__(self, executor, browser):
     Protocol.__init__(self, executor, browser)
     self.webdriver_binary = executor.webdriver_binary
     self.webdriver_args = executor.webdriver_args
     self.capabilities = self.executor.capabilities
     self.session_config = None
     self.server = None
開發者ID:frivoal,項目名稱:web-platform-tests,代碼行數:7,代碼來源:base.py

示例3: __init__

 def __init__(self, conn):
     Protocol.__init__(self, conn)
     self.mapfn = self.reducefn = None
     
     self.register_command('mapfn', self.set_mapfn)
     self.register_command('reducefn', self.set_reducefn)
     self.register_command('map', self.call_mapfn)
     self.register_command('reduce', self.call_reducefn)
     
     self.send_command('ready')
開發者ID:ec262,項目名稱:client,代碼行數:10,代碼來源:worker.py

示例4: __init__

 def __init__(self, worker, server):
     """Connect to the specified worker"""
     Protocol.__init__(self)
     self.server = server
     self.register_command('taskcomplete', self.complete_task)
     self.register_command('ready', lambda x, y: self.initialize_worker())
     # Create connection
     logging.debug("Connecting to worker %s:%d..." % worker)
     self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
     self.connect(worker)
開發者ID:ec262,項目名稱:client,代碼行數:10,代碼來源:foreman.py

示例5: __init__

 def __init__(self):
     Protocol.__init__(self)
     # Module-specific attributes
     self.attributes = {
         "NAME": 'ftp',
         "MODULE_SPEAKS_PROTOCOL": True,
         "PROTOCOL_DEFAULT_PORTS": [21],
         "PROTOCOL_SPEAKS_FIRST": True,
         "PATTERN": r"\d{3}(\s|-).*"
     }
     self.compile_pattern()
開發者ID:aych,項目名稱:portprobe,代碼行數:11,代碼來源:ftp.py

示例6: __init__

 def __init__(self):
     Protocol.__init__(self)
     # Module-specific attributes
     self.attributes = {
         "NAME": 'http',
         "MODULE_SPEAKS_PROTOCOL": True,
         "PROTOCOL_DEFAULT_PORTS": [80, 1080, 8080],
         "PROTOCOL_SPEAKS_FIRST": False,
         "PATTERN": r"^HTTP.+?\s\d{3}\s.+?"
     }
     self.compile_pattern()
開發者ID:aych,項目名稱:portprobe,代碼行數:11,代碼來源:http.py

示例7: Client

class Client(Protocol):
    def __init__(self):
        self.engine = Engine()
        self.engine.print_traceback = True
        self.proto = FitnesseProtocol(self)

    def ack(self):
        self.ack_received = True

    def connectionMade(self):
        self.socketToken = sys.argv[4]
        request = "GET /?responder=socketCatcher&ticket=%s HTTP/1.1\r\n\r\n" % self.socketToken
        bytes = request.encode("UTF-8")
        self.transport.write(bytes)

    def dataReceived(self, data):
        self.proto.dataReceived(data)

    def content(self, data):
        self.doc = Document(data)
        self.doc.visit_tables(self)

    def on_table(self, table):
        fixture = self.engine.process(table, throw=False)
        self.write_table(table)

    def on_comment(self, node):
        html = str(node.toxml())
        self.transport.write(util.format_10_digit_number(len(html) + 1))
        self.transport.write(html)
        self.transport.write('\n')
    
    def done(self):
        self.transport.loseConnection()
        
    def write_table(self, table):
        html = str(table.toxml()) # Fixme : str() workaround for 'Data must not be unicode'
        self.transport.write(util.format_10_digit_number(len(html) + 1))
        self.transport.write(html)
        self.transport.write('\n')
        
    def write_number(self, number):
        self.transport.write(util.format_10_digit_number(number))

    def report(self):
        summary = self.engine.summary

        # 0 right, 0 wrong, 0 ignored, 0 exceptions
        self.write_number(0)
        self.write_number(summary.right)
        self.write_number(summary.wrong)
        self.write_number(summary.ignored)
        self.write_number(summary.exceptions)
        summary.reset()
開發者ID:epronk,項目名稱:pyfit2,代碼行數:54,代碼來源:client.py

示例8: __init__

 def __init__(self):
     Protocol.__init__(self)
     # Module-specific attributes
     self.attributes = {
         "NAME": 'socks5',
         "MODULE_SPEAKS_PROTOCOL": True,
         "PROTOCOL_DEFAULT_PORTS": [1080, 8080],
         "PROTOCOL_SPEAKS_FIRST": False,
         "PATTERN": r""
     }
     self.compile_pattern()
開發者ID:aych,項目名稱:portprobe,代碼行數:11,代碼來源:socks5.py

示例9: __init__

 def __init__(self):
     Protocol.__init__(self)
     # Module-specific attributes
     self.attributes = {
         "NAME": 'irc',
         "MODULE_SPEAKS_PROTOCOL": True,
         "PROTOCOL_DEFAULT_PORTS": [6660, 6661, 6662, 6663, 6664, 6665, 6666, 6667, 6668, 6669, 7000],
         "PROTOCOL_SPEAKS_FIRST": True,
         "PATTERN": r"[0-9A-Z:a-z-\s*._]+?:[0-9A-Z:a-z-\s*._]+?"
     }
     self.compile_pattern()
     self.unprocessed = ''
     self.registered = False
開發者ID:aych,項目名稱:portprobe,代碼行數:13,代碼來源:irc.py

示例10: get_metadata

    def get_metadata(self):
        meta_cmds = [
            ("interface", Protocol.FE_CMD_INTERFACE),
            ("firmware", Protocol.FE_CMD_FIRMWARE),
            ("decoder", Protocol.FE_CMD_DECODER),
            ("build_date", Protocol.FE_CMD_BUILDDATE),
            ("compiler", Protocol.FE_CMD_COMPILER),
            ("os", Protocol.FE_CMD_OSNAME),
            ("build_by", Protocol.FE_CMD_USER),
            ("email", Protocol.FE_CMD_EMAIL)
        ]
        meta = {}
        location_ids = None

        for _, cmd in meta_cmds:
            self.queue_out.put(Protocol.create_packet(cmd))

        self.queue_out.put(Protocol.create_packet(Protocol.FE_CMD_LOCATION_ID_LIST, data=bytearray(b'\x00\x00\x00'), use_length=True))

        while True:
            if all(name in meta for name, _ in meta_cmds) and location_ids is not None:
                break

            try:
                if not self.queue_out.empty():
                    packet = self.queue_out.get(False)
                    LOG.debug("--> %s" % binascii.hexlify(packet[1:-2]))
                    self.ser.write(packet)
                    self.ser.flush()

                    resp = self.queue_in.get()
                    LOG.debug("<-- %s" % binascii.hexlify(resp))
                    data = Protocol.decode_packet(resp)

                    # FIXME: hax, make more elegant
                    meta_info = [(name, data[1].decode("ascii").rstrip('\0')) for name, cmd_id in meta_cmds if cmd_id + 1 == data[0]]
                    if meta_info:
                        m = meta_info[0]
                        LOG.debug("Received meta: %s" % m[0])
                        meta[m[0]] = m[1]
                    elif data[0] == Protocol.FE_CMD_LOCATION_ID_LIST + 1:
                        ids = len(data[1]) / 2
                        LOG.debug("Received %d location IDs" % ids)
                        location_ids = struct.unpack_from(">%dH" % ids, buffer(data[1]))

                    # TODO: error message handling

            except Queue.Empty:
                pass

        return meta, location_ids
開發者ID:MrOnion,項目名稱:fuct,代碼行數:51,代碼來源:interrogator.py

示例11: handle

    def handle(self):
        proto = Protocol(self.rfile.read, self.wfile.write)
        command, args = proto.read_cmd()

        # switch case to handle the specific git command
        if command == 'git-upload-pack':
            cls = UploadPackHandler
        elif command == 'git-receive-pack':
            cls = ReceivePackHandler
        else:
            return

        h = cls(self.server.backend, self.rfile.read, self.wfile.write)
        h.handle()
開發者ID:SRabbelier,項目名稱:hg-git,代碼行數:14,代碼來源:server.py

示例12: __init__

 def __init__(self, **args):
     # Here we are going to intercept the original _defineParams function
     # and replace by an empty one, this is to postpone the definition of 
     # params until the protocol is set and then self.protocol can be used
     # for a more dynamic definition
     object.__setattr__(self, '_defineParamsBackup', self._defineParams)
     object.__setattr__(self, '_defineParams', self._defineParamsEmpty)
 
     Protocol.__init__(self, **args)
     Viewer.__init__(self, **args)
     self.allowHeader.set(False)
     self.showPlot = True # This flag will be used to display a plot or return the plotter
     self._tkRoot = None
     self.formWindow = None
     self.setWorkingDir(self.getProject().getTmpPath())
開發者ID:coocoky,項目名稱:scipion,代碼行數:15,代碼來源:viewer.py

示例13: get_ram_data

    def get_ram_data(self, location, size):
        LOG.debug("Get RAM location: 0x%02x, offset: %d, size: %d" % (location[0], location[1], size))
        packet = Protocol.create_packet(Protocol.FE_CMD_RAM_READ, location, size)
        LOG.debug("--> %s" % binascii.hexlify(packet[1:-2]))
        self.ser.write(packet)
        self.ser.flush()

        resp = self.queue_in.get(5)
        if resp:
            LOG.debug("<-- %s" % binascii.hexlify(resp))
            data = Protocol.decode_packet(resp)
            if data[0] == Protocol.FE_CMD_RAM_READ + 1:
                return data[1]
        else:
            LOG.warn("Failed to load location...")
開發者ID:MrOnion,項目名稱:fuct,代碼行數:15,代碼來源:interrogator.py

示例14: ServoCtrl

class ServoCtrl(ChassisDev):

    TYPE = 0x82
    # 12 bytes data package format in struct, only first byte valid
    pack_pmt = "4B2f"


    def __init__(self, serial_dev):
        self.protocol = Protocol(self.TYPE, self.pack_pmt)

        self.serial_dev = serial_dev

        ChassisDev.__init__(self, "Servo",
                            sub_topic = "/robot_chassis/Servo",
                            sub_msg_class = Byte)

    def start_subscribe(self):

        def cb_func(pwm_data):
            self.dev_write(self.pwm_to_encoder(pwm_data.data))

        ChassisDev.start_sub(self, cb_func)

    def pwm_to_encoder(self, pwm):
        """ construct the payload
        """
        return [pwm, 0,0,0,0,0]

    def dev_write(self, data):
        """ write data to serial
        """
        self.serial_dev.write(self.protocol.encode(data))
        print "Servo: Write to serial", data
開發者ID:CaoTaMaBi,項目名稱:open-robot,代碼行數:33,代碼來源:servo_ctrl.py

示例15: Battery

class Battery(ChassisDev):

    TYPE = 0x03
    # 12 bytes data package format in struct
    pack_pmt = "2f2H"

    def __init__(self):
        self.protocol = Protocol(self.TYPE, self.pack_pmt)

        ChassisDev.__init__(self, "smart_battery",
                            pub_topic = "smart_battery",
                            pub_msg_class = SmartBatteryStatus)
        self.battery_status = SmartBatteryStatus()

        ChassisDev.start_pub(self)

    def data_handler(self, bin_data_pack):
        try:
            voltage, rate, _,_ = \
                self.protocol.decode(bin_data_pack)
        except e:
            print e
            return

        self.battery_status.voltage = voltage
        self.battery_status.rate = rate
        self.battery_status.charge_state = 0
        if voltage > 2000:
            self.battery_status.percentage = 100 - (2520 - voltage)/4
        else:
            self.battery_status.percentage = 100 - (1260 - voltage)/1.6
        ChassisDev.pub_data_update(self, self.battery_status)
開發者ID:CaoTaMaBi,項目名稱:open-robot,代碼行數:32,代碼來源:battery.py


注:本文中的protocol.Protocol類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。