obvious syntax fixes preparing python3 support

This commit is contained in:
benoitc 2012-10-24 12:11:15 +02:00
parent e984008010
commit 53ce50bc7b
17 changed files with 59 additions and 57 deletions

View File

@ -16,14 +16,14 @@ class MsgForm(forms.Form):
def home(request): def home(request):
from django.conf import settings from django.conf import settings
print settings.SOME_VALUE print(settings.SOME_VALUE)
subject = None subject = None
message = None message = None
size = 0 size = 0
print request.META print(request.META)
if request.POST: if request.POST:
form = MsgForm(request.POST, request.FILES) form = MsgForm(request.POST, request.FILES)
print request.FILES print(request.FILES)
if form.is_valid(): if form.is_valid():
subject = form.cleaned_data['subject'] subject = form.cleaned_data['subject']
message = form.cleaned_data['message'] message = form.cleaned_data['message']

View File

@ -4,7 +4,7 @@ import gevent
def child_process(queue): def child_process(queue):
while True: while True:
print queue.get() print(queue.get())
requests.get('http://requestb.in/15s95oz1') requests.get('http://requestb.in/15s95oz1')
class GunicornSubProcessTestMiddleware(object): class GunicornSubProcessTestMiddleware(object):

View File

@ -16,14 +16,14 @@ class MsgForm(forms.Form):
def home(request): def home(request):
from django.conf import settings from django.conf import settings
print settings.SOME_VALUE print(settings.SOME_VALUE)
subject = None subject = None
message = None message = None
size = 0 size = 0
print request.META print(request.META)
if request.POST: if request.POST:
form = MsgForm(request.POST, request.FILES) form = MsgForm(request.POST, request.FILES)
print request.FILES print(request.FILES)
if form.is_valid(): if form.is_valid():
subject = form.cleaned_data['subject'] subject = form.cleaned_data['subject']
message = form.cleaned_data['message'] message = form.cleaned_data['message']

View File

@ -4,6 +4,7 @@
# See the NOTICE for more information. # See the NOTICE for more information.
import sys
import time import time
class TestIter(object): class TestIter(object):
@ -22,6 +23,7 @@ def app(environ, start_response):
('Content-type','text/plain'), ('Content-type','text/plain'),
('Transfer-Encoding', "chunked"), ('Transfer-Encoding', "chunked"),
] ]
print 'request received' sys.stdout.write('request received')
sys.stdout.flush()
start_response(status, response_headers) start_response(status, response_headers)
return TestIter() return TestIter()

View File

@ -17,7 +17,7 @@
try: try:
from routes import Mapper from routes import Mapper
except: except:
print "This example requires Routes to be installed" print("This example requires Routes to be installed")
# Obviously you'd import your app callables # Obviously you'd import your app callables
# from different places... # from different places...

View File

@ -3,7 +3,7 @@
# This file is part of gunicorn released under the MIT license. # This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information. # See the NOTICE for more information.
import sys
import time import time
@ -14,7 +14,8 @@ def app(environ, start_response):
response_headers = [ response_headers = [
('Content-type','text/plain'), ('Content-type','text/plain'),
('Content-Length', str(len(data))) ] ('Content-Length', str(len(data))) ]
print 'request received, pausing 10 seconds' sys.stdout.write('request received, pausing 10 seconds')
sys.stdout.flush()
time.sleep(10) time.sleep(10)
start_response(status, response_headers) start_response(status, response_headers)
return iter([data]) return iter([data])

View File

