X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Futil.py;h=92b441c08ddb5fb47227f963da8f205eb9c2c7f0;hb=2b4cce75e1eb09715b27fa94b63484c0a6f5a032;hp=79a824071610ea9a60e50809d8b2a120290382ef;hpb=03f970ca2c0e9b7f8de42c81df758081bcfd5567;p=wrw.git diff --git a/wrw/util.py b/wrw/util.py index 79a8240..92b441c 100644 --- a/wrw/util.py +++ b/wrw/util.py @@ -1,5 +1,5 @@ import inspect, math -from . import req, dispatch, session, form, resp, proto +import req, dispatch, session, form, resp, proto def wsgiwrap(callable): def wrapper(env, startreq): @@ -7,15 +7,6 @@ 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): @@ -26,7 +17,7 @@ def formparams(callable): for arg in list(args): if arg not in spec.args: del args[arg] - for i in range(len(spec.args) - (len(spec.defaults) if spec.defaults else 0)): + for i in xrange(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) @@ -58,7 +49,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): @@ -94,12 +87,12 @@ class preiter(object): self.bk = real self.bki = iter(real) self._next = None - self.__next__() + self.next() def __iter__(self): return self - def __next__(self): + def next(self): if self._next is self.end: raise StopIteration() ret = self._next @@ -140,7 +133,7 @@ class sessiondata(object): class autodirty(sessiondata): @classmethod def get(cls, req): - ret = super().get(req) + ret = super(autodirty, cls).get(req) if "_is_dirty" not in ret.__dict__: ret.__dict__["_is_dirty"] = False return ret @@ -152,18 +145,18 @@ class autodirty(sessiondata): return self._is_dirty def __setattr__(self, name, value): - super().__setattr__(name, value) + super(autodirty, self).__setattr__(name, value) if "_is_dirty" in self.__dict__: self.__dict__["_is_dirty"] = True def __delattr__(self, name): - super().__delattr__(name, value) + super(autodirty, self).__delattr__(name, value) if "_is_dirty" in self.__dict__: self.__dict__["_is_dirty"] = True class manudirty(object): def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) + super(manudirty, self).__init__(*args, **kwargs) self.__dirty = False def sessfrozen(self): @@ -206,7 +199,7 @@ class specslot(object): class specclass(type): def __init__(self, name, bases, tdict): - super().__init__(name, bases, tdict) + super(specclass, self).__init__(name, bases, tdict) sslots = set() dslots = set() for cls in self.__mro__: @@ -218,7 +211,8 @@ class specclass(type): for i, slot in enumerate(self.__sslots_a__): setattr(self, slot, specslot(slot, i, slot in dslots)) -class specdirty(sessiondata, metaclass=specclass): +class specdirty(sessiondata): + __metaclass__ = specclass __slots__ = ["session", "__sslots__", "_is_dirty"] def __specinit__(self): @@ -226,7 +220,7 @@ class specdirty(sessiondata, metaclass=specclass): @staticmethod def __new__(cls, req, sess): - self = super().__new__(cls) + self = super(specdirty, cls).__new__(cls) self.session = sess self.__sslots__ = [specslot.unbound] * len(cls.__sslots_a__) self.__specinit__() @@ -266,6 +260,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)