def recv_plain(self): try: buf = self.buffer.popleft() if buf[4] == '\xff': errors.raise_error(buf) else: return buf except IndexError: pass pktsize = 0 try: buf = self.sock.recv(self.recvsize) while buf: totalsize = len(buf) if pktsize == 0 and totalsize >= 4: pktsize = struct.unpack("<I", buf[0:3] + '\x00')[0] if pktsize > 0 and totalsize >= pktsize + 4: size = pktsize + 4 self.buffer.append(buf[0:size]) buf = buf[size:] pktsize = 0 if not buf: try: buf = self.buffer.popleft() if buf[4] == '\xff': errors.raise_error(buf) else: return buf except IndexError, e: break elif totalsize < pktsize + 4: buf += self.sock.recv(self.recvsize)
def recv_plain(self): try: buf = self.buffer.popleft() if buf[4] == '\xff': errors.raise_error(buf) else: return buf except IndexError: pass pktsize = 0 try: buf = self.sock.recv(self.recvsize) while buf: totalsize = len(buf) if pktsize == 0 and totalsize >= 4: pktsize = struct.unpack("<I", buf[0:3]+'\x00')[0] if pktsize > 0 and totalsize >= pktsize+4: size = pktsize+4 self.buffer.append(buf[0:size]) buf = buf[size:] pktsize = 0 if not buf: try: buf = self.buffer.popleft() if buf[4] == '\xff': errors.raise_error(buf) else: return buf except IndexError, e: break elif totalsize < pktsize+4: buf += self.sock.recv(self.recvsize)
def get_response(url): """ Gets the response from the queried API service URL :param url: the queried API service URL :return: the response from the queried API service URL """ headers = {'cache-control': "no-cache"} response = requests.get(url, headers=headers) # print(response.status_code) # Debug # ===Start Response Checking=== if response.status_code != 200: # 200 means that a valid response was sent back to the client def switch(arg): switcher = { 400: InvalidData, 403: Forbidden, 404: NotFound, 429: ExceedLimit } return switcher.get(arg, ScanError) raise_error(switch(response.status_code)) # ===End Response Checking=== return response
def __init__(self, response, content, is_value): self.content_type = response.headers['content-type'] if ((is_value and self.content_type == PRIMITIVE_CONTENT_TYPE) or (self.content_type in DESERIALIZABLE_CONTENT_TYPES)): try: self.value = json.loads(content) except ValueError: self.value = content else: self.value = content self.status = response.status_code self.response = response self.content = content self.request_id = self.response.headers.get('x-fluiddb-request-id') self.error = self.response.headers.get('x-fluiddb-error-class') if self.status >= 400: raise_error(self)
def __init__(self, response, content, is_value): self.content_type = response.headers["content-type"] if (is_value and self.content_type == PRIMITIVE_CONTENT_TYPE) or ( self.content_type in DESERIALIZABLE_CONTENT_TYPES ): try: self.value = json.loads(content) except ValueError: self.value = content else: self.value = content self.status = response.status_code self.response = response self.content = content self.request_id = self.response.headers.get("x-fluiddb-request-id") self.error = self.response.headers.get("x-fluiddb-error-class") if self.status >= 400: raise_error(self)
def deco(func): def call(*args, **kwargs): try: if label: pktdata = kwargs[label] else: pktdata = args[idx] except Exception, e: raise errors.InterfaceError( "Can't check for Error packet; %s" % e) try: if pktdata and pktdata[4] == '\xff': errors.raise_error(pktdata) except errors.Error: raise except: pass return func(*args, **kwargs)