From: Fredrik Tolf Date: Mon, 2 Sep 2013 01:26:39 +0000 (+0200) Subject: Merge branch 'master' into python3 X-Git-Url: http://dolda2000.com/gitweb/?p=wrw.git;a=commitdiff_plain;h=babf3e21cb06bf867e3ec98003d4a077090b8839 Merge branch 'master' into python3 Conflicts: wrw/resp.py wrw/util.py --- babf3e21cb06bf867e3ec98003d4a077090b8839 diff --cc wrw/form.py index 98d2ed9,0363b0b..c97b0f9 --- a/wrw/form.py +++ b/wrw/form.py @@@ -88,10 -88,10 +88,10 @@@ class formpart(object) 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 diff --cc wrw/req.py index 11f856c,41fd330..016d2d8 --- a/wrw/req.py +++ b/wrw/req.py @@@ -19,9 -19,9 +19,9 @@@ class headdict(object) 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 diff --cc wrw/resp.py index ebd98ec,7fae787..965df6c --- a/wrw/resp.py +++ b/wrw/resp.py @@@ -59,13 -59,19 +59,19 @@@ class httperror(usererror) 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") diff --cc wrw/sp/cons.py index 74a6ea6,ce258c6..c4d9999 --- a/wrw/sp/cons.py +++ b/wrw/sp/cons.py @@@ -59,10 -60,10 +59,10 @@@ class context(object) 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() diff --cc wrw/util.py index ed32cc6,7459b6d..79a8240 --- a/wrw/util.py +++ b/wrw/util.py @@@ -7,26 -7,17 +7,26 @@@ def wsgiwrap(callable) 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)