Skip to content

Commit 8fa57d0

Browse files
authored
Merge pull request #2928 from samypr100/pycodestyle-fixup
Fixing errors reported by pycodestyle
2 parents bba59ae + 2ea4699 commit 8fa57d0

File tree

11 files changed

+86
-84
lines changed

11 files changed

+86
-84
lines changed

gunicorn/arbiter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def start(self):
154154

155155
self.LISTENERS = sock.create_sockets(self.cfg, self.log, fds)
156156

157-
listeners_str = ",".join([str(l) for l in self.LISTENERS])
157+
listeners_str = ",".join([str(lnr) for lnr in self.LISTENERS])
158158
self.log.debug("Arbiter booted")
159159
self.log.info("Listening at: %s (%s)", listeners_str, self.pid)
160160
self.log.info("Using worker: %s", self.cfg.worker_class_str)
@@ -421,7 +421,7 @@ def reexec(self):
421421
environ['LISTEN_FDS'] = str(len(self.LISTENERS))
422422
else:
423423
environ['GUNICORN_FD'] = ','.join(
424-
str(l.fileno()) for l in self.LISTENERS)
424+
str(lnr.fileno()) for lnr in self.LISTENERS)
425425

426426
os.chdir(self.START_CTX['cwd'])
427427

@@ -454,11 +454,11 @@ def reload(self):
454454
# do we need to change listener ?
455455
if old_address != self.cfg.address:
456456
# close all listeners
457-
for l in self.LISTENERS:
458-
l.close()
457+
for lnr in self.LISTENERS:
458+
lnr.close()
459459
# init new listeners
460460
self.LISTENERS = sock.create_sockets(self.cfg, self.log)
461-
listeners_str = ",".join([str(l) for l in self.LISTENERS])
461+
listeners_str = ",".join([str(lnr) for lnr in self.LISTENERS])
462462
self.log.info("Listening at: %s", listeners_str)
463463

464464
# do some actions on reload

gunicorn/config.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def _validate_callable(val):
448448
raise TypeError(str(e))
449449
except AttributeError:
450450
raise TypeError("Can not load '%s' from '%s'"
451-
"" % (obj_name, mod_name))
451+
"" % (obj_name, mod_name))
452452
if not callable(val):
453453
raise TypeError("Value is not callable: %s" % val)
454454
if arity != -1 and arity != util.get_arity(val):
@@ -563,6 +563,7 @@ class ConfigFile(Setting):
563563
prefix.
564564
"""
565565

566+
566567
class WSGIApp(Setting):
567568
name = "wsgi_app"
568569
section = "Config File"
@@ -575,6 +576,7 @@ class WSGIApp(Setting):
575576
.. versionadded:: 20.1.0
576577
"""
577578

579+
578580
class Bind(Setting):
579581
name = "bind"
580582
action = "append"
@@ -1273,69 +1275,70 @@ class ForwardedAllowIPS(Setting):
12731275
12741276
By default, the value of the ``FORWARDED_ALLOW_IPS`` environment
12751277
variable. If it is not defined, the default is ``"127.0.0.1"``.
1276-
1278+
12771279
.. note::
1278-
1280+
12791281
The interplay between the request headers, the value of ``forwarded_allow_ips``, and the value of
1280-
``secure_scheme_headers`` is complex. Various scenarios are documented below to further elaborate. In each case, we
1281-
have a request from the remote address 134.213.44.18, and the default value of ``secure_scheme_headers``:
1282-
1282+
``secure_scheme_headers`` is complex. Various scenarios are documented below to further elaborate.
1283+
In each case, we have a request from the remote address 134.213.44.18, and the default value of
1284+
``secure_scheme_headers``:
1285+
12831286
.. code::
1284-
1287+
12851288
secure_scheme_headers = {
12861289
'X-FORWARDED-PROTOCOL': 'ssl',
12871290
'X-FORWARDED-PROTO': 'https',
12881291
'X-FORWARDED-SSL': 'on'
12891292
}
1290-
1291-
1292-
.. list-table::
1293+
1294+
1295+
.. list-table::
12931296
:header-rows: 1
12941297
:align: center
12951298
:widths: auto
1296-
1299+
12971300
* - ``forwarded-allow-ips``
12981301
- Secure Request Headers
12991302
- Result
13001303
- Explanation
1301-
* - .. code::
1302-
1304+
* - .. code::
1305+
13031306
["127.0.0.1"]
13041307
- .. code::
1305-
1308+
13061309
X-Forwarded-Proto: https
1307-
- .. code::
1308-
1310+
- .. code::
1311+
13091312
wsgi.url_scheme = "http"
13101313
- IP address was not allowed
1311-
* - .. code::
1312-
1314+
* - .. code::
1315+
13131316
"*"
13141317
- <none>
1315-
- .. code::
1316-
1318+
- .. code::
1319+
13171320
wsgi.url_scheme = "http"
13181321
- IP address allowed, but no secure headers provided
1319-
* - .. code::
1320-
1322+
* - .. code::
1323+
13211324
"*"
13221325
- .. code::
1323-
1326+
13241327
X-Forwarded-Proto: https
1325-
- .. code::
1326-
1328+
- .. code::
1329+
13271330
wsgi.url_scheme = "https"
13281331
- IP address allowed, one request header matched
1329-
* - .. code::
1330-
1332+
* - .. code::
1333+
13311334
["134.213.44.18"]
13321335
- .. code::
1333-
1336+
13341337
X-Forwarded-Ssl: on
13351338
X-Forwarded-Proto: http
13361339
- ``InvalidSchemeHeaders()`` raised
13371340
- IP address allowed, but the two secure headers disagreed on if HTTPS was used
1338-
1341+
13391342
13401343
"""
13411344

@@ -1617,6 +1620,7 @@ class StatsdHost(Setting):
16171620
.. versionadded:: 19.1
16181621
"""
16191622

