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


Python dispatcher.send方法代码示例

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


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

示例1: stop

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def stop(self):
		dispatcher.send(data = "LinkLayer stopping..", signal = LinkLayer.SIGNAL_LINKLAYER_STOPPING, sender = LinkLayer.DISPATCHER_SENDER_NAME)
		self.state["EVENT_STOP_WRITE"].set()
		self.state["EVENT_STOP_READ"].set()
		# terminate read thread if set
		if self.state.has_key("read_thread"):
			try:
				self.state["read_thread"].join()
			except RuntimeError:
				pass # same thread or not started
		# terminate write thread if set
		if self.state.has_key("write_thread") and threading.currentThread != self.state["write_thread"]:
			try:
				self.state["write_thread"].join()
			except RuntimeError:
				pass # same thread or not started

		dispatcher.send(data = "LinkLayer stopped", signal = LinkLayer.SIGNAL_LINKLAYER_STOPPED, sender = LinkLayer.DISPATCHER_SENDER_NAME) 
开发者ID:RoganDawes,项目名称:P4wnP1,代码行数:20,代码来源:LinkLayer.py

示例2: start

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def start(self):
		#sync linklayer (Send with SEQ till correct ACK received)
		self.__sync_link()

		# start write thread
		#thread.start_new_thread(self.write_rep, ( ))
		self.state["write_thread"] = Thread(target = self.write_rep, name = "LinkLayer writer", args = ( ))
		self.state["write_thread"].start()

		# start read thread
		#thread.start_new_thread(self.read_rep, ( ) )
		self.state["read_thread"] = Thread(target = self.read_rep, name = "LinkLayer reader", args = ( ))
		self.state["read_thread"].start()

		dispatcher.send(data = "LinkLayer running", signal = LinkLayer.SIGNAL_LINKLAYER_STARTED, sender = LinkLayer.DISPATCHER_SENDER_NAME)
		# we don't send this from __sync_link, but when write thread is started, as this is resend on reconnect request after
		# write thread restart too (in difference to SIGNAL_LINK_LAYER_STARTED which is only send once)
		dispatcher.send(data = "LinkLayer connection established", signal = LinkLayer.SIGNAL_LINKLAYER_CONNECTION_ESTABLISHED, sender = LinkLayer.DISPATCHER_SENDER_NAME) 
开发者ID:RoganDawes,项目名称:P4wnP1,代码行数:20,代码来源:LinkLayer.py

示例3: print_msg

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def print_msg(class_name, method, message, level='DEBUG'):
    if level.lower() != 'error' and Commons.quiet:
        return

    log_level = '[' + level + ']'
    log_message = '{:7s} {:11s}  {:35s} {!s:s}'.format(log_level, class_name, method, message)
    try:
        print(log_message)
        Logger(log_message)
    except:
        print(log_message.encode('utf-8'))

    if level == 'ERROR':
        SIGNAL = 'publish-error-signal'
        sender = {}
        new_message = ''.join(str(v) for v in message)
        dispatcher.send(signal=SIGNAL, sender=sender, message=new_message, class_name=class_name, method_name=method) 
开发者ID:homedepot,项目名称:flow,代码行数:19,代码来源:commons.py

示例4: listen

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def listen(self):
        while self._running:
            socket_list = [self.serial]
            read_sockets, write_sockets, error_sockets = select.select(socket_list, socket_list, [], 5)
            if read_sockets:
                data = self.serial.recv(1024)
                if data:
                    self.read_data(data)
                else:
                    LOGGER.warning('OOPS connection lost, reconnect...')
                    self.reconnect()
            if write_sockets:
                while not self.queue.empty():
                    data = self.queue.get()
                    try:
                        self.serial.send(data)
                    except OSError:
                        LOGGER.warning('OOPS connection lost, reconnect...')
                        self.reconnect()
            time.sleep(0.05) 
开发者ID:doudz,项目名称:zigate,代码行数:22,代码来源:transport.py

