def connect(self): if self._client is not None: while not (yield self._client.connect()): Log.e(TAG, "client connect error. retry after 1 sec") yield tornado.gen.sleep(1) raise tornado.gen.Return() raise AttributeError("tornadis client is None!")
def _execute_callbacks(queue, *args, **kwargs): # type: (list, tuple, dict) -> None for i in range(len(queue)): callback = queue.pop() try: callback(*args, **kwargs) except Exception as e: Log.e(TAG, b"callback execute error", e) Log.d(TAG, b"callbacks execution done")
def _handle_request(self, data): try: start_line, headers = self.parse_headers(data) request = httputil.HTTPServerRequest( headers=headers, start_line=httputil.parse_request_start_line(start_line)) deli = self._handler.application.find_handler(request) getattr(self._handler, request.method.lower(), self._handler.r404)(*deli.path_args, **deli.path_kwargs) except httputil.HTTPInputError as e: Log.e(TAG, b"_handle_request error", e)
def authenticate(self, headers): # type: (dict) -> Account or None for header_name in ["Authorization", "WWW-Authorization"]: auth_data = headers.get(header_name, None) if auth_data is not None: try: auth_type, token = auth_data.split(" ") auth_method = { "otp": self.auth_otp, "basic": self.auth_basic }.get(auth_type.lower(), None) if auth_method is not None: raise tornado.gen.Return((yield auth_method( Base64.decode(token).decode("utf-8")))) except Exception as e: Log.e(TAG, "authenticate error", e)
def _handle_response(self, data): try: response = httputil.parse_response_start_line(data) Log.d(TAG, b"_handle_response %r" % response) except httputil.HTTPInputError as e: Log.e(TAG, b"_handle_response error", e)