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