Skip to content

Commit

Permalink
'suppress_version_info' also reduces the displayed Python version
Browse files Browse the repository at this point in the history
  • Loading branch information
mar10 committed Dec 3, 2023
1 parent e63b69a commit 64f3812
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
21 changes: 11 additions & 10 deletions wsgidav/server/server_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _init_command_line_options():
del args.quiet

if args.root_path and not os.path.isdir(args.root_path):
msg = "{} is not a directory".format(args.root_path)
msg = f"{args.root_path} is not a directory"
parser.error(msg)

if args.version:
Expand All @@ -239,9 +239,9 @@ def _init_command_line_options():
"64" if sys.maxsize > 2**32 else "32",
platform.platform(aliased=True),
)
version_info += "\nPython from: {}".format(sys.executable)
version_info += f"\nPython from: {sys.executable}"
else:
version_info = "{}".format(__version__)
version_info = f"{__version__}"
print(version_info)
sys.exit()

Expand All @@ -254,7 +254,7 @@ def _init_command_line_options():
defPath = os.path.abspath(filename)
if os.path.exists(defPath):
if args.verbose >= 3:
print("Using default configuration file: {}".format(defPath))
print(f"Using default configuration file: {defPath}")
args.config_file = defPath
break
else:
Expand Down Expand Up @@ -429,6 +429,7 @@ def _init_config():

if config["suppress_version_info"]:
util.public_wsgidav_info = "WsgiDAV"
util.public_python_info = f"Python/{sys.version_info[0]}"

return cli_opts, config

Expand All @@ -443,7 +444,7 @@ def _run_cheroot(app, config, _server):
return False

version = (
f"{util.public_wsgidav_info} {wsgi.Server.version} Python/{util.PYTHON_VERSION}"
f"{util.public_wsgidav_info} {wsgi.Server.version} {util.public_python_info}"
)
# wsgi.Server.version = version

Expand Down Expand Up @@ -535,7 +536,7 @@ def _run_gevent(app, config, server):

info = _get_common_info(config)
version = f"gevent/{gevent.__version__}"
version = f"{util.public_wsgidav_info} {version} Python {util.PYTHON_VERSION}"
version = f"{util.public_wsgidav_info} {version} {util.public_python_info}"

# Override or add custom args
server_args = {
Expand Down Expand Up @@ -630,7 +631,7 @@ def load(self):
server_args.update(custom_args)

version = f"gunicorn/{gunicorn.__version__}"
version = f"{util.public_wsgidav_info} {version} Python {util.PYTHON_VERSION}"
version = f"{util.public_wsgidav_info} {version} {util.public_python_info}"
_logger.info(f"Running {version} ...")

GunicornApplication(app, server_args).run()
Expand All @@ -653,7 +654,7 @@ def _run_paste(app, config, server):
info = _get_common_info(config)

version = httpserver.WSGIHandler.server_version
version = f"{util.public_wsgidav_info} {version} Python {util.PYTHON_VERSION}"
version = f"{util.public_wsgidav_info} {version} {util.public_python_info}"

# See http://pythonpaste.org/modules/httpserver.html for more options
server = httpserver.serve(
Expand Down Expand Up @@ -727,7 +728,7 @@ def _run_uvicorn(app, config, server):
server_args.update(custom_args)

version = f"uvicorn/{uvicorn.__version__}"
version = f"{util.public_wsgidav_info} {version} Python {util.PYTHON_VERSION}"
version = f"{util.public_wsgidav_info} {version} {util.public_python_info}"
_logger.info(f"Running {version} ...")

uvicorn.run(app, **server_args)
Expand All @@ -738,7 +739,7 @@ def _run_wsgiref(app, config, _server):
from wsgiref.simple_server import WSGIRequestHandler, make_server

version = WSGIRequestHandler.server_version
version = f"{util.public_wsgidav_info} {version}" # Python {util.PYTHON_VERSION}"
version = f"{util.public_wsgidav_info} {version}" # {util.public_python_info}"
_logger.info(f"Running {version} ...")

_logger.warning(
Expand Down
2 changes: 1 addition & 1 deletion wsgidav/server/server_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def main():

# For an example, use cheroot:
version = (
f"{util.public_wsgidav_info} {wsgi.Server.version} Python/{util.PYTHON_VERSION}"
f"{util.public_wsgidav_info} {wsgi.Server.version} {util.public_python_info}"
)

server = wsgi.Server(
Expand Down
3 changes: 3 additions & 0 deletions wsgidav/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#: This is reset to ``"WsgiDAV"`` if ``suppress_version_info`` is set in the
#: configuration.
public_wsgidav_info = f"WsgiDAV/{__version__}"
#: This is reset to ``"Python/3"`` if ``suppress_version_info`` is set in the
#: configuration.
public_python_info = f"Python/{PYTHON_VERSION}"


class NO_DEFAULT:
Expand Down
6 changes: 3 additions & 3 deletions wsgidav/wsgidav_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import time
from urllib.parse import unquote

from wsgidav import util
from wsgidav import __version__, util
from wsgidav.dav_provider import DAVProvider
from wsgidav.default_conf import DEFAULT_CONFIG
from wsgidav.fs_dav_provider import FilesystemProvider
Expand Down Expand Up @@ -278,8 +278,8 @@ def __init__(self, config):
_logger.error("Could not add middleware {}.".format(mw))

_logger.info(
"{} Python/{} {}".format(
util.public_wsgidav_info,
"WsgiDAV/{} Python/{} {}".format(
__version__,
util.PYTHON_VERSION,
platform.platform(aliased=True),
)
Expand Down

0 comments on commit 64f3812

Please sign in to comment.