1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
--- jon/cgi.py.orig 2012-04-04 15:01:19 UTC
+++ jon/cgi.py
@@ -1,10 +1,10 @@
# $Id: cgi.py,v 9f23fa584882 2012/04/04 15:01:19 jon $
-import sys, re, os, Cookie, errno
+import sys, re, os, http.cookies, errno
try:
- import cStringIO as StringIO
+ import io as StringIO
except ImportError:
- import StringIO
+ import io
"""Object-oriented CGI interface."""
@@ -38,13 +38,13 @@ def html_encode(raw):
Specifically, the following characters are encoded as entities:
& < > " ' +
"""
- if not isinstance(raw, (str, unicode)):
+ if not isinstance(raw, str):
raw = str(raw)
return re.sub(_html_encre, lambda m: _html_encodes[m.group(0)], raw)
def url_encode(raw):
"""Return the string parameter URL-encoded."""
- if not isinstance(raw, (str, unicode)):
+ if not isinstance(raw, str):
raw = str(raw)
return re.sub(_url_encre, lambda m: "%%%02X" % ord(m.group(0)), raw)
@@ -69,7 +69,7 @@ def traceback(req, html=0):
except SequencingError:
pass
cgitb.Hook(file=req)(*exc)
- s = StringIO.StringIO()
+ s = io.StringIO()
cgitb.Hook(file=s, format="text")(*exc)
req.error(s.getvalue())
@@ -90,7 +90,7 @@ class Request(object):
self._doneHeaders = 0
self._headers = []
self._bufferOutput = 1
- self._output = StringIO.StringIO()
+ self._output = io.StringIO()
self._pos = 0
self.closed = 0
self._encoding = self._inputencoding = self._form_encoding = None
@@ -98,7 +98,7 @@ class Request(object):
del self.params
except AttributeError:
pass
- self.cookies = Cookie.SimpleCookie()
+ self.cookies = http.cookies.SimpleCookie()
if "HTTP_COOKIE" in self.environ:
self.cookies.load(self.environ["HTTP_COOKIE"])
self.aborted = 0
@@ -263,11 +263,11 @@ class Request(object):
"""Sends some data to the client."""
self._check_open()
if self._encoding:
- if not isinstance(s, unicode):
+ if not isinstance(s, str):
if self._inputencoding:
- s = unicode(s, self._inputencoding)
+ s = str(s, self._inputencoding)
else:
- s = unicode(s)
+ s = str(s)
s = s.encode(self._encoding)
else:
s = str(s)
@@ -347,7 +347,7 @@ class Request(object):
placed in the dictionary will be a list. This is useful for multiple-value
fields. If the variable name ends with a '!' character (before the '*' if
present) then the value will be a mime.Entity object."""
- import mime
+ from . import mime
headers = "Content-Type: %s\n" % contenttype
for entity in mime.Entity(encoded.read(), mime=1, headers=headers).entities:
if not entity.content_disposition:
@@ -504,7 +504,7 @@ class CGIRequest(Request):
if not self.aborted:
try:
self.__out.write(s)
- except IOError, x:
+ except IOError as x:
# Ignore EPIPE, caused by the browser having gone away
if x[0] != errno.EPIPE:
raise
@@ -514,7 +514,7 @@ class CGIRequest(Request):
if not self.aborted:
try:
self.__out.flush()
- except IOError, x:
+ except IOError as x:
# Ignore EPIPE, caused by the browser having gone away
if x[0] != errno.EPIPE:
raise
--- jon/fcgi.py.orig 2010-03-20 19:53:55 UTC
+++ jon/fcgi.py
@@ -1,7 +1,7 @@
# $Id: fcgi.py,v 5efd11fe0588 2010/03/20 18:27:40 jribbens $
import struct, socket, sys, errno, os, select
-import cgi, fakefile
+from . import cgi, fakefile
log_level = 0
log_name = "/tmp/fcgi.log"
@@ -184,8 +184,8 @@ class Connection(object):
self.params = params
self.threading_level = threading_level
if self.threading_level > 1:
- import thread
- self.socketlock = thread.allocate_lock()
+ import _thread
+ self.socketlock = _thread.allocate_lock()
else:
self.socketlock = None
@@ -216,9 +216,9 @@ class Connection(object):
self.socketlock.release()
else:
self.socket.sendall(rec.encode())
- except socket.error, x:
+ except socket.error as x:
if x[0] == errno.EPIPE:
- for req in self.requests.values():
+ for req in list(self.requests.values()):
req.aborted = 2
else:
raise
@@ -242,7 +242,7 @@ class Connection(object):
if isinstance(x, (EOFError, ValueError)) or \
(isinstance(x, socket.error) and x[0] == errno.EBADF):
self.log(2, 0, "EOF received on connection")
- for req in self.requests.values():
+ for req in list(self.requests.values()):
req.aborted = 2
break
else:
@@ -314,8 +314,8 @@ class Connection(object):
self.log(3, rec.request_id, "< FCGI_PARAMS: <empty>")
if self.threading_level > 1:
self.log(2, rec.request_id, "starting request thread")
- import thread
- thread.start_new_thread(req.run, ())
+ import _thread
+ _thread.start_new_thread(req.run, ())
else:
self.log(2, rec.request_id, "executing request")
req.run()
@@ -417,7 +417,7 @@ class Request(cgi.Request):
0, 0, 0)
self.log(2, "> FCGI_END_REQUEST")
self.__connection.write(rec)
- except IOError, x:
+ except IOError as x:
if x[0] == errno.EPIPE:
self.log(2, "EPIPE during request finalisation")
else:
@@ -457,7 +457,7 @@ class Request(cgi.Request):
pos += len(rec.content_data)
try:
self.__connection.write(rec)
- except IOError, x:
+ except IOError as x:
if x[0] == errno.EPIPE:
self.aborted = 2
self.log(2, "Aborted due to EPIPE")
@@ -480,9 +480,9 @@ class Server(object):
self.log(2, "theading_level = %d" % threading_level)
if threading_level > 0:
try:
- import thread
- log_lock = thread.allocate_lock()
- except ImportError, x:
+ import _thread
+ log_lock = _thread.allocate_lock()
+ except ImportError as x:
threading_level = 0
self.log(2, "cannot import thread (%s), disabling threading" % str(x))
self.threading_level = threading_level
@@ -505,7 +505,7 @@ class Server(object):
socket.SOCK_STREAM)
try:
self._sock.getpeername()
- except socket.error, x:
+ except socket.error as x:
if x[0] != errno.ENOTSOCK and x[0] != errno.ENOTCONN:
raise
if x[0] == errno.ENOTSOCK:
@@ -522,7 +522,7 @@ class Server(object):
# OSes)
select.select([self._sock], [], [])
(newsock, addr) = self._sock.accept()
- except socket.error, x:
+ except socket.error as x:
if x[0] == errno.EBADF:
break
raise
@@ -537,8 +537,8 @@ class Server(object):
self.params, self.threading_level)
del newsock
if self.threading_level > 0:
- import thread
- thread.start_new_thread(conn.run, ())
+ import _thread
+ _thread.start_new_thread(conn.run, ())
else:
conn.run()
if self.max_requests > 0:
--- jon/session.py.orig 2011-05-27 18:04:15 UTC
+++ jon/session.py
@@ -1,6 +1,6 @@
# $Id: session.py,v 2bbf755d62ad 2011/05/27 18:03:28 jon $
-import time, hmac, Cookie, re, random, os, errno, fcntl
+import time, hmac, http.cookies, re, random, os, errno, fcntl
try:
import hashlib
sha = hashlib.sha1
@@ -9,7 +9,7 @@ except ImportError:
import sha
shanew = sha.new
try:
- import cPickle as pickle
+ import pickle as pickle
except ImportError:
import pickle
@@ -127,7 +127,7 @@ class Session(dict):
if "hash" not in self:
self["hash"] = self._make_hash(self["id"], self._secret)
if self.cookie:
- c = Cookie.SimpleCookie()
+ c = http.cookies.SimpleCookie()
c[self.cookie] = self["id"] + self["hash"]
c[self.cookie]["path"] = self.root + "/"
if self.secure:
@@ -191,13 +191,13 @@ class FileSession(Session):
Session._create(self, secret)
try:
os.lstat("%s/%s" % (self.basedir, self["id"][:2]))
- except OSError, x:
+ except OSError as x:
if x[0] == errno.ENOENT:
- os.mkdir("%s/%s" % (self.basedir, self["id"][:2]), 0700)
+ os.mkdir("%s/%s" % (self.basedir, self["id"][:2]), 0o700)
try:
fd = os.open("%s/%s/%s" % (self.basedir, self["id"][:2],
- self["id"][2:]), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0700)
- except OSError, x:
+ self["id"][2:]), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o700)
+ except OSError as x:
if x[0] != errno.EEXIST:
raise
continue
@@ -211,7 +211,7 @@ class FileSession(Session):
try:
f = open("%s/%s/%s" % (self.basedir, self["id"][:2], self["id"][2:]),
"r+b")
- except IOError, x:
+ except IOError as x:
if x[0] != errno.ENOENT:
raise
return 0
@@ -255,9 +255,9 @@ class FileSession(Session):
st = os.lstat(basedir)
if st[4] != os.getuid():
raise Error("Sessions basedir is not owned by user %d" % os.getuid())
- except OSError, x:
+ except OSError as x:
if x[0] == errno.ENOENT:
- os.mkdir(basedir, 0700)
+ os.mkdir(basedir, 0o700)
return basedir
_find_basedir = staticmethod(_find_basedir)
@@ -322,19 +322,19 @@ class MySQLSession(GenericSQLSession):
while 1:
Session._create(self, secret)
self.dbc.execute("SELECT 1 FROM %s WHERE ID=%%s" % (self.table,),
- (long(self["id"], 16),))
+ (int(self["id"], 16),))
if self.dbc.rowcount == 0:
break
self["hash"] = self._make_hash(self["id"], secret)
self.dbc.execute("INSERT INTO %s (ID,hash,created,updated,data) VALUES " \
"(%%s,%%s,%%s,%%s,%%s)" % (self.table,),
- (long(self["id"], 16), self["hash"], int(self.created),
+ (int(self["id"], 16), self["hash"], int(self.created),
int(self.created), pickle.dumps({}, 1)))
self.dbc.execute("UNLOCK TABLES")
def _load(self):
self.dbc.execute("SELECT created,data FROM %s WHERE ID=%%s" % (self.table,),
- (long(self["id"], 16),))
+ (int(self["id"], 16),))
if self.dbc.rowcount == 0:
return 0
row = self.dbc.fetchone()
@@ -345,7 +345,7 @@ class MySQLSession(GenericSQLSession):
def save(self):
self.dbc.execute("UPDATE %s SET updated=%%s,data=%%s"
" WHERE ID=%%s" % (self.table,), (int(time.time()),
- pickle.dumps(self.copy(), 1), long(self["id"], 16)))
+ pickle.dumps(self.copy(), 1), int(self["id"], 16)))
SQLSession = MySQLSession # backwards compatibility name
--- jon/wsgi.py.orig 2010-03-23 01:01:42 UTC
+++ jon/wsgi.py
@@ -1,6 +1,6 @@
# $Id: wsgi.py,v a9ebd961ae72 2010/03/23 01:01:42 jon $
-import cgi, fakefile
+from . import cgi, fakefile
# classes involving calling jonpy-style handlers from WSGI server connectors
@@ -64,7 +64,7 @@ class Application(object):
class Handler(cgi.Handler):
def process(self, req):
- environ = dict(req.environ.items())
+ environ = dict(list(req.environ.items()))
environ["wsgi.version"] = (1, 0)
environ["wsgi.input"] = req
environ["wsgi.errors"] = fakefile.FakeOutput(req.error)
@@ -81,7 +81,7 @@ class Handler(cgi.Handler):
if exc_info:
try:
if req.get_header("Status") is not None:
- raise exc_info[0], exc_info[1], exc_info[2]
+ raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
finally:
exc_info = None
elif req.get_header("Status") is not None:
--- jon/wt/__init__.py.orig 2010-03-20 19:53:55 UTC
+++ jon/wt/__init__.py
@@ -43,7 +43,7 @@ def replace(wt, template, namespace):
out = getattr(namespace, chunk)()
else:
out = getattr(namespace, chunk)
- if not isinstance(out, unicode):
+ if not isinstance(out, str):
out = str(out)
wt.req.write(encode(out))
@@ -79,7 +79,7 @@ class GlobalTemplate(TemplateCode):
if encoding is None:
self.process(open(self.template_name(), "rb").read())
else:
- self.process(unicode(open(self.template_name(), "rb").read(),
+ self.process(str(open(self.template_name(), "rb").read(),
encoding))
def template_name(self):
@@ -94,7 +94,7 @@ class GlobalTemplate(TemplateCode):
# is substituted instead
obj = self.outer.page(self.outer)
if obj.template_as_file:
- import StringIO as cStringIO
+ import io as cStringIO
obj.main(StringIO.StringIO(self.outer._pageTemplate))
else:
obj.main(self.outer._pageTemplate)
@@ -123,7 +123,7 @@ def process(wt, template, namespace, selected=None):
(type(selected) == type(()) and name in selected)):
obj = getattr(namespace, name)(namespace, wt)
if obj.template_as_file:
- import cStringIO as StringIO
+ import io as StringIO
obj.main(StringIO.StringIO(template[start.end():end]))
else:
obj.main(template[start.end():end])
@@ -177,7 +177,7 @@ class Handler(cgi.Handler):
except KeyError:
namespace = { "wt": sys.modules[__name__] }
code = compile(open(codefname, "r").read(), codefname, "exec")
- exec code in namespace
+ exec(code, namespace)
del code
if self.cache_code:
_code_cache[codefname] = namespace
@@ -190,7 +190,7 @@ class Handler(cgi.Handler):
if encoding is None:
obj.main(open(self.template, "rb").read())
else:
- obj.main(unicode(open(self.template, "rb").read(), encoding))
+ obj.main(str(open(self.template, "rb").read(), encoding))
self.post_request(obj)
|