@ -14,8 +14,7 @@ def app(environ, start_response):
"""Simplest possible application object""" """Simplest possible application object"""
data = 'Hello, World!\n' data = 'Hello, World!\n'
status = '200 OK' status = '200 OK'
# print("print to stdout in test app")
# sys.stderr.write("stderr, print to stderr in test app\n")
response_headers = [ response_headers = [
('Content-type','text/plain'), ('Content-type','text/plain'),
('Content-Length', str(len(data))), ('Content-Length', str(len(data))),

View File

@ -31,7 +31,7 @@ class Application(object):
def do_load_config(self): def do_load_config(self):
try: try:
self.load_config() self.load_config()
except Exception, e: except Exception as e:
sys.stderr.write("\nError: %s\n" % str(e)) sys.stderr.write("\nError: %s\n" % str(e))
sys.stderr.flush() sys.stderr.flush()
sys.exit(1) sys.exit(1)
@ -64,7 +64,7 @@ class Application(object):
try: try:
execfile(opts.config, cfg, cfg) execfile(opts.config, cfg, cfg)
except Exception: except Exception:
print "Failed to read config file: %s" % opts.config print("Failed to read config file: %s" % opts.config)
traceback.print_exc() traceback.print_exc()
sys.exit(1) sys.exit(1)
@ -122,7 +122,7 @@ class Application(object):
try: try:
Arbiter(self).run() Arbiter(self).run()
except RuntimeError, e: except RuntimeError as e:
sys.stderr.write("\nError: %s\n\n" % e) sys.stderr.write("\nError: %s\n\n" % e)
sys.stderr.flush() sys.stderr.flush()
sys.exit(1) sys.exit(1)

View File

@ -118,7 +118,7 @@ class PasterServerApplication(PasterBaseApplication):
for k, v in cfg.items(): for k, v in cfg.items():
if k.lower() in self.cfg.settings and v is not None: if k.lower() in self.cfg.settings and v is not None:
self.cfg.set(k.lower(), v) self.cfg.set(k.lower(), v)
except Exception, e: except Exception as e:
sys.stderr.write("\nConfig error: %s\n" % str(e)) sys.stderr.write("\nConfig error: %s\n" % str(e))
sys.stderr.flush() sys.stderr.flush()
sys.exit(1) sys.exit(1)

View File

@ -181,7 +181,7 @@ class Arbiter(object):
self.halt() self.halt()
except KeyboardInterrupt: except KeyboardInterrupt:
self.halt() self.halt()
except HaltServer, inst: except HaltServer as inst:
self.halt(reason=inst.reason, exit_status=inst.exit_status) self.halt(reason=inst.reason, exit_status=inst.exit_status)
except SystemExit: except SystemExit:
raise raise
@ -271,7 +271,7 @@ class Arbiter(object):
""" """
try: try:
os.write(self.PIPE[1], '.') os.write(self.PIPE[1], '.')
except IOError, e: except IOError as e:
if e.errno not in [errno.EAGAIN, errno.EINTR]: if e.errno not in [errno.EAGAIN, errno.EINTR]:
raise raise
@ -296,10 +296,10 @@ class Arbiter(object):
return return
while os.read(self.PIPE[0], 1): while os.read(self.PIPE[0], 1):
pass pass
except select.error, e: except select.error as e:
if e[0] not in [errno.EAGAIN, errno.EINTR]: if e.args[0] not in [errno.EAGAIN, errno.EINTR]:
raise raise
except OSError, e: except OSError as e:
if e.errno not in [errno.EAGAIN, errno.EINTR]: if e.errno not in [errno.EAGAIN, errno.EINTR]:
raise raise
except KeyboardInterrupt: except KeyboardInterrupt:
@ -423,7 +423,7 @@ class Arbiter(object):
if not worker: if not worker:
continue continue
worker.tmp.close() worker.tmp.close()
except OSError, e: except OSError as e:
if e.errno == errno.ECHILD: if e.errno == errno.ECHILD:
pass pass
@ -504,7 +504,7 @@ class Arbiter(object):
""" """
try: try:
os.kill(pid, sig) os.kill(pid, sig)
except OSError, e: except OSError as e:
if e.errno == errno.ESRCH: if e.errno == errno.ESRCH:
try: try:
worker = self.WORKERS.pop(pid) worker = self.WORKERS.pop(pid)

View File

@ -43,7 +43,7 @@ class Spew(object):
line = 'Unknown code named [%s]. VM instruction #%d' % ( line = 'Unknown code named [%s]. VM instruction #%d' % (
frame.f_code.co_name, frame.f_lasti) frame.f_code.co_name, frame.f_lasti)
if self.trace_names is None or name in self.trace_names: if self.trace_names is None or name in self.trace_names:
print '%s:%s: %s' % (name, lineno, line.rstrip()) print('%s:%s: %s' % (name, lineno, line.rstrip()))
if not self.show_values: if not self.show_values:
return self return self
details = [] details = []
@ -54,7 +54,7 @@ class Spew(object):
if tok in frame.f_locals: if tok in frame.f_locals:
details.append('%s=%r' % (tok, frame.f_locals[tok])) details.append('%s=%r' % (tok, frame.f_locals[tok]))
if details: if details:
print "\t%s" % ' '.join(details) print("\t%s" % ' '.join(details))
return self return self

View File

@ -256,7 +256,7 @@ class Request(Message):
try: try:
remote_host = self.unreader.sock.getpeername()[0] remote_host = self.unreader.sock.getpeername()[0]
except socket.error as e: except socket.error as e:
if e[0] == ENOTCONN: if e.args[0] == ENOTCONN:
raise ForbiddenProxyRequest("UNKNOW") raise ForbiddenProxyRequest("UNKNOW")
raise raise
if remote_host not in self.cfg.proxy_allow_ips: if remote_host not in self.cfg.proxy_allow_ips:

View File

@ -286,7 +286,7 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
except: except:
traceback.print_exc() traceback.print_exc()
os.remove(file) os.remove(file)
except socket.error, e: except socket.error as e:
if type(e.args) != types.TupleType: if type(e.args) != types.TupleType:
raise raise
else: else:

View File

@ -76,11 +76,11 @@ class Pidfile(object):
try: try:
os.kill(wpid, 0) os.kill(wpid, 0)
return wpid return wpid
except OSError, e: except OSError as e:
if e[0] == errno.ESRCH: if e[0] == errno.ESRCH:
return return
raise raise
except IOError, e: except IOError as e:
if e[0] == errno.ENOENT: if e[0] == errno.ENOENT:
return return
raise raise

View File

@ -44,7 +44,7 @@ class BaseSocket(object):
def close(self): def close(self):
try: try:
self.sock.close() self.sock.close()
except socket.error, e: except socket.error as e:
self.log.info("Error while closing socket %s", str(e)) self.log.info("Error while closing socket %s", str(e))
time.sleep(0.3) time.sleep(0.3)
del self.sock del self.sock
@ -117,7 +117,7 @@ def create_socket(conf, log):
fd = int(os.environ.pop('GUNICORN_FD')) fd = int(os.environ.pop('GUNICORN_FD'))
try: try:
return sock_type(conf, log, fd=fd) return sock_type(conf, log, fd=fd)
except socket.error, e: except socket.error as e:
if e[0] == errno.ENOTCONN: if e[0] == errno.ENOTCONN:
log.error("GUNICORN_FD should refer to an open socket.") log.error("GUNICORN_FD should refer to an open socket.")
else: else:
@ -130,7 +130,7 @@ def create_socket(conf, log):
for i in range(5): for i in range(5):
try: try:
return sock_type(conf, log) return sock_type(conf, log)
except socket.error, e: except socket.error as e:
if e[0] == errno.EADDRINUSE: if e[0] == errno.EADDRINUSE:
log.error("Connection in use: %s", str(addr)) log.error("Connection in use: %s", str(addr))
if e[0] == errno.EADDRNOTAVAIL: if e[0] == errno.EADDRNOTAVAIL:

View File

@ -125,7 +125,7 @@ def load_class(uri, default="sync", section="gunicorn.workers"):
return pkg_resources.load_entry_point("gunicorn", return pkg_resources.load_entry_point("gunicorn",
section, uri) section, uri)
except ImportError, e: except ImportError as e:
raise RuntimeError("class uri invalid or not found: " + raise RuntimeError("class uri invalid or not found: " +
"[%s]" % str(e)) "[%s]" % str(e))
klass = components.pop(-1) klass = components.pop(-1)
@ -350,6 +350,6 @@ def seed():
def check_is_writeable(path): def check_is_writeable(path):
try: try:
f = open(path, 'a') f = open(path, 'a')
except IOError, e: except IOError as e:
raise RuntimeError("Error: '%s' isn't writable [%r]" % (path, e)) raise RuntimeError("Error: '%s' isn't writable [%r]" % (path, e))
f.close() f.close()

View File

@ -43,25 +43,25 @@ class AsyncWorker(base.Worker):
if not req: if not req:
break break
self.handle_request(req, client, addr) self.handle_request(req, client, addr)
except http.errors.NoMoreData, e: except http.errors.NoMoreData as e:
self.log.debug("Ignored premature client disconnection. %s", e) self.log.debug("Ignored premature client disconnection. %s", e)
except StopIteration, e: except StopIteration as e:
self.log.debug("Closing connection. %s", e) self.log.debug("Closing connection. %s", e)
except socket.error: except socket.error:
raise # pass to next try-except level raise # pass to next try-except level
except Exception, e: except Exception as e:
self.handle_error(req, client, addr, e) self.handle_error(req, client, addr, e)
except socket.timeout as e: except socket.timeout as e:
self.handle_error(req, client, addr, e) self.handle_error(req, client, addr, e)
except socket.error, e: except socket.error as e:
if e[0] not in (errno.EPIPE, errno.ECONNRESET): if e.args[0] not in (errno.EPIPE, errno.ECONNRESET):
self.log.exception("Socket error processing request.") self.log.exception("Socket error processing request.")
else: else:
if e[0] == errno.ECONNRESET: if e.args[0] == errno.ECONNRESET:
self.log.debug("Ignoring connection reset") self.log.debug("Ignoring connection reset")
else: else:
self.log.debug("Ignoring EPIPE") self.log.debug("Ignoring EPIPE")
except Exception, e: except Exception as e:
self.handle_error(req, client, addr, e) self.handle_error(req, client, addr, e)
finally: finally:
util.close(client) util.close(client)