From c33f2d6c068bf96c56e8e6966340f5f6e448df96 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sat, 3 Dec 2011 07:43:47 +0100 Subject: [PATCH] Various python3 modifications. --- wrw/cookie.py | 10 +++++----- wrw/dispatch.py | 2 +- wrw/filesys.py | 2 +- wrw/form.py | 2 +- wrw/req.py | 2 +- wrw/resp.py | 12 ++++++------ wrw/session.py | 8 ++++---- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/wrw/cookie.py b/wrw/cookie.py index 37e8708..c6ae36c 100644 --- a/wrw/cookie.py +++ b/wrw/cookie.py @@ -1,4 +1,4 @@ -import Cookie +import http.cookies __all__ = ["cookies", "get", "add"] @@ -10,10 +10,10 @@ def addcookies(req): class cookiedict(object): def __init__(self, req): try: - self.bk = Cookie.SimpleCookie(req.ihead.get("Cookie")) - except Cookie.CookieError: - self.bk = Cookie.SimpleCookie() - self.codec = Cookie.SimpleCookie() + self.bk = http.cookies.SimpleCookie(req.ihead.get("Cookie")) + except http.cookies.CookieError: + self.bk = http.cookies.SimpleCookie() + self.codec = http.cookies.SimpleCookie() req.oncommit(addcookies) def __getitem__(self, name): diff --git a/wrw/dispatch.py b/wrw/dispatch.py index 5a7bda0..b6009af 100644 --- a/wrw/dispatch.py +++ b/wrw/dispatch.py @@ -20,7 +20,7 @@ def handle(req, startreq, handler): try: resp = handler(req) break - except restart, i: + except restart as i: handler = i.handle req.commit(startreq) return resp diff --git a/wrw/filesys.py b/wrw/filesys.py index 264cf14..56d58aa 100644 --- a/wrw/filesys.py +++ b/wrw/filesys.py @@ -29,7 +29,7 @@ class filehandler(object): elif ext == "html": ctype = "text/html" req.ohead["Content-Type"] = ctype - return open(path, "r") + return open(path, "rb") def resolvefile(self, req, curpath, el): if os.path.isfile(pj(curpath, el)): diff --git a/wrw/form.py b/wrw/form.py index af599e6..dd1d5e9 100644 --- a/wrw/form.py +++ b/wrw/form.py @@ -31,7 +31,7 @@ class formwrap(object): return list(iter()) def keys(self): - return self.cf.keys() + return list(self.cf.keys()) def values(self): return [val for key, val in self.items()] diff --git a/wrw/req.py b/wrw/req.py index 0d26964..0689cbd 100644 --- a/wrw/req.py +++ b/wrw/req.py @@ -17,7 +17,7 @@ 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 = ""): if key.lower() in self.dict: diff --git a/wrw/resp.py b/wrw/resp.py index 04f3cab..75a7f3a 100644 --- a/wrw/resp.py +++ b/wrw/resp.py @@ -38,7 +38,7 @@ def setskel(req, skel): class usererror(dispatch.restart): def __init__(self, message, detail): - super(usererror, self).__init__() + super().__init__() self.message = message self.detail = detail @@ -47,7 +47,7 @@ class usererror(dispatch.restart): class message(dispatch.restart): def __init__(self, message, detail): - super(message, self).__init__() + super().__init__() self.message = message self.detail = detail @@ -60,20 +60,20 @@ class httperror(usererror): message = proto.statusinfo[status][0] if detail is None: detail = proto.statusinfo[status][1] - super(httperror, self).__init__(message, detail) + super().__init__(message, detail) self.status = status def handle(self, req): req.status(self.status, self.message) - return super(httperror, self).handle(req) + return super().handle(req) 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): - super(redirect, self).__init__() + super().__init__() self.url = url self.status = status diff --git a/wrw/session.py b/wrw/session.py index 41f2b5d..b46b818 100644 --- a/wrw/session.py +++ b/wrw/session.py @@ -11,7 +11,7 @@ def hexencode(str): def gennonce(length): nonce = "" - for i in xrange(length): + for i in range(length): nonce += chr(random.randint(0, 255)) return nonce @@ -83,7 +83,7 @@ class db(object): now = int(time.time()) with self.lock: dlist = [] - for sess in self.live.itervalues(): + for sess in self.live.values(): if sess.atime + self.freezetime < now: try: if sess.dirty(): @@ -154,14 +154,14 @@ class db(object): class backeddb(db): def __init__(self, backdb, *args, **kw): - super(backeddb, self).__init__(*args, **kw) + super().__init__(*args, **kw) self.backdb = backdb def thaw(self, sessid): data = self.backdb[sessid] try: return pickle.loads(data) - except Exception, e: + except: raise KeyError() def freeze(self, sess): -- 2.11.0