示例5: __on_reconnect

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def __on_reconnect(self):
		#print "Handling reconnect..."
		#print "Stop Write thread..."
		dispatcher.send(data = "LinkLayer connection reset by peer", signal = LinkLayer.SIGNAL_LINKLAYER_CONNECTION_RESET, sender = LinkLayer.DISPATCHER_SENDER_NAME)

		# stop write thread (we want to write from this thread on connection establishment)
		self.state["EVENT_STOP_WRITE"].set() # set stop event for write thread

		# wait for write thread to terminate
		self.state["write_thread"].join() # wait for current write thread to terminate
		#print "Write thread terminated"
				
		# empty queues with old data
		#print "Clearing input and output queues..."
		self.state["qout"].queue.clear()
		#self.state["qin"].queue.clear()


		# write empty report in order to terminate the blocking read on other end 
		# (peer is waiting for incoming report after sending reconnect request, which is never
		# sent after the write thread has been terminated)
		outbytes = struct.pack('!BB62s', 0, 0, "" )
		self.fout.write(outbytes)
		self.fout.flush()
				
		# resync connection (sync SEQ to ACK before restarting write thread)
		self.__sync_link()

		# restart write thread
		#print "Restarting write thread..."
		self.state["EVENT_STOP_WRITE"].clear()
		self.state["write_thread"] = Thread(target = self.write_rep, name = "LinkLayer writer", args = ( ))
		self.state["write_thread"].start()

		# we don't send this after sync, but when write thread is restarted
		dispatcher.send(data = "LinkLayer connection established", signal = LinkLayer.SIGNAL_LINKLAYER_CONNECTION_ESTABLISHED, sender = LinkLayer.DISPATCHER_SENDER_NAME) 
开发者ID:RoganDawes,项目名称:P4wnP1,代码行数:38,代码来源:LinkLayer.py

示例6: __write_raw_stream

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def __write_raw_stream(self, stream):
                # should keep track of LinkLayer's output queue size (needs additional dispatcher messages)
                dispatcher.send(data = stream, signal = TransportLayer.SIGNAL_TRANSPORTLAYER_SEND_STREAM, sender = TransportLayer.TRANSPORTLAYER_SENDER_NAME_DOWN) 
开发者ID:RoganDawes,项目名称:P4wnP1,代码行数:5,代码来源:TransportLayer.py

示例7: publish_changes

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def publish_changes(self, etype, echid):
        """Post updates for specified event type."""
        _LOGGING.debug('%s Update: %s, %s',
                       self.name, etype, self.fetch_attributes(etype, echid))
        signal = 'ValueChanged.{}'.format(self.cam_id)
        sender = '{}.{}'.format(etype, echid)
        if dispatcher:
            dispatcher.send(signal=signal, sender=sender)

        self._do_update_callback('{}.{}.{}'.format(self.cam_id, etype, echid)) 
开发者ID:mezz64,项目名称:pyHik,代码行数:12,代码来源:hikvision.py

示例8: dispatch_signal

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def dispatch_signal(signal=dispatcher.Any, sender=dispatcher.Anonymous,
                    *arguments, **named):
    '''
    Dispatch signal with exception proof
    '''
    LOGGER.debug('Dispatch %s', signal)
    try:
        dispatcher.send(signal, sender, *arguments, **named)
    except Exception:
        LOGGER.error('Exception dispatching signal %s', signal)
        LOGGER.error(traceback.format_exc()) 
开发者ID:doudz,项目名称:zigate,代码行数:13,代码来源:core.py

示例9: send_to_transport

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def send_to_transport(self, data):
        if not self.connection or not self.connection.is_connected():
            LOGGER.error('Not connected to zigate')
            return
        self.connection.send(data) 
开发者ID:doudz,项目名称:zigate,代码行数:7,代码来源:core.py

示例10: send_data

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def send_data(self, cmd, data="", wait_response=None, wait_status=True):
        '''
        send data through ZiGate
        '''
        LOGGER.debug('REQUEST : 0x{:04x} {}'.format(cmd, data))
        self._last_status[cmd] = None
        if wait_response:
            self._clear_response(wait_response)
        if isinstance(cmd, int):
            byte_cmd = struct.pack('!H', cmd)
        elif isinstance(data, str):
            byte_cmd = bytes.fromhex(cmd)
        else:
            byte_cmd = cmd
        if isinstance(data, str):
            byte_data = bytes.fromhex(data)
        else:
            byte_data = data
        assert type(byte_cmd) == bytes
        assert type(byte_data) == bytes
        length = len(byte_data)
        byte_length = struct.pack('!H', length)
        checksum = self.checksum(byte_cmd, byte_length, byte_data)

        msg = struct.pack('!HHB%ds' % length, cmd, length, checksum, byte_data)
        LOGGER.debug('Msg to send %s', hexlify(msg))

        enc_msg = self.zigate_encode(msg)
        enc_msg.insert(0, 0x01)
        enc_msg.append(0x03)
        encoded_output = bytes(enc_msg)
        LOGGER.debug('Encoded Msg to send %s', hexlify(encoded_output))

        self.send_to_transport(encoded_output)
        if wait_status:
            status = self._wait_status(cmd)
            if wait_response and status is not None:
                r = self._wait_response(wait_response)
                return r
            return status
        return False 
