Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 6, 2025
1 parent cf0b104 commit 7e0bd47
Show file tree
Hide file tree
Showing 30 changed files with 1,482 additions and 1,482 deletions.
38 changes: 19 additions & 19 deletions bin/pip_constraint_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import sys

PYTHON_IMPLEMENTATION_MAP = { # noqa: WPS407
"cpython": "cp",
"ironpython": "ip",
"jython": "jy",
"python": "py",
"pypy": "pp",
'cpython': 'cp',
'ironpython': 'ip',
'jython': 'jy',
'python': 'py',
'pypy': 'pp',
}
PYTHON_IMPLEMENTATION = platform.python_implementation()

Expand All @@ -34,10 +34,10 @@ def get_runtime_python_tag():
python_tag_prefix = PYTHON_IMPLEMENTATION_MAP.get(sys_impl, sys_impl)

# pylint: disable=possibly-unused-variable
python_minor_ver_tag = "".join(map(str, python_minor_ver))
python_minor_ver_tag = ''.join(map(str, python_minor_ver))

return (
"{python_tag_prefix!s}{python_minor_ver_tag!s}".format(**locals()) # noqa: WPS421
'{python_tag_prefix!s}{python_minor_ver_tag!s}'.format(**locals()) # noqa: WPS421
)


Expand All @@ -54,20 +54,20 @@ def get_constraint_file_path(req_dir, toxenv, python_tag):
# pylint: disable=possibly-unused-variable
platform_machine = platform.machine().lower()

