self.buf = ""
return ret
- def readline(self, limit = -1):
+ def readline(self, limit=-1):
last = 0
while True:
- p = self.buf.find('\n', last)
+ p = self.buf.find(b'\n', last)
if p < 0:
if self.eof:
ret = self.buf
del self.dict[key.lower()]
def __iter__(self):
- return iter((list[0] for list in self.dict.itervalues()))
+ return iter((list[0] for list in self.dict.values()))
- def get(self, key, default = ""):
+ def get(self, key, default=""):
if key.lower() in self.dict:
return self.dict[key.lower()][1]
return default
class notfound(httperror):
def __init__(self):
- return super(notfound, self).__init__(404)
+ return super().__init__(404)
class redirect(dispatch.restart):
- def __init__(self, url, status = 303):
+ bases = {"url": proto.requrl,
+ "script": proto.scripturl,
+ "site": proto.siteurl}
+
+ def __init__(self, url, status=303, base="url"):
- super(redirect, self).__init__()
+ super().__init__()
self.url = url
self.status = status
+ self.bases[base]
+ self.base = base
def handle(self, req):
req.status(self.status, "Redirect")
node.children.append(self.nodefrom(child))
def addattr(self, node, k, v):
- node.attrs[unicode(k)] = unicode(v)
+ node.attrs[str(k)] = str(v)
class constructor(object):
- def __init__(self, ns, elcls = element, ctx=None):
+ def __init__(self, ns, elcls=element, ctx=None):
self._ns = ns
self._elcls = elcls
if ctx is None: ctx = context()
wrapper.__wrapped__ = callable
return wrapper
+def stringwrap(charset):
+ def dec(callable):
+ def wrapper(*args, **kwargs):
+ bk = callable(*args, **kwargs)
+ for string in bk:
+ yield string.encode(charset)
+ return wrapper
+ return dec
+
def formparams(callable):
+ spec = inspect.getargspec(callable)
def wrapper(req):
data = form.formdata(req)
- spec = inspect.getargspec(callable)
args = dict(data.items())
args["req"] = req
if not spec.keywords:
for arg in list(args):
if arg not in spec.args:
del args[arg]
- for i in range(len(spec.args) - len(spec.defaults)):
- for i in xrange(len(spec.args) - (len(spec.defaults) if spec.defaults else 0)):
++ for i in range(len(spec.args) - (len(spec.defaults) if spec.defaults else 0)):
if spec.args[i] not in args:
raise resp.httperror(400, "Missing parameter", ("The query parameter `", resp.h.code(spec.args[i]), "' is required but not supplied."))
return callable(**args)