Merge pull request #1667 from BuhtigithuB/improve/pep8-main-py
Enhance main.py PEP8
This commit is contained in:
@@ -11,7 +11,8 @@ The gluon wsgi application
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
if False: import import_all # DO NOT REMOVE PART OF FREEZE PROCESS
|
||||
if False:
|
||||
import import_all # DO NOT REMOVE PART OF FREEZE PROCESS
|
||||
import gc
|
||||
|
||||
import os
|
||||
@@ -26,7 +27,7 @@ import random
|
||||
import string
|
||||
|
||||
from gluon._compat import Cookie, urllib2
|
||||
#from thread import allocate_lock
|
||||
# from thread import allocate_lock
|
||||
|
||||
from gluon.fileutils import abspath, write_file
|
||||
from gluon.settings import global_settings
|
||||
@@ -67,14 +68,14 @@ import gluon.messageboxhandler
|
||||
logging.gluon = gluon
|
||||
# so we must restore it! Thanks ozancag
|
||||
import locale
|
||||
locale.setlocale(locale.LC_CTYPE, "C") # IMPORTANT, web2py requires locale "C"
|
||||
locale.setlocale(locale.LC_CTYPE, "C") # IMPORTANT, web2py requires locale "C"
|
||||
|
||||
exists = os.path.exists
|
||||
pjoin = os.path.join
|
||||
|
||||
try:
|
||||
logging.config.fileConfig(abspath("logging.conf"))
|
||||
except: # fails on GAE or when logfile is missing
|
||||
except: # fails on GAE or when logfile is missing
|
||||
logging.basicConfig()
|
||||
logger = logging.getLogger("web2py")
|
||||
|
||||
@@ -254,6 +255,7 @@ class LazyWSGI(object):
|
||||
return [data]
|
||||
for item in middleware_apps:
|
||||
app = item(app)
|
||||
|
||||
def caller(app):
|
||||
return app(self.environ, self.start_response)
|
||||
return lambda caller=caller, app=app: caller(app)
|
||||
@@ -294,9 +296,9 @@ def wsgibase(environ, responder):
|
||||
response = Response()
|
||||
session = Session()
|
||||
env = request.env
|
||||
#env.web2py_path = global_settings.applications_parent
|
||||
# env.web2py_path = global_settings.applications_parent
|
||||
env.web2py_version = web2py_version
|
||||
#env.update(global_settings)
|
||||
# env.update(global_settings)
|
||||
static_file = False
|
||||
http_response = None
|
||||
try:
|
||||
@@ -325,7 +327,6 @@ def wsgibase(environ, responder):
|
||||
'Expires'] = 'Thu, 31 Dec 2037 23:59:59 GMT'
|
||||
response.stream(static_file, request=request)
|
||||
|
||||
|
||||
# ##################################################
|
||||
# fill in request items
|
||||
# ##################################################
|
||||
@@ -356,17 +357,15 @@ def wsgibase(environ, responder):
|
||||
cmd_opts = global_settings.cmd_options
|
||||
|
||||
request.update(
|
||||
client = client,
|
||||
folder = abspath('applications', app) + os.sep,
|
||||
ajax = x_req_with == 'xmlhttprequest',
|
||||
cid = env.http_web2py_component_element,
|
||||
is_local = (env.remote_addr in local_hosts and
|
||||
client == env.remote_addr),
|
||||
is_shell = False,
|
||||
is_scheduler = False,
|
||||
is_https = env.wsgi_url_scheme in HTTPS_SCHEMES or \
|
||||
request.env.http_x_forwarded_proto in HTTPS_SCHEMES \
|
||||
or env.https == 'on'
|
||||
client=client,
|
||||
folder=abspath('applications', app) + os.sep,
|
||||
ajax=x_req_with == 'xmlhttprequest',
|
||||
cid=env.http_web2py_component_element,
|
||||
is_local=(env.remote_addr in local_hosts and client == env.remote_addr),
|
||||
is_shell=False,
|
||||
is_scheduler=False,
|
||||
is_https=env.wsgi_url_scheme in HTTPS_SCHEMES or
|
||||
request.env.http_x_forwarded_proto in HTTPS_SCHEMES or env.https == 'on'
|
||||
)
|
||||
request.url = environ['PATH_INFO']
|
||||
|
||||
@@ -390,7 +389,7 @@ def wsgibase(environ, responder):
|
||||
% 'invalid request',
|
||||
web2py_error='invalid application')
|
||||
elif not request.is_local and exists(disabled):
|
||||
five0three = os.path.join(request.folder,'static','503.html')
|
||||
five0three = os.path.join(request.folder, 'static', '503.html')
|
||||
if os.path.exists(five0three):
|
||||
raise HTTP(503, file(five0three, 'r').read())
|
||||
else:
|
||||
@@ -406,7 +405,7 @@ def wsgibase(environ, responder):
|
||||
# get the GET and POST data
|
||||
# ##################################################
|
||||
|
||||
#parse_get_post_vars(request, environ)
|
||||
# parse_get_post_vars(request, environ)
|
||||
|
||||
# ##################################################
|
||||
# expose wsgi hooks for convenience
|
||||
@@ -625,7 +624,7 @@ def appfactory(wsgiapp=wsgibase,
|
||||
raise BaseException("Can't create dir %s" % profiler_dir)
|
||||
filepath = pjoin(profiler_dir, 'wtest')
|
||||
try:
|
||||
filehandle = open( filepath, 'w' )
|
||||
filehandle = open(filepath, 'w')
|
||||
filehandle.close()
|
||||
os.unlink(filepath)
|
||||
except IOError:
|
||||
|
||||
Reference in New Issue
Block a user