Skip to content

Commit

Permalink
r1
Browse files Browse the repository at this point in the history
  • Loading branch information
ali96343 committed Nov 15, 2023
1 parent 8ca0349 commit 4012018
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions py4web/server_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def run(self, py4web_apps_handler):
"keyfile": self.options.get("keyfile", None),
"accesslog": None,
"errorlog": None,
"config": "sa_config_B",
# ( 'sa_config_B', 'sa_config_L', 'GUNICORN_', 'gunicorn.saenv', 'gunicorn.conf.py' )
"config": "sa_config",
# ( 'sa_config', 'GUNICORN_', 'gunicorn.saenv', 'gunicorn.conf.py' )
}

if not self.quiet:
Expand All @@ -162,7 +162,6 @@ def run(self, py4web_apps_handler):
"access_log_format": '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"',
"accesslog": log_to,
"errorlog": log_to,
"config": "sa_config_L",
}
)

Expand All @@ -177,24 +176,20 @@ def get_gunicorn_options(
env_key="GUNICORN_",
):
def check_kv(kx, vx):
bad_keys = (
"bind",
"config",
)
if kx and vx and kx not in bad_keys:
if kx and vx and ( kx not in ( "bind", "config",) ) :
if vx.startswith("{") and vx.endswith("}"):
vt = re.sub( r'\,\s*\}', "}", vx)
vx = json.loads(vt.replace("'", '"'))
if vx == "None":
vx = None
return kx, vx
self.logger_info(f"gunicorn: Bad {kx}={vx}")
self.logger_info(f"gunicorn: Ignored {kx}={vx}")
return None, None

if os.path.isfile(default):
return {"use_python_config": default, "config": default}

gu_opts = dict()
res_opts = dict()

if os.path.isfile(env_file):
try:
Expand All @@ -215,11 +210,11 @@ def check_kv(kx, vx):
k, v = check_kv(k, v)
if k is None:
continue
gu_opts[k] = v
if gu_opts:
gu_opts["config"] = env_file
return gu_opts
except OSError as ex:
res_opts[k] = v
if res_opts:
res_opts["config"] = env_file
return res_opts
except (IOError, OSError):
self.logger_info(f"gunicorn: Bad {env_file}")

for k, v in os.environ.items():
Expand All @@ -228,11 +223,11 @@ def check_kv(kx, vx):
k, v = check_kv(k, v)
if k is None:
continue
gu_opts[k] = v
res_opts[k] = v

if gu_opts:
gu_opts["config"] = env_key
return gu_opts
if res_opts:
res_opts["config"] = env_key
return res_opts

def load_config(self):
sa_config.update(self.get_gunicorn_options())
Expand All @@ -247,10 +242,10 @@ def load_config(self):
self.logger_info(sa_config)
self.logger_info(self.cfg)

for e in ("use_python_config", "use_native_config"):
for e in ( "use_python_config", "usepy", ):
if e in sa_config:
filename = sa_config[e]
Application.load_config_from_file(self, filename)
Application.load_config_from_file(self, sa_config [ e ] )
break

def load(self):
return py4web_apps_handler
Expand Down

0 comments on commit 4012018

Please sign in to comment.