本文整理汇总了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'))
示例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
示例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')
示例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)
示例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()
示例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()
示例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()
示例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()
示例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
示例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
示例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()
示例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())
示例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...")
示例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
示例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)