X-Git-Url: http://dolda2000.com/gitweb/?p=wrw.git;a=blobdiff_plain;f=wrw%2Futil.py;h=7209ae42d9d96bc39f1b01594b49d1d4afb3db2b;hp=79a824071610ea9a60e50809d8b2a120290382ef;hb=6a9037cbbdde6ac644683096f8b0b0e53a678b3e;hpb=6d2e09cf5bf8ddfa126ca16d536f6b42e502f0ce diff --git a/wrw/util.py b/wrw/util.py index 79a8240..7209ae4 100644 --- a/wrw/util.py +++ b/wrw/util.py @@ -7,19 +7,13 @@ 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) + try: + data = form.formdata(req) + except IOError: + raise resp.httperror(400, "Invalid request", "Form data was incomplete") args = dict(data.items()) args["req"] = req if not spec.keywords: @@ -47,6 +41,8 @@ class funplex(object): def __call__(self, req): if req.pathinfo == "": + if "__root__" in self.dir: + return self.dir["__root__"](req) raise resp.redirect(req.uriname + "/") if req.pathinfo[:1] != "/": raise resp.notfound() @@ -58,7 +54,9 @@ class funplex(object): p = p.partition("/")[0] bi = len(p) + 1 if p in self.dir: - return self.dir[p](req.shift(bi)) + sreq = req.shift(bi) + sreq.selfpath = req.pathinfo[1:] + return self.dir[p](sreq) raise resp.notfound() def add(self, fun): @@ -119,6 +117,16 @@ def pregen(callable): wrapper.__wrapped__ = callable return wrapper +def stringwrap(charset): + def dec(callable): + @pregen + def wrapper(*args, **kwargs): + for string in callable(*args, **kwargs): + yield string.encode(charset) + wrapper.__wrapped__ = callable + return wrapper + return dec + class sessiondata(object): @classmethod def get(cls, req, create=True): @@ -266,6 +274,6 @@ class specdirty(sessiondata, metaclass=specclass): def datecheck(req, mtime): if "If-Modified-Since" in req.ihead: rtime = proto.phttpdate(req.ihead["If-Modified-Since"]) - if rtime >= math.floor(mtime): + if rtime is not None and rtime >= math.floor(mtime): raise resp.unmodified() req.ohead["Last-Modified"] = proto.httpdate(mtime)