if toxenv in {"py", "python"}:
extra_prefix = "py" if PYTHON_IMPLEMENTATION == "PyPy" else ""
toxenv = "{prefix}py{ver}".format(
if toxenv in {'py', 'python'}:
extra_prefix = 'py' if PYTHON_IMPLEMENTATION == 'PyPy' else ''
toxenv = '{prefix}py{ver}'.format(
prefix=extra_prefix,
ver=python_tag[2:],
)

if sys_platform == "linux2":
sys_platform = "linux"
if sys_platform == 'linux2':
sys_platform = 'linux'

constraint_name = (
"tox-{toxenv}-{python_tag}-{sys_platform}-{platform_machine}".format(**locals()) # noqa: WPS421
'tox-{toxenv}-{python_tag}-{sys_platform}-{platform_machine}'.format(**locals()) # noqa: WPS421
)
return os.path.join(req_dir, os.path.extsep.join((constraint_name, "txt")))
return os.path.join(req_dir, os.path.extsep.join((constraint_name, 'txt')))


def make_pip_cmd(pip_args, constraint_file_path):
Expand All @@ -78,14 +78,14 @@ def make_pip_cmd(pip_args, constraint_file_path):
:returns: pip command.
"""
pip_cmd = [sys.executable, "-m", "pip"] + pip_args
pip_cmd = [sys.executable, '-m', 'pip'] + pip_args
if os.path.isfile(constraint_file_path):
pip_cmd += ["--constraint", constraint_file_path]
pip_cmd += ['--constraint', constraint_file_path]
else:
print_info(
"WARNING: The expected pinned constraints file for the current "
'WARNING: The expected pinned constraints file for the current '
'env does not exist (should be "{constraint_file_path}").'.format(
**locals()
**locals(),
), # noqa: WPS421
)
return pip_cmd
Expand All @@ -97,6 +97,6 @@ def run_cmd(cmd):
:param cmd: The command to invoke.
"""
print_info(
"Invoking the following command: {cmd}".format(cmd=" ".join(cmd)),
'Invoking the following command: {cmd}'.format(cmd=' '.join(cmd)),
)
subprocess.check_call(cmd) # noqa: S603
4 changes: 2 additions & 2 deletions cheroot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@


try:
__version__ = metadata.version("cheroot")
__version__ = metadata.version('cheroot')
except Exception:
__version__ = "unknown"
__version__ = 'unknown'
2 changes: 1 addition & 1 deletion cheroot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

from .cli import main

if __name__ == "__main__":
if __name__ == '__main__':
main()
26 changes: 13 additions & 13 deletions cheroot/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@
IS_ABOVE_OPENSSL10 = None


IS_CI = bool(os.getenv("CI"))
IS_GITHUB_ACTIONS_WORKFLOW = bool(os.getenv("GITHUB_WORKFLOW"))
IS_CI = bool(os.getenv('CI'))
IS_GITHUB_ACTIONS_WORKFLOW = bool(os.getenv('GITHUB_WORKFLOW'))


IS_PYPY = platform.python_implementation() == "PyPy"
IS_PYPY = platform.python_implementation() == 'PyPy'


SYS_PLATFORM = platform.system()
IS_WINDOWS = SYS_PLATFORM == "Windows"
IS_LINUX = SYS_PLATFORM == "Linux"
IS_MACOS = SYS_PLATFORM == "Darwin"
IS_SOLARIS = SYS_PLATFORM == "SunOS"
IS_WINDOWS = SYS_PLATFORM == 'Windows'
IS_LINUX = SYS_PLATFORM == 'Linux'
IS_MACOS = SYS_PLATFORM == 'Darwin'
IS_SOLARIS = SYS_PLATFORM == 'SunOS'

PLATFORM_ARCH = platform.machine()
IS_PPC = PLATFORM_ARCH.startswith("ppc")
IS_PPC = PLATFORM_ARCH.startswith('ppc')


def ntob(n, encoding="ISO-8859-1"):
def ntob(n, encoding='ISO-8859-1'):
"""Return the native string as bytes in the given encoding."""
assert_native(n)
# In Python 3, the native string type is unicode
return n.encode(encoding)


def ntou(n, encoding="ISO-8859-1"):
def ntou(n, encoding='ISO-8859-1'):
"""Return the native string as Unicode with the given encoding."""
assert_native(n)
# In Python 3, the native string type is unicode
return n


def bton(b, encoding="ISO-8859-1"):
def bton(b, encoding='ISO-8859-1'):
"""Return the byte string as native string in the given encoding."""
return b.decode(encoding)

Expand All @@ -58,7 +58,7 @@ def assert_native(n):
"""
if not isinstance(n, str):
raise TypeError("n must be a native str (got %s)" % type(n).__name__)
raise TypeError('n must be a native str (got %s)' % type(n).__name__)


def extract_bytes(mv):
Expand All @@ -81,5 +81,5 @@ def extract_bytes(mv):
return mv

raise ValueError(
"extract_bytes() only accepts bytes and memoryview/buffer",
'extract_bytes() only accepts bytes and memoryview/buffer',
)
132 changes: 66 additions & 66 deletions cheroot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class AbstractSocket(BindLocation):

def __init__(self, abstract_socket):
"""Initialize."""
self.bind_addr = "\x00{sock_path}".format(sock_path=abstract_socket)
self.bind_addr = '\x00{sock_path}'.format(sock_path=abstract_socket)


class Application:
Expand All @@ -78,8 +78,8 @@ class Application:
@classmethod
def resolve(cls, full_path):
"""Read WSGI app/Gateway path string and import application module."""
mod_path, _, app_path = full_path.partition(":")
app = getattr(import_module(mod_path), app_path or "application")
mod_path, _, app_path = full_path.partition(':')
app = getattr(import_module(mod_path), app_path or 'application')
# suppress the `TypeError` exception, just in case `app` is not a class
with suppress(TypeError):
if issubclass(app, server.Gateway):
Expand All @@ -91,8 +91,8 @@ def __init__(self, wsgi_app):
"""Initialize."""
if not callable(wsgi_app):
raise TypeError(
"Application must be a callable object or "
"cheroot.server.Gateway subclass",
'Application must be a callable object or '
'cheroot.server.Gateway subclass',
)
self.wsgi_app = wsgi_app

Expand All @@ -101,7 +101,7 @@ def server_args(self, parsed_args):
args = {
arg: value
for arg, value in vars(parsed_args).items()
if not arg.startswith("_") and value is not None
if not arg.startswith('_') and value is not None
}
args.update(vars(self))
return args
Expand All @@ -121,11 +121,11 @@ def __init__(self, gateway):
def server(self, parsed_args):
"""Server."""
server_args = vars(self)
server_args["bind_addr"] = parsed_args["bind_addr"]
server_args['bind_addr'] = parsed_args['bind_addr']
if parsed_args.max is not None:
server_args["maxthreads"] = parsed_args.max
server_args['maxthreads'] = parsed_args.max
if parsed_args.numthreads is not None:
server_args["minthreads"] = parsed_args.numthreads
server_args['minthreads'] = parsed_args.numthreads
return server.HTTPServer(**server_args)


Expand All @@ -135,12 +135,12 @@ def parse_wsgi_bind_location(bind_addr_string):
# this is the first condition to verify, otherwise the urlparse
# validation would detect //@<value> as a valid url with a hostname
# with value: "<value>" and port: None
if bind_addr_string.startswith("@"):
if bind_addr_string.startswith('@'):
return AbstractSocket(bind_addr_string[1:])

# try and match for an IP/hostname and port
match = urllib.parse.urlparse(
"//{addr}".format(addr=bind_addr_string),
'//{addr}'.format(addr=bind_addr_string),
)
try:
addr = match.hostname
Expand All @@ -160,84 +160,84 @@ def parse_wsgi_bind_addr(bind_addr_string):


_arg_spec = {
"_wsgi_app": {
"metavar": "APP_MODULE",
"type": Application.resolve,
"help": "WSGI application callable or cheroot.server.Gateway subclass",
'_wsgi_app': {
'metavar': 'APP_MODULE',
'type': Application.resolve,
'help': 'WSGI application callable or cheroot.server.Gateway subclass',
},
"--bind": {
"metavar": "ADDRESS",
"dest": "bind_addr",
"type": parse_wsgi_bind_addr,
"default": "[::1]:8000",
"help": "Network interface to listen on (default: [::1]:8000)",
'--bind': {
'metavar': 'ADDRESS',
'dest': 'bind_addr',
'type': parse_wsgi_bind_addr,
'default': '[::1]:8000',
'help': 'Network interface to listen on (default: [::1]:8000)',
},
"--chdir": {
"metavar": "PATH",
"type": os.chdir,
"help": "Set the working directory",
'--chdir': {
'metavar': 'PATH',
'type': os.chdir,
'help': 'Set the working directory',
},
"--server-name": {
"dest": "server_name",
"type": str,
"help": "Web server name to be advertised via Server HTTP header",
'--server-name': {
'dest': 'server_name',
'type': str,
'help': 'Web server name to be advertised via Server HTTP header',
},
"--threads": {
"metavar": "INT",
"dest": "numthreads",
"type": int,
"help": "Minimum number of worker threads",
'--threads': {
'metavar': 'INT',
'dest': 'numthreads',
'type': int,
'help': 'Minimum number of worker threads',
},
"--max-threads": {
"metavar": "INT",
"dest": "max",
"type": int,
"help": "Maximum number of worker threads",
'--max-threads': {
'metavar': 'INT',
'dest': 'max',
'type': int,
'help': 'Maximum number of worker threads',
},
"--timeout": {
"metavar": "INT",
"dest": "timeout",
"type": int,
"help": "Timeout in seconds for accepted connections",
'--timeout': {
'metavar': 'INT',
'dest': 'timeout',
'type': int,
'help': 'Timeout in seconds for accepted connections',
},
"--shutdown-timeout": {
"metavar": "INT",
"dest": "shutdown_timeout",
"type": int,
"help": "Time in seconds to wait for worker threads to cleanly exit",
'--shutdown-timeout': {
'metavar': 'INT',
'dest': 'shutdown_timeout',
'type': int,
'help': 'Time in seconds to wait for worker threads to cleanly exit',
},
"--request-queue-size": {
"metavar": "INT",
"dest": "request_queue_size",
"type": int,
"help": "Maximum number of queued connections",
'--request-queue-size': {
'metavar': 'INT',
'dest': 'request_queue_size',
'type': int,
'help': 'Maximum number of queued connections',
},
"--accepted-queue-size": {
"metavar": "INT",
"dest": "accepted_queue_size",
"type": int,
"help": "Maximum number of active requests in queue",
'--accepted-queue-size': {
'metavar': 'INT',
'dest': 'accepted_queue_size',
'type': int,
'help': 'Maximum number of active requests in queue',
},
"--accepted-queue-timeout": {
"metavar": "INT",
"dest": "accepted_queue_timeout",
"type": int,
"help": "Timeout in seconds for putting requests into queue",
'--accepted-queue-timeout': {
'metavar': 'INT',
'dest': 'accepted_queue_timeout',
'type': int,
'help': 'Timeout in seconds for putting requests into queue',
},
}


def main():
"""Create a new Cheroot instance with arguments from the command line."""
parser = argparse.ArgumentParser(
description="Start an instance of the Cheroot WSGI/HTTP server.",
description='Start an instance of the Cheroot WSGI/HTTP server.',
)
for arg, spec in _arg_spec.items():
parser.add_argument(arg, **spec)
raw_args = parser.parse_args()

# ensure cwd in sys.path
"" in sys.path or sys.path.insert(0, "")
'' in sys.path or sys.path.insert(0, '')

# create a server based on the arguments provided
raw_args._wsgi_app.server(raw_args).safe_start()
Loading

0 comments on commit 7e0bd47

Please sign in to comment.