Various python3 modifications.
authorFredrik Tolf <fredrik@dolda2000.com>
Sat, 3 Dec 2011 06:43:47 +0000 (07:43 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Sat, 3 Dec 2011 06:43:47 +0000 (07:43 +0100)
wrw/cookie.py
wrw/dispatch.py
wrw/filesys.py
wrw/form.py
wrw/req.py
wrw/resp.py
wrw/session.py

index 37e8708..c6ae36c 100644 (file)
@@ -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):
index 5a7bda0..b6009af 100644 (file)
@@ -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
index 264cf14..56d58aa 100644 (file)
@@ -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)):
index af599e6..dd1d5e9 100644 (file)
@@ -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()]
index 0d26964..0689cbd 100644 (file)
@@ -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:
index 04f3cab..75a7f3a 100644 (file)
@@ -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
 
index 41f2b5d..b46b818 100644 (file)
@@ -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):