cleanup in main, thanks Paolo

This commit is contained in:
mdipierro
2019-04-23 22:10:53 -07:00
parent 14dee6b466
commit 0a9975809c
+12 -14
View File
@@ -28,7 +28,7 @@ import string
from gluon._compat import Cookie, urllib_quote
# from thread import allocate_lock
from gluon.fileutils import abspath, write_file
from gluon.fileutils import abspath, read_file, write_file
from gluon.settings import global_settings
from gluon.utils import web2py_uuid, unlocalised_http_header_date
from gluon.admin import add_path_first, create_missing_folders, create_missing_app_folders
@@ -98,13 +98,9 @@ requests = 0 # gc timer
# Security Checks: validate URL and session_id here,
# accept_language is validated in languages
# pattern used to validate client address
regex_client = re.compile('[\w\-:]+(\.[\w\-]+)*\.?') # ## to account for IPV6
try:
version_info = open(pjoin(global_settings.gluon_parent, 'VERSION'), 'r')
raw_version_string = version_info.read().split()[-1].strip()
version_info.close()
version_info = read_file(pjoin(global_settings.gluon_parent, 'VERSION'))
raw_version_string = version_info.split()[-1].strip()
global_settings.web2py_version = raw_version_string
web2py_version = global_settings.web2py_version
except:
@@ -121,6 +117,9 @@ load_routes()
HTTPS_SCHEMES = set(('https', 'HTTPS'))
# pattern used to validate client address
REGEX_CLIENT = re.compile(r'[\w:-]+(\.[\w-]+)*\.?') # ## to account for IPV6
def get_client(env):
"""
Guesses the client address from the environment variables
@@ -129,12 +128,12 @@ def get_client(env):
if all fails, assume '127.0.0.1' or '::1' (running locally)
"""
eget = env.get
g = regex_client.search(eget('http_x_forwarded_for', ''))
client = (g.group() or '').split(',')[0] if g else None
m = REGEX_CLIENT.search(eget('http_x_forwarded_for', ''))
client = m and m.group()
if client in (None, '', 'unknown'):
g = regex_client.search(eget('remote_addr', ''))
if g:
client = g.group()
m = REGEX_CLIENT.search(eget('remote_addr', ''))
if m:
client = m.group()
elif env.http_host.startswith('['): # IPv6
client = '::1'
else:
@@ -352,7 +351,6 @@ def wsgibase(environ, responder):
local_hosts = global_settings.local_hosts
client = get_client(env)
x_req_with = str(env.http_x_requested_with).lower()
cmd_opts = global_settings.cmd_options
request.update(
client=client,
@@ -558,6 +556,7 @@ def wsgibase(environ, responder):
if not http_response:
return wsgibase(new_environ, responder)
if global_settings.web2py_crontype == 'soft':
cmd_opts = global_settings.cmd_options
newcron.softcron(global_settings.applications_parent).start()
return http_response.to(responder, env=env)
@@ -711,7 +710,6 @@ class HttpServer(object):
if interfaces:
# if interfaces is specified, it must be tested for rocket parameter correctness
# not necessarily completely tested (e.g. content of tuples or ip-format)
import types
if isinstance(interfaces, list):
for i in interfaces:
if not isinstance(i, tuple):