开发者ID:doudz,项目名称:zigate,代码行数:43,代码来源:core.py

示例11: identify_device

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def identify_device(self, time_sec=5):
        '''
        send identify command
        sec is time in second
        '''
        ep = list(self.endpoints.keys())
        ep.sort()
        if ep:
            endpoint = ep[0]
        else:
            endpoint = 1
        self._zigate.identify_send(self.addr, endpoint, time_sec) 
开发者ID:doudz,项目名称:zigate,代码行数:14,代码来源:core.py

示例12: send

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def send(self, data):
        self.queue.put(data) 
开发者ID:doudz,项目名称:zigate,代码行数:4,代码来源:transport.py

示例13: reconnect

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def reconnect(self, retry=True):
        delay = 1
        while self._running:
            try:
                if self.serial:
                    self.serial.close()  # just to be sure it's not already open
                self.serial = self.initSerial()
                break
            except ZIGATE_NOT_FOUND:
                LOGGER.error('ZiGate has not been found, please check configuration.')
                if not retry:
                    sys.exit(2)
            except Exception:
                if not retry:
                    LOGGER.error('Cannot connect to ZiGate using port {}'.format(self._port))
                    raise ZIGATE_CANNOT_CONNECT('Cannot connect to ZiGate using port {}'.format(self._port))
                    sys.exit(2)
                # maybe port has change so try to find it
                if delay > 3:
                    self._port = 'auto'
            msg = 'Failed to connect, retry in {} sec...'.format(int(delay))
            dispatcher.send(ZIGATE_FAILED_TO_CONNECT, message=msg)
            LOGGER.error(msg)
            time.sleep(int(delay))
            if delay < 30:
                delay *= 1.5 
开发者ID:doudz,项目名称:zigate,代码行数:28,代码来源:transport.py

示例14: do_GET

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def do_GET(self):

        # get the requested path and the client IP
        resource = self.path
        clientIP = self.client_address[0]
        sessionID = None

        cookie = self.headers.getheader("Cookie")
        if cookie:
            # search for a SESSIONID value in the cookie
            parts = cookie.split(";")
            for part in parts:
                if "SESSIONID" in part:
                    # extract the sessionID value
                    name, sessionID = part.split("=")

        # fire off an event for this GET (for logging)
        dispatcher.send("[*] "+resource+" requested from "+str(sessionID)+" at "+clientIP, sender="HttpHandler")

        # get the appropriate response from the agent handler
        (code, responsedata) = self.server.agents.process_get(self.server.server_port, clientIP, sessionID, resource)

        # write the response out
        self.send_response(code)
        self.end_headers()
        self.wfile.write(responsedata)
        self.wfile.flush()
        # self.wfile.close() # causes an error with HTTP comms 
开发者ID:EmpireProject,项目名称:EmPyre,代码行数:30,代码来源:http.py

示例15: do_POST

# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import send [as 别名]
def do_POST(self):

        resource = self.path
        clientIP = self.client_address[0]
        sessionID = None

        cookie = self.headers.getheader("Cookie")
        if cookie:
            # search for a SESSIONID value in the cookie
            parts = cookie.split(";")
            for part in parts:
                if "SESSIONID" in part:
                    # extract the sessionID value
                    name, sessionID = part.split("=")

        # fire off an event for this POST (for logging)
        dispatcher.send("[*] Post to "+resource+" from "+str(sessionID)+" at "+clientIP, sender="HttpHandler")

        # read in the length of the POST data
        if self.headers.getheader('content-length'):
            length = int(self.headers.getheader('content-length'))
            postData = self.rfile.read(length)

            # get the appropriate response for this agent
            (code, responsedata) = self.server.agents.process_post(self.server.server_port, clientIP, sessionID, resource, postData)

            # write the response out
            self.send_response(code)
            self.end_headers()
            self.wfile.write(responsedata)
            self.wfile.flush()
            # self.wfile.close() # causes an error with HTTP comms

    # supress all the stupid default stdout/stderr output 
开发者ID:EmpireProject,项目名称:EmPyre,代码行数:36,代码来源:http.py


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