mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
obvious syntax fixes preparing python3 support
This commit is contained in:
parent
e984008010
commit
53ce50bc7b
@ -12,18 +12,18 @@ class MsgForm(forms.Form):
|
||||
subject = forms.CharField(max_length=100)
|
||||
message = forms.CharField()
|
||||
f = forms.FileField()
|
||||
|
||||
|
||||
|
||||
def home(request):
|
||||
from django.conf import settings
|
||||
print settings.SOME_VALUE
|
||||
print(settings.SOME_VALUE)
|
||||
subject = None
|
||||
message = None
|
||||
size = 0
|
||||
print request.META
|
||||
print(request.META)
|
||||
if request.POST:
|
||||
form = MsgForm(request.POST, request.FILES)
|
||||
print request.FILES
|
||||
print(request.FILES)
|
||||
if form.is_valid():
|
||||
subject = form.cleaned_data['subject']
|
||||
message = form.cleaned_data['message']
|
||||
@ -31,29 +31,29 @@ def home(request):
|
||||
size = int(os.fstat(f.fileno())[6])
|
||||
else:
|
||||
form = MsgForm()
|
||||
|
||||
|
||||
|
||||
|
||||
return render_to_response('home.html', {
|
||||
'form': form,
|
||||
'subject': subject,
|
||||
'message': message,
|
||||
'size': size
|
||||
}, RequestContext(request))
|
||||
|
||||
|
||||
|
||||
|
||||
def acsv(request):
|
||||
rows = [
|
||||
{'a': 1, 'b': 2},
|
||||
{'a': 3, 'b': 3}
|
||||
]
|
||||
|
||||
|
||||
response = HttpResponse(mimetype='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename=report.csv'
|
||||
|
||||
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(['a', 'b'])
|
||||
|
||||
|
||||
for r in rows:
|
||||
writer.writerow([r['a'], r['b']])
|
||||
|
||||
|
||||
return response
|
||||
|
||||
@ -4,7 +4,7 @@ import gevent
|
||||
|
||||
def child_process(queue):
|
||||
while True:
|
||||
print queue.get()
|
||||
print(queue.get())
|
||||
requests.get('http://requestb.in/15s95oz1')
|
||||
|
||||
class GunicornSubProcessTestMiddleware(object):
|
||||
|
||||
@ -16,14 +16,14 @@ class MsgForm(forms.Form):
|
||||
|
||||
def home(request):
|
||||
from django.conf import settings
|
||||
print settings.SOME_VALUE
|
||||
print(settings.SOME_VALUE)
|
||||
subject = None
|
||||
message = None
|
||||
size = 0
|
||||
print request.META
|
||||
print(request.META)
|
||||
if request.POST:
|
||||
form = MsgForm(request.POST, request.FILES)
|
||||
print request.FILES
|
||||
print(request.FILES)
|
||||
if form.is_valid():
|
||||
subject = form.cleaned_data['subject']
|
||||
message = form.cleaned_data['message']
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
# -*- coding: utf-8 -
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
class TestIter(object):
|
||||
|
||||
|
||||
def __iter__(self):
|
||||
lines = ['line 1\n', 'line 2\n']
|
||||
for line in lines:
|
||||
@ -22,6 +23,7 @@ def app(environ, start_response):
|
||||
('Content-type','text/plain'),
|
||||
('Transfer-Encoding', "chunked"),
|
||||
]
|
||||
print 'request received'
|
||||
sys.stdout.write('request received')
|
||||
sys.stdout.flush()
|
||||
start_response(status, response_headers)
|
||||
return TestIter()
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# Run this application with:
|
||||
@ -17,7 +17,7 @@
|
||||
try:
|
||||
from routes import Mapper
|
||||
except:
|
||||
print "This example requires Routes to be installed"
|
||||
print("This example requires Routes to be installed")
|
||||
|
||||
# Obviously you'd import your app callables
|
||||
# from different places...
|
||||
@ -55,4 +55,4 @@ class Application(object):
|
||||
start_response('404 Not Found', headers)
|
||||
return [html]
|
||||
|
||||
app = Application()
|
||||
app = Application()
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
# -*- coding: utf-8 -
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
@ -14,7 +14,8 @@ def app(environ, start_response):
|
||||
response_headers = [
|
||||
('Content-type','text/plain'),
|
||||
('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)
|
||||
start_response(status, response_headers)
|
||||
return iter([data])
|
||||
return iter([data])
|
||||
|
||||
@ -14,8 +14,7 @@ def app(environ, start_response):
|
||||
"""Simplest possible application object"""
|
||||
data = 'Hello, World!\n'
|
||||
status = '200 OK'
|
||||
# print("print to stdout in test app")
|
||||
# sys.stderr.write("stderr, print to stderr in test app\n")
|
||||
|
||||
response_headers = [
|
||||
('Content-type','text/plain'),
|
||||
('Content-Length', str(len(data))),
|
||||
|
||||
@ -31,7 +31,7 @@ class Application(object):
|
||||
def do_load_config(self):
|
||||
try:
|
||||
self.load_config()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
sys.stderr.write("\nError: %s\n" % str(e))
|
||||
sys.stderr.flush()
|
||||
sys.exit(1)
|
||||
@ -64,7 +64,7 @@ class Application(object):
|
||||
try:
|
||||
execfile(opts.config, cfg, cfg)
|
||||
except Exception:
|
||||
print "Failed to read config file: %s" % opts.config
|
||||
print("Failed to read config file: %s" % opts.config)
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
@ -122,7 +122,7 @@ class Application(object):
|
||||
|
||||
try:
|
||||
Arbiter(self).run()
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
sys.stderr.write("\nError: %s\n\n" % e)
|
||||
sys.stderr.flush()
|
||||
sys.exit(1)
|
||||
|
||||
@ -118,7 +118,7 @@ class PasterServerApplication(PasterBaseApplication):
|
||||
for k, v in cfg.items():
|
||||
if k.lower() in self.cfg.settings and v is not None:
|
||||
self.cfg.set(k.lower(), v)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
sys.stderr.write("\nConfig error: %s\n" % str(e))
|
||||
sys.stderr.flush()
|
||||
sys.exit(1)
|
||||
|
||||
@ -181,7 +181,7 @@ class Arbiter(object):
|
||||
self.halt()
|
||||
except KeyboardInterrupt:
|
||||
self.halt()
|
||||
except HaltServer, inst:
|
||||
except HaltServer as inst:
|
||||
self.halt(reason=inst.reason, exit_status=inst.exit_status)
|
||||
except SystemExit:
|
||||
raise
|
||||
@ -271,7 +271,7 @@ class Arbiter(object):
|
||||
"""
|
||||
try:
|
||||
os.write(self.PIPE[1], '.')
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
if e.errno not in [errno.EAGAIN, errno.EINTR]:
|
||||
raise
|
||||
|
||||
@ -296,10 +296,10 @@ class Arbiter(object):
|
||||
return
|
||||
while os.read(self.PIPE[0], 1):
|
||||
pass
|
||||
except select.error, e:
|
||||
if e[0] not in [errno.EAGAIN, errno.EINTR]:
|
||||
except select.error as e:
|
||||
if e.args[0] not in [errno.EAGAIN, errno.EINTR]:
|
||||
raise
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno not in [errno.EAGAIN, errno.EINTR]:
|
||||
raise
|
||||
except KeyboardInterrupt:
|
||||
@ -423,7 +423,7 @@ class Arbiter(object):
|
||||
if not worker:
|
||||
continue
|
||||
worker.tmp.close()
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno == errno.ECHILD:
|
||||
pass
|
||||
|
||||
@ -504,7 +504,7 @@ class Arbiter(object):
|
||||
"""
|
||||
try:
|
||||
os.kill(pid, sig)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno == errno.ESRCH:
|
||||
try:
|
||||
worker = self.WORKERS.pop(pid)
|
||||
|
||||
@ -43,7 +43,7 @@ class Spew(object):
|
||||
line = 'Unknown code named [%s]. VM instruction #%d' % (
|
||||
frame.f_code.co_name, frame.f_lasti)
|
||||
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:
|
||||
return self
|
||||
details = []
|
||||
@ -54,7 +54,7 @@ class Spew(object):
|
||||
if tok in frame.f_locals:
|
||||
details.append('%s=%r' % (tok, frame.f_locals[tok]))
|
||||
if details:
|
||||
print "\t%s" % ' '.join(details)
|
||||
print("\t%s" % ' '.join(details))
|
||||
return self
|
||||
|
||||
|
||||
|
||||
@ -256,7 +256,7 @@ class Request(Message):
|
||||
try:
|
||||
remote_host = self.unreader.sock.getpeername()[0]
|
||||
except socket.error as e:
|
||||
if e[0] == ENOTCONN:
|
||||
if e.args[0] == ENOTCONN:
|
||||
raise ForbiddenProxyRequest("UNKNOW")
|
||||
raise
|
||||
if remote_host not in self.cfg.proxy_allow_ips:
|
||||
|
||||
@ -286,7 +286,7 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
|
||||
except:
|
||||
traceback.print_exc()
|
||||
os.remove(file)
|
||||
except socket.error, e:
|
||||
except socket.error as e:
|
||||
if type(e.args) != types.TupleType:
|
||||
raise
|
||||
else:
|
||||
|
||||
@ -76,11 +76,11 @@ class Pidfile(object):
|
||||
try:
|
||||
os.kill(wpid, 0)
|
||||
return wpid
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e[0] == errno.ESRCH:
|
||||
return
|
||||
raise
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
if e[0] == errno.ENOENT:
|
||||
return
|
||||
raise
|
||||
|
||||
@ -44,7 +44,7 @@ class BaseSocket(object):
|
||||
def close(self):
|
||||
try:
|
||||
self.sock.close()
|
||||
except socket.error, e:
|
||||
except socket.error as e:
|
||||
self.log.info("Error while closing socket %s", str(e))
|
||||
time.sleep(0.3)
|
||||
del self.sock
|
||||
@ -117,7 +117,7 @@ def create_socket(conf, log):
|
||||
fd = int(os.environ.pop('GUNICORN_FD'))
|
||||
try:
|
||||
return sock_type(conf, log, fd=fd)
|
||||
except socket.error, e:
|
||||
except socket.error as e:
|
||||
if e[0] == errno.ENOTCONN:
|
||||
log.error("GUNICORN_FD should refer to an open socket.")
|
||||
else:
|
||||
@ -130,7 +130,7 @@ def create_socket(conf, log):
|
||||
for i in range(5):
|
||||
try:
|
||||
return sock_type(conf, log)
|
||||
except socket.error, e:
|
||||
except socket.error as e:
|
||||
if e[0] == errno.EADDRINUSE:
|
||||
log.error("Connection in use: %s", str(addr))
|
||||
if e[0] == errno.EADDRNOTAVAIL:
|
||||
|
||||
@ -125,7 +125,7 @@ def load_class(uri, default="sync", section="gunicorn.workers"):
|
||||
|
||||
return pkg_resources.load_entry_point("gunicorn",
|
||||
section, uri)
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
raise RuntimeError("class uri invalid or not found: " +
|
||||
"[%s]" % str(e))
|
||||
klass = components.pop(-1)
|
||||
@ -350,6 +350,6 @@ def seed():
|
||||
def check_is_writeable(path):
|
||||
try:
|
||||
f = open(path, 'a')
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
raise RuntimeError("Error: '%s' isn't writable [%r]" % (path, e))
|
||||
f.close()
|
||||
|
||||
@ -43,25 +43,25 @@ class AsyncWorker(base.Worker):
|
||||
if not req:
|
||||
break
|
||||
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)
|
||||
except StopIteration, e:
|
||||
except StopIteration as e:
|
||||
self.log.debug("Closing connection. %s", e)
|
||||
except socket.error:
|
||||
raise # pass to next try-except level
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.handle_error(req, client, addr, e)
|
||||
except socket.timeout as e:
|
||||
self.handle_error(req, client, addr, e)
|
||||
except socket.error, e:
|
||||
if e[0] not in (errno.EPIPE, errno.ECONNRESET):
|
||||
except socket.error as e:
|
||||
if e.args[0] not in (errno.EPIPE, errno.ECONNRESET):
|
||||
self.log.exception("Socket error processing request.")
|
||||
else:
|
||||
if e[0] == errno.ECONNRESET:
|
||||
if e.args[0] == errno.ECONNRESET:
|
||||
self.log.debug("Ignoring connection reset")
|
||||
else:
|
||||
self.log.debug("Ignoring EPIPE")
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.handle_error(req, client, addr, e)
|
||||
finally:
|
||||
util.close(client)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user