Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'gunicorn' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
# -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import os
import unittest.mock as mock
import gunicorn.app.base
import gunicorn.arbiter
from gunicorn.config import ReusePort
class DummyApplication(gunicorn.app.base.BaseApplication):
"""
Dummy application that has a default configuration.
"""
def init(self, parser, opts, args):
"""No-op"""
def load(self):
"""No-op"""
def load_config(self):
"""No-op"""
@mock.patch('gunicorn.sock.close_sockets')
def test_arbiter_stop_closes_listeners(close_sockets):
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import os
try:
import unittest.mock as mock
except ImportError:
import mock
import gunicorn.app.base
import gunicorn.arbiter
class DummyApplication(gunicorn.app.base.BaseApplication):
"""
Dummy application that has an default configuration.
"""
def init(self, parser, opts, args):
"""No-op"""
def load(self):
"""No-op"""
def load_config(self):
"""No-op"""
def test_arbiter_shutdown_closes_listeners():
arbiter = gunicorn.arbiter.Arbiter(DummyApplication())
def test_keyfile():
assert issubclass(KeyFile, Setting)
assert KeyFile.name == 'keyfile'
assert KeyFile.section == 'SSL'
assert KeyFile.cli == ['--keyfile']
assert KeyFile.meta == 'FILE'
assert KeyFile.default is None
def test_bool_validation():
c = config.Config()
assert c.preload_app is False
c.set("preload_app", True)
assert c.preload_app is True
c.set("preload_app", "true")
assert c.preload_app is True
c.set("preload_app", "false")
assert c.preload_app is False
pytest.raises(ValueError, c.set, "preload_app", "zilch")
pytest.raises(TypeError, c.set, "preload_app", 4)
def test_get_username_handles_malformed_basic_auth_header():
"""Should catch a malformed auth header"""
request = SimpleNamespace(headers=())
response = SimpleNamespace(
status='200', response_length=1024, sent=1024,
headers=(('Content-Type', 'text/plain'),),
)
environ = {
'REQUEST_METHOD': 'GET', 'RAW_URI': '/my/path?foo=bar',
'PATH_INFO': '/my/path', 'QUERY_STRING': 'foo=bar',
'SERVER_PROTOCOL': 'HTTP/1.1',
'HTTP_AUTHORIZATION': 'Basic ixsTtkKzIpVTncfQjbBcnoRNoDfbnaXG',
}
logger = Logger(Config())
atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
assert atoms['u'] == '-'
def test_prefix_multiple_dots():
c = Config()
c.set("statsd_prefix", "test...")
logger = Statsd(c)
logger.sock = MockSocket(False)
logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
assert logger.sock.msgs[0] == b"test.gunicorn.test:666|g"
def test_always_use_configured_logger():
c = config.Config()
c.set('logger_class', __name__ + '.MyLogger')
assert c.logger_class == MyLogger
c.set('statsd_host', 'localhost:12345')
# still uses custom logger over statsd
assert c.logger_class == MyLogger
def test_defaults():
c = config.Config()
for s in config.KNOWN_SETTINGS:
assert c.settings[s.name].validator(s.default) == c.settings[s.name].get()
def test_always_use_configured_logger():
c = config.Config()
c.set('logger_class', __name__ + '.MyLogger')
assert c.logger_class == MyLogger
c.set('statsd_host', 'localhost:12345')
# still uses custom logger over statsd
assert c.logger_class == MyLogger
def test_defaults():
c = config.Config()
for s in config.KNOWN_SETTINGS:
assert c.settings[s.name].validator(s.default) == c.settings[s.name].get()