def __init__(self, server): TcpServerBase.__init__(self, server, Http) # Default Handlers @statichttp(self.apiroutine) def default404(env): for m in env.error(404, showerror=False): yield m @statichttp(self.apiroutine) def options(env): env.output(MemoryStream(b'')) if False: yield def main(): om = HttpRequestEvent.createMatcher(None, b'*', b'OPTIONS') dm = HttpRequestEvent.createMatcher() while True: yield (om, dm) if not self.apiroutine.event.canignore: self.apiroutine.event.canignore = True if self.apiroutine.matcher is om: self.apiroutine.subroutine( options(self.apiroutine.event), False) else: self.apiroutine.subroutine( default404(self.apiroutine.event), False) self.apiroutine.main = main self.routines.append(self.apiroutine)
def __init__(self, server): TcpServerBase.__init__(self, server, Http) # Default Handlers @statichttp(self.apiroutine) def default404(env): for m in env.error(404, showerror=False): yield m @statichttp(self.apiroutine) def options(env): env.output(MemoryStream(b"")) if False: yield def main(): om = HttpRequestEvent.createMatcher(None, b"*", b"OPTIONS") dm = HttpRequestEvent.createMatcher() while True: yield (om, dm) if not self.apiroutine.event.canignore: self.apiroutine.event.canignore = True if self.apiroutine.matcher is om: self.apiroutine.subroutine(options(self.apiroutine.event), False) else: self.apiroutine.subroutine(default404(self.apiroutine.event), False) self.apiroutine.main = main self.routines.append(self.apiroutine)
def __init__(self, server): TcpServerBase.__init__(self, server, Http) # Default Handlers @statichttp(self.apiroutine) async def default404(env): await env.error(404, showerror = False) @statichttp(self.apiroutine) async def options(env): env.output(MemoryStream(b'')) async def main(): om = HttpRequestEvent.createMatcher(None, b'*', b'OPTIONS') dm = HttpRequestEvent.createMatcher() while True: ev, m = await M_(om, dm) if not ev.canignore: ev.canignore = True if m is om: self.apiroutine.subroutine(options(ev), False) else: self.apiroutine.subroutine(default404(ev), False) self.apiroutine.main = main self.routines.append(self.apiroutine)
def __init__(self, server): self._redis_clients = {} TcpServerBase.__init__(self, server, Redis) self._sequencial = False self._sequencialsince = time() self._enterlock = False self._enterlocksince = time() if self.serialize == 'pickle' or self.serialize == 'cpickle' or self.serialize == 'cPickle': if self.serialize == 'pickle': if not self.cpickle: p = pickle else: p = cPickle else: p = cPickle if self.pickleversion is None or self.pickleversion == 'default': pickleversion = None elif self.pickleversion == 'highest': pickleversion = p.HIGHEST_PROTOCOL else: pickleversion = self.pickleversion if self.deflate: def _encode(obj): return compress(p.dumps(obj, pickleversion), 1) else: def _encode(obj): return p.dumps(obj, pickleversion) self._encode = _encode if self.deflate: def _decode(data): if data is None: return None elif isinstance(data, Exception): raise data else: try: return p.loads(decompress(data)) except zlib_error: return p.loads(data) else: def _decode(data): if data is None: return None elif isinstance(data, Exception): raise data else: return p.loads(data) self._decode = _decode else: if self.deflate: def _encode(obj): return compress(json.dumps(obj, default=encode_default).encode('utf-8'), 1) self._encode = _encode def _decode(data): if data is None: return None elif isinstance(data, Exception): raise data else: try: data = decompress(data) except zlib_error: pass if not isinstance(data, str) and isinstance(data, bytes): data = data.decode('utf-8') return json.loads(data, object_hook=decode_object) self._decode = _decode else: def _encode(obj): return json.dumps(obj, default=encode_default).encode('utf-8') self._encode = _encode def _decode(data): if data is None: return None elif isinstance(data, Exception): raise data elif not isinstance(data, str) and isinstance(data, bytes): data = data.decode('utf-8') return json.loads(data, object_hook=decode_object) self._decode = _decode self.appendAPI(api(self.getclient), api(self.get, self.apiroutine), api(self.set, self.apiroutine), api(self.delete, self.apiroutine), api(self.mget, self.apiroutine), api(self.mset, self.apiroutine), api(self.update, self.apiroutine), api(self.mupdate, self.apiroutine), api(self.updateall, self.apiroutine), api(self.updateallwithtime, self.apiroutine), api(self.listallkeys, self.apiroutine))
def __init__(self, server): TcpServerBase.__init__(self, server, Openflow)
def __init__(self, server): TcpServerBase.__init__(self, server, JsonRPC)