1623+
16201624
# Datadog Statsd (dogstatsd) tags. https://docs.datadoghq.com/developers/dogstatsd/
16211625
class DogstatsdTags(Setting):
16221626
name = "dogstatsd_tags"
@@ -1632,6 +1636,7 @@ class DogstatsdTags(Setting):
16321636
.. versionadded:: 20
16331637
"""
16341638

1639+
16351640
class StatsdPrefix(Setting):
16361641
name = "statsd_prefix"
16371642
section = "Logging"

gunicorn/debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __call__(self, frame, event, arg):
2828
if '__file__' in frame.f_globals:
2929
filename = frame.f_globals['__file__']
3030
if (filename.endswith('.pyc') or
31-
filename.endswith('.pyo')):
31+
filename.endswith('.pyo')):
3232
filename = filename[:-1]
3333
name = frame.f_globals['__name__']
3434
line = linecache.getline(filename, lineno)

gunicorn/glogging.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,46 +44,45 @@
4444
"local7": 23
4545
}
4646

47-
4847
CONFIG_DEFAULTS = dict(
49-
version=1,
50-
disable_existing_loggers=False,
51-
52-
root={"level": "INFO", "handlers": ["console"]},
53-
loggers={
54-
"gunicorn.error": {
55-
"level": "INFO",
56-
"handlers": ["error_console"],
57-
"propagate": True,
58-
"qualname": "gunicorn.error"
59-
},
60-
61-
"gunicorn.access": {
62-
"level": "INFO",
63-
"handlers": ["console"],
64-
"propagate": True,
65-
"qualname": "gunicorn.access"
66-
}
48+
version=1,
49+
disable_existing_loggers=False,
50+
51+
root={"level": "INFO", "handlers": ["console"]},
52+
loggers={
53+
"gunicorn.error": {
54+
"level": "INFO",
55+
"handlers": ["error_console"],
56+
"propagate": True,
57+
"qualname": "gunicorn.error"
6758
},
68-
handlers={
69-
"console": {
70-
"class": "logging.StreamHandler",
71-
"formatter": "generic",
72-
"stream": "ext://sys.stdout"
73-
},
74-
"error_console": {
75-
"class": "logging.StreamHandler",
76-
"formatter": "generic",
77-
"stream": "ext://sys.stderr"
78-
},
59+
60+
"gunicorn.access": {
61+
"level": "INFO",
62+
"handlers": ["console"],
63+
"propagate": True,
64+
"qualname": "gunicorn.access"
65+
}
66+
},
67+
handlers={
68+
"console": {
69+
"class": "logging.StreamHandler",
70+
"formatter": "generic",
71+
"stream": "ext://sys.stdout"
7972
},
80-
formatters={
81-
"generic": {
82-
"format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s",
83-
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
84-
"class": "logging.Formatter"
85-
}
73+
"error_console": {
74+
"class": "logging.StreamHandler",
75+
"formatter": "generic",
76+
"stream": "ext://sys.stderr"
77+
},
78+
},
79+
formatters={
80+
"generic": {
81+
"format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s",
82+
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
83+
"class": "logging.Formatter"
8684
}
85+
}
8786
)
8887

8988

@@ -299,7 +298,7 @@ def atoms(self, resp, req, environ, request_time):
299298
'a': environ.get('HTTP_USER_AGENT', '-'),
300299
'T': request_time.seconds,
301300
'D': (request_time.seconds * 1000000) + request_time.microseconds,
302-
'M': (request_time.seconds * 1000) + int(request_time.microseconds/1000),
301+
'M': (request_time.seconds * 1000) + int(request_time.microseconds / 1000),
303302
'L': "%d.%06d" % (request_time.seconds, request_time.microseconds),
304303
'p': "<%s>" % os.getpid()
305304
}
@@ -437,7 +436,7 @@ def _set_syslog_handler(self, log, cfg, fmt, name):
437436

438437
# finally setup the syslog handler
439438
h = logging.handlers.SysLogHandler(address=addr,
440-
facility=facility, socktype=socktype)
439+
facility=facility, socktype=socktype)
441440

442441
h.setFormatter(fmt)
443442
h._gunicorn = True

gunicorn/http/message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, cfg, unreader, peer_addr):
4141
# set headers limits
4242
self.limit_request_fields = cfg.limit_request_fields
4343
if (self.limit_request_fields <= 0
44-
or self.limit_request_fields > MAX_HEADERS):
44+
or self.limit_request_fields > MAX_HEADERS):
4545
self.limit_request_fields = MAX_HEADERS
4646
self.limit_request_field_size = cfg.limit_request_field_size
4747
if self.limit_request_field_size < 0:
@@ -71,7 +71,7 @@ def parse_headers(self, data):
7171
secure_scheme_headers = {}
7272
if ('*' in cfg.forwarded_allow_ips or
7373
not isinstance(self.peer_addr, tuple)
74-
or self.peer_addr[0] in cfg.forwarded_allow_ips):
74+
or self.peer_addr[0] in cfg.forwarded_allow_ips):
7575
secure_scheme_headers = cfg.secure_scheme_headers
7676

7777
# Parse headers into key/value pairs paying attention
@@ -173,7 +173,7 @@ def __init__(self, cfg, unreader, peer_addr, req_number=1):
173173
# get max request line size
174174
self.limit_request_line = cfg.limit_request_line
175175
if (self.limit_request_line < 0
176-
or self.limit_request_line >= MAX_REQUEST_LINE):
176+
or self.limit_request_line >= MAX_REQUEST_LINE):
177177
self.limit_request_line = MAX_REQUEST_LINE
178178

179179
self.req_number = req_number
@@ -276,7 +276,7 @@ def proxy_protocol_access_check(self):
276276
# check in allow list
277277
if ("*" not in self.cfg.proxy_allow_ips and
278278
isinstance(self.peer_addr, tuple) and
279-
self.peer_addr[0] not in self.cfg.proxy_allow_ips):
279+
self.peer_addr[0] not in self.cfg.proxy_allow_ips):
280280
raise ForbiddenProxyRequest(self.peer_addr[0])
281281

282282
def parse_proxy_protocol(self, line):

gunicorn/sock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __getattr__(self, name):
3939
def set_options(self, sock, bound=False):
4040
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
4141
if (self.conf.reuse_port
42-
and hasattr(socket, 'SO_REUSEPORT')): # pragma: no cover
42+
and hasattr(socket, 'SO_REUSEPORT')): # pragma: no cover
4343
try:
4444
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
4545
except socket.error as err:

gunicorn/systemd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def sd_notify(state, logger, unset_environment=False):
5858
child processes.
5959
"""
6060

