def get_module(self, module): for url in self.urls: LOG.info("url 0 [ %s ] , module [ %s ]" % (url[0], module)) if url[0] == module: LOG.debug("found it " + url[1]["target"]) module = _import(url[1]["target"]) return module else: LOG.error("not found module named %s in file setting" % module)
def search(self): search_path = self.root + "/*/*_setting.py" _p_path_list = glob.glob(search_path) if not _p_path_list: LOG.error("Not found any project in path " + self.root) return None for path in _p_path_list: LOG.debug("Add project " + path) self.projects.append(Project(path)) LOG.debug("Found %d project in path" % len(self.projects))
def handshake(self): _hash = self.validate_key() _hs = [] _hs.append("HTTP/1.1 101 Switching Protocols") _hs.append("Upgrade: websocket") _hs.append("Connection: Upgrade") _hs.append("Sec-WebSocket-Accept: " + _hash) # _hs.append("Sec-WebSocket-Protocol: %s" % self.header.protocol) response = "\r\n".join(_hs) + "\r\n\r\n" LOG.debug("handshake response : \n%s " % response) return response
def lineReceived(self, line): self.state = WebSocketProtocol.STATE_CONNECTING if line: LOG.debug("new line was received : %s " % line) self._header.append(line.decode()) else: self.header = Header("\n".join(self._header)) _p = Protocol13(self.header) if _p: self.session = self.factory.create(self) self.protocol = _p response = _p.handshake() self.transport.write(response.encode()) self.state = WebSocketProtocol.STATE_OPEN self.session.connected() self.setRawMode()
def connectionMade(self): now_number = len(self.factory.find()) LOG.debug("new connection has been accepted, now was %d " % now_number) self._header = []
def _init_base_info(self, line): LOG.debug("base info from header : %s" % line) self.scheme, self.uri, self.protocol = line.split() self.p = dict() self.parse_uri()
def _process_frame_header(self, data): # first byte contains fin, rsv and ops b = data[0] #fin: #Indicates that this is the final fragment in a message. The first #fragment MAY also be the final fragment self._frame_fin = (b & 0x80) != 0 #rsv #MUST be 0 unless an extension is negotiated which defines meanings #for non-zero values. If a nonzero value is received and none of #the negotiated extensions defines the meaning of such a nonzero #value, the receiving endpoint MUST _Fail the WebSocket Connection_. self._frame_rsv = (b & 0x70) >> 4 self._frame_ops = b & 0x0f # second byte contains mask and payload length b = data[1] self._frame_mask = (b & 0x80) != 0 frame_payload_len1 = b & 0x7f if (self._frame_mask): mask_len = 4 else: mask_len = 0 # i is frame index. It's at 2 here because we've already processed the # first 2 bytes of the frame. i = 2 if frame_payload_len1 < 126: self._frame_header_len = i + mask_len self._frame_payload_len = frame_payload_len1 elif frame_payload_len1 == 126: self._frame_header_len = i + 2 + mask_len self._frame_payload_len = struct.unpack( "!H", data[i:i+2])[0] i += 2 elif frame_payload_len1 == 127: self._frame_header_len = i + 8 + mask_len self._frame_payload_len = struct.unpack( "!Q", data[i:i+8])[0] i += 8 self._header_index = i LOG.debug("====== received data header ======") LOG.debug("_frame_fin = {}".format(self._frame_fin)) LOG.debug("_frame_rsv = {}".format(self._frame_rsv)) LOG.debug("_frame_ops = {}".format(self._frame_ops)) LOG.debug("_frame_mask = {}".format(self._frame_mask)) LOG.debug("_frame_mask_len = {}".format(mask_len)) LOG.debug("_header_index = {}".format(self._header_index)) LOG.debug("_frame_payload_len = {}".format(self._frame_payload_len)) LOG.debug("=================================")
def _import(_path): LOG.debug("import module with path " + _path) return importlib.import_module(_path)
def add_search_path(_path): LOG.debug("add search path " + _path) sys.path.insert(0, _path)