def __init__(self, observable_update_callback, host_ip, sender_callback, *args, **keys): """Shall initialize the given parameters as attributes and call the constructor of the super class. The observable_update_callback is in fact the update method of the observable implementation (in this case it may be UDPUpdateObservable). This method is called as a request is precessed by the handle method. As long as the received data is not sent by the the same host as it was received (I sent data to myself), the callback method is called. I define the "I sent data to myself"-thing as kickback. As a result of receiving lists from other hosts, the rhythm of sending our list to the multicast group has to be expanded. This is done by calling the sender_callback method. Which in fact is to expand the time of the sending rhythm. :param observable_update_callback: The callback of the observable implementation :param host_ip: The ip address of the host, where this handler is running :param sender_callback: The callback of the sending Thread. :param args: arguments for the BaseRequestHandler :param keys: keys for the BaseRequestHandler :return: None """ self._observable_callback = observable_update_callback self._sender_callback = sender_callback self._own_ip = host_ip self._logger = Log.get_logger(self.__class__.__name__) BaseRequestHandler.__init__(self, *args, **keys)
def __init__(self, request, client_address, server): """Constructor. When called without arguments, create an unconnected instance. With a hostname argument, it connects the instance; a port number is optional. """ # Am I doing the echoing? self.DOECHO = True # What opts have I sent DO/DONT for and what did I send? self.DOOPTS = {} # What opts have I sent WILL/WONT for and what did I send? self.WILLOPTS = {} # What commands does this CLI support self.COMMANDS = {} self.sock = None # TCP socket self.rawq = '' # Raw input string self.sbdataq = '' # Sub-Neg string self.eof = 0 # Has EOF been reached? self.iacseq = '' # Buffer for IAC sequence. self.sb = 0 # Flag for SB and SE sequence. self.history = [] # Command history self.RUNSHELL = True # A little magic - Everything called cmdXXX is a command # Also, check for decorated functions for k in dir(self): method = getattr(self, k) try: name = method.command_name except: if k[:3] == 'cmd': name = k[3:] else: continue name = name.upper() self.COMMANDS[name] = method for alias in getattr(method, "aliases", []): self.COMMANDS[alias.upper()] = self.COMMANDS[name] BaseRequestHandler.__init__(self, request, client_address, server)
def __init__(self, request, client_address, server): self.request = request self.client_address = client_address self.tcp_server = server # Keep track of channel information from the transport self.channels = {} self.client = request._sock # Transport turns the socket into an SSH transport self.transport = Transport(self.client) # Create the PTY handler class by mixing in TelnetHandlerClass = self.telnet_handler class MixedPtyHandler(TelnetToPtyHandler, TelnetHandlerClass): # BaseRequestHandler does not inherit from object, must call the __init__ directly def __init__(self, *args): TelnetHandlerClass.__init__(self, *args) self.pty_handler = MixedPtyHandler # Call the base class to run the handler BaseRequestHandler.__init__(self, request, client_address, server)
def __init__(self, request, client_address, server): self.my_init() BaseRequestHandler.__init__(self, request, client_address, server) return
def __init__(self, balance: Onionbalance, *args, **kwargs): StatusSocketHandlerMixin.__init__(self, balance) BaseRequestHandler.__init__(self, *args, **kwargs)
--------------------------- * socketserver 模块是对 socket 的封装 * 有点事件驱动的意思 * 类体系 BaseServer(Server最顶层类) |-TCPServer |-ThreadingTCPServer(支持多线程的TCPServer) |-ForkingTCPServer(支持多进程的TCPServer,仅仅在unix有效) |-UnixStreamServer |-UDPServer |-ThreadingUDPServer(支持多线程的UDPServer) |-ForkingUDPServer(支持多进程的UDPServer,仅仅在unix有效)) |-UnixDatagramServer |-HTTPServer |-WSGIServer BaseRequestHandler(Handle顶层类) |-StreamRequestHandler |-BaseHTTPRequestHandler |-WSGIRequestHandler * BaseServer 的一些方法,在有特殊需求的时候可以自己覆写 server_bind() * 绑定监听 * BaseServer 的一些属性 allow_reuse_address * 默认为 False,是否允许端口复用 --------------------------- tcp | ---------------------------
def __init__(self, callbacks: TCPCallbacks, settingsManager: ConfigurationManager, *args, **kwargs): self._callbacks = callbacks self._settingsManager = settingsManager BaseRequestHandler.__init__(self, *args, **kwargs)
def __init__(self, request, client_address, server): BaseRequestHandler.__init__(self, request, client_address, server) Transport.__init__(self)
def __init__(self, *args): BaseRequestHandler.__init__(self, *args)
def __init__(self, callback, srv_uri, *args, **keys): self.callback = callback self.srv_uri = srv_uri BaseRequestHandler.__init__(self, *args, **keys)
def setup(self): logging.info('Client {} connect'.format(self.client_address[0])) return BaseRequestHandler.setup(self)
def __init__(self, *args): ''' Constructor ''' BaseRequestHandler.__init__(self, *args) self.callback = None
def finish(self): logging.info('Client {} disconnect'.format(self.client_address[0])) global http_get_start http_get_start = False #stop http get thread return BaseRequestHandler.finish(self)
def __init__(self, request, client_address, server, filesystem): self._fs = filesystem self._cwd = PurePosixPath('/') BaseRequestHandler.__init__(self, request, client_address, server)
def __init__(self, request, client_address, server): logging.debug("__init__") BaseRequestHandler.__init__(self, request, client_address, server)
def __init__(self, request, client_address, server): print("__init__") #self.b = SMBus(5) BaseRequestHandler.__init__(self, request, client_address, server)
def finish(self): logging.info('Client {} disconnect'.format(self.client_address[0])) return BaseRequestHandler.finish(self)
def __init__(self, request, client_address, server): self._request_id = itertools.count(1) Thread(target=self._heartbeat_loop, daemon=True).start() BaseRequestHandler.__init__(self, request, client_address, server)
def on_request(handler: BaseRequestHandler): handler._login_config = login_config