61-
6261
addr = os.environ.get('NOTIFY_SOCKET')
6362
if addr is None:
6463
# not run in a service, just a noop
@@ -69,7 +68,7 @@ def sd_notify(state, logger, unset_environment=False):
6968
addr = '\0' + addr[1:]
7069
sock.connect(addr)
7170
sock.sendall(state.encode('utf-8'))
72-
except:
71+
except Exception:
7372
logger.debug("Exception while invoking sd_notify()", exc_info=True)
7473
finally:
7574
if unset_environment:

gunicorn/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def load_class(uri, default="gunicorn.workers.sync.SyncWorker",
9797

9898
try:
9999
mod = importlib.import_module('.'.join(components))
100-
except:
100+
except Exception:
101101
exc = traceback.format_exc()
102102
msg = "class uri %r invalid or not found: \n\n[%s]"
103103
raise RuntimeError(msg % (uri, exc))

gunicorn/workers/geventlet.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def _eventlet_socket_sendfile(self, file, offset=0, count=None):
6666
file.seek(offset + total_sent)
6767

6868

69-
7069
def _eventlet_serve(sock, handle, concurrency):
7170
"""
7271
Serve requests forever.

gunicorn/workers/ggevent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def patch(self):
4141
sockets = []
4242
for s in self.sockets:
4343
sockets.append(socket.socket(s.FAMILY, socket.SOCK_STREAM,
44-
fileno=s.sock.fileno()))
44+
fileno=s.sock.fileno()))
4545
self.sockets = sockets
4646

4747
def notify(self):

0 commit comments

Comments
 (0)