Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 style cleanup (part 2) #3280

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions docs/source/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -523,27 +523,12 @@ SSL certificate file

**Command line:** ``--ssl-version``

**Default:** ``<_SSLMethod.PROTOCOL_TLS: 2>``
**Default:** (ignored)

SSL version to use (see stdlib ssl module's).

.. deprecated:: 21.0
The option is deprecated and it is currently ignored. Use :ref:`ssl-context` instead.

============= ============
--ssl-version Description
============= ============
SSLv3 SSLv3 is not-secure and is strongly discouraged.
SSLv23 Alias for TLS. Deprecated in Python 3.6, use TLS.
TLS Negotiate highest possible version between client/server.
Can yield SSL. (Python 3.6+)
TLSv1 TLS 1.0
TLSv1_1 TLS 1.1 (Python 3.4+)
TLSv1_2 TLS 1.2 (Python 3.4+)
TLS_SERVER Auto-negotiate the highest protocol version like TLS,
but only support server-side SSLSocket connections.
(Python 3.6+)
============= ============
The option is deprecated and it is currently **ignored**. Use :ref:`ssl-context` instead.

.. versionchanged:: 19.7
The default value has been changed from ``ssl.PROTOCOL_TLSv1`` to
Expand Down Expand Up @@ -1166,9 +1151,11 @@ Note that this affects unix socket permissions.

A valid value for the ``os.umask(mode)`` call or a string compatible
with ``int(value, 0)`` (``0`` means Python guesses the base, so values
like ``0``, ``0xFF``, ``0022`` are valid for decimal, hex, and octal
like ``0``, ``0xFF``, ``0o022`` are valid for decimal, hex, and octal
representations)

.. note:: For historical reasons, leading zero is treated like ``0o``.

.. _initgroups:

``initgroups``
Expand Down Expand Up @@ -1650,14 +1637,14 @@ libraries may be installed using setuptools' ``extras_require`` feature.
A string referring to one of the following bundled classes:

* ``sync``
* ``gthread``
* ``eventlet`` - Requires eventlet >= 0.24.1 (or install it via
``pip install gunicorn[eventlet]``)
``pip install gunicorn[eventlet]``).
Usages in new projects are discouraged.
* ``gevent`` - Requires gevent >= 1.4 (or install it via
``pip install gunicorn[gevent]``)
* ``tornado`` - Requires tornado >= 0.2 (or install it via
``pip install gunicorn[tornado]``)
* ``gthread`` - Python 2 requires the futures package to be installed
(or install it via ``pip install gunicorn[gthread]``)

Optionally, you can provide your own worker by giving Gunicorn a
Python path to a subclass of ``gunicorn.workers.base.Worker``.
Expand Down
4 changes: 1 addition & 3 deletions gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,7 @@ def sleep(self):
while os.read(self.PIPE[0], 1):
pass
except OSError as e:
# TODO: select.error is a subclass of OSError since Python 3.3.
error_number = getattr(e, 'errno', e.args[0])
if error_number not in [errno.EAGAIN, errno.EINTR]:
if e.errno not in [errno.EAGAIN, errno.EINTR]:
raise
except KeyboardInterrupt:
sys.exit()
Expand Down
35 changes: 9 additions & 26 deletions gunicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,14 +678,14 @@ class WorkerClass(Setting):
A string referring to one of the following bundled classes:

* ``sync``
* ``gthread``
* ``eventlet`` - Requires eventlet >= 0.24.1 (or install it via
``pip install gunicorn[eventlet]``)
``pip install gunicorn[eventlet]``).
Usages in new projects are discouraged.
* ``gevent`` - Requires gevent >= 1.4 (or install it via
``pip install gunicorn[gevent]``)
* ``tornado`` - Requires tornado >= 0.2 (or install it via
``pip install gunicorn[tornado]``)
* ``gthread`` - Python 2 requires the futures package to be installed
(or install it via ``pip install gunicorn[gthread]``)

Optionally, you can provide your own worker by giving Gunicorn a
Python path to a subclass of ``gunicorn.workers.base.Worker``.
Expand Down Expand Up @@ -1197,8 +1197,10 @@ class Umask(Setting):

A valid value for the ``os.umask(mode)`` call or a string compatible
with ``int(value, 0)`` (``0`` means Python guesses the base, so values
like ``0``, ``0xFF``, ``0022`` are valid for decimal, hex, and octal
like ``0``, ``0xFF``, ``0o022`` are valid for decimal, hex, and octal
representations)

.. note:: For historical reasons, leading zero is treated like ``0o``.
"""


Expand Down Expand Up @@ -2125,33 +2127,14 @@ class SSLVersion(Setting):
section = "SSL"
cli = ["--ssl-version"]
validator = validate_ssl_version
default = object() # always warn unless left at default
default_doc = "(ignored)"

if hasattr(ssl, "PROTOCOL_TLS"):
default = ssl.PROTOCOL_TLS
else:
default = ssl.PROTOCOL_SSLv23

default = ssl.PROTOCOL_SSLv23
desc = """\
SSL version to use (see stdlib ssl module's).

.. deprecated:: 21.0
The option is deprecated and it is currently ignored. Use :ref:`ssl-context` instead.

============= ============
--ssl-version Description
============= ============
SSLv3 SSLv3 is not-secure and is strongly discouraged.
SSLv23 Alias for TLS. Deprecated in Python 3.6, use TLS.
TLS Negotiate highest possible version between client/server.
Can yield SSL. (Python 3.6+)
TLSv1 TLS 1.0
TLSv1_1 TLS 1.1 (Python 3.4+)
TLSv1_2 TLS 1.2 (Python 3.4+)
TLS_SERVER Auto-negotiate the highest protocol version like TLS,
but only support server-side SSLSocket connections.
(Python 3.6+)
============= ============
The option is deprecated and it is currently **ignored**. Use :ref:`ssl-context` instead.

.. versionchanged:: 19.7
The default value has been changed from ``ssl.PROTOCOL_TLSv1`` to
Expand Down
6 changes: 3 additions & 3 deletions gunicorn/pidfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ def validate(self):
os.kill(wpid, 0)
return wpid
except OSError as e:
if e.args[0] == errno.EPERM:
if e.errno == errno.EPERM:
return wpid
if e.args[0] == errno.ESRCH:
if e.errno == errno.ESRCH:
return
raise
except OSError as e:
if e.args[0] == errno.ENOENT:
if e.errno == errno.ENOENT:
return
raise
6 changes: 3 additions & 3 deletions gunicorn/sock.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(self, addr, conf, log, fd=None):
try:
st = os.stat(addr)
except OSError as e:
if e.args[0] != errno.ENOENT:
if e.errno != errno.ENOENT:
raise
else:
if stat.S_ISSOCK(st.st_mode):
Expand Down Expand Up @@ -183,9 +183,9 @@ def create_sockets(conf, log, fds=None):
try:
sock = sock_type(addr, conf, log)
except OSError as e:
if e.args[0] == errno.EADDRINUSE:
if e.errno == errno.EADDRINUSE:
log.error("Connection in use: %s", str(addr))
if e.args[0] == errno.EADDRNOTAVAIL:
if e.errno == errno.EADDRNOTAVAIL:
log.error("Invalid address: %s", str(addr))
msg = "connection to {addr} failed: {error}"
log.error(msg.format(addr=str(addr), error=str(e)))
Expand Down
4 changes: 2 additions & 2 deletions gunicorn/workers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def wait(self, timeout):
return ret[0]

except OSError as e:
if e.args[0] == errno.EINTR:
if e.errno == errno.EINTR:
return self.sockets
if e.args[0] == errno.EBADF:
if e.errno == errno.EBADF:
if self.nr < 0:
return self.sockets
else:
Expand Down
3 changes: 2 additions & 1 deletion tests/requests/invalid/001.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import NoMoreData
request = NoMoreData

request = NoMoreData
1 change: 1 addition & 0 deletions tests/requests/invalid/002.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidRequestLine

request = InvalidRequestLine
1 change: 1 addition & 0 deletions tests/requests/invalid/003.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidRequestLine

request = InvalidRequestLine
3 changes: 2 additions & 1 deletion tests/requests/invalid/003b.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidRequestMethod
request = InvalidRequestMethod

request = InvalidRequestMethod
1 change: 1 addition & 0 deletions tests/requests/invalid/003c.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidRequestMethod

request = InvalidRequestMethod
3 changes: 2 additions & 1 deletion tests/requests/invalid/004.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidHTTPVersion
request = InvalidHTTPVersion

request = InvalidHTTPVersion
3 changes: 2 additions & 1 deletion tests/requests/invalid/005.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidHeaderName
request = InvalidHeaderName

request = InvalidHeaderName
1 change: 1 addition & 0 deletions tests/requests/invalid/006.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import LimitRequestLine

request = LimitRequestLine
1 change: 1 addition & 0 deletions tests/requests/invalid/007.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import LimitRequestHeaders

request = LimitRequestHeaders
1 change: 1 addition & 0 deletions tests/requests/invalid/008.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import LimitRequestHeaders

request = LimitRequestHeaders
1 change: 1 addition & 0 deletions tests/requests/invalid/009.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import LimitRequestHeaders

request = LimitRequestHeaders
2 changes: 0 additions & 2 deletions tests/requests/invalid/010.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from gunicorn.config import Config
from gunicorn.http.errors import LimitRequestHeaders

request = LimitRequestHeaders
cfg = Config()
cfg.set('limit_request_field_size', 10)
2 changes: 0 additions & 2 deletions tests/requests/invalid/011.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from gunicorn.config import Config
from gunicorn.http.errors import LimitRequestHeaders

request = LimitRequestHeaders
cfg = Config()
cfg.set('limit_request_fields', 2)
2 changes: 0 additions & 2 deletions tests/requests/invalid/012.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from gunicorn.config import Config
from gunicorn.http.errors import LimitRequestHeaders

request = LimitRequestHeaders
cfg = Config()
cfg.set('limit_request_field_size', 98)
2 changes: 0 additions & 2 deletions tests/requests/invalid/013.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from gunicorn.config import Config
from gunicorn.http.errors import LimitRequestHeaders

request = LimitRequestHeaders
cfg = Config()
cfg.set('limit_request_field_size', 14)

# once this option is removed, this test should not be dropped;
Expand Down
2 changes: 0 additions & 2 deletions tests/requests/invalid/017.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gunicorn.config import Config
from gunicorn.http.errors import LimitRequestHeaders

cfg = Config()
request = LimitRequestHeaders
1 change: 1 addition & 0 deletions tests/requests/invalid/018.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidHTTPVersion

request = InvalidHTTPVersion
2 changes: 0 additions & 2 deletions tests/requests/invalid/019.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidSchemeHeaders

request = InvalidSchemeHeaders
cfg = Config()
cfg.set('forwarded_allow_ips', '*')
2 changes: 0 additions & 2 deletions tests/requests/invalid/020.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeaderName

cfg = Config()
request = InvalidHeaderName
2 changes: 0 additions & 2 deletions tests/requests/invalid/021.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader

cfg = Config()
request = InvalidHeader
2 changes: 0 additions & 2 deletions tests/requests/invalid/022.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader

cfg = Config()
request = InvalidHeader
2 changes: 0 additions & 2 deletions tests/requests/invalid/023.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader

cfg = Config()
request = InvalidHeader
2 changes: 0 additions & 2 deletions tests/requests/invalid/024.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader

cfg = Config()
request = InvalidHeader
2 changes: 0 additions & 2 deletions tests/requests/invalid/040.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from gunicorn.http.errors import InvalidHeaderName
from gunicorn.config import Config

cfg = Config()
cfg.set("header_map", "refuse")

request = InvalidHeaderName
1 change: 1 addition & 0 deletions tests/requests/invalid/chunked_01.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidChunkSize

request = InvalidChunkSize
1 change: 1 addition & 0 deletions tests/requests/invalid/chunked_02.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidHeader

request = InvalidHeader
5 changes: 3 additions & 2 deletions tests/requests/invalid/chunked_03.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidHeader
request = InvalidHeader
from gunicorn.http.errors import InvalidHeader

request = InvalidHeader
1 change: 1 addition & 0 deletions tests/requests/invalid/chunked_04.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidHeader

request = InvalidHeader
1 change: 1 addition & 0 deletions tests/requests/invalid/chunked_05.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidHeader

request = InvalidHeader
5 changes: 3 additions & 2 deletions tests/requests/invalid/chunked_06.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidHeader
request = InvalidHeader
from gunicorn.http.errors import InvalidHeader

request = InvalidHeader
2 changes: 0 additions & 2 deletions tests/requests/invalid/chunked_07.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from gunicorn.http.errors import InvalidHeaderName
from gunicorn.config import Config

cfg = Config()
cfg.set("header_map", "refuse")

request = InvalidHeaderName
1 change: 1 addition & 0 deletions tests/requests/invalid/chunked_08.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidHeader

request = InvalidHeader
1 change: 1 addition & 0 deletions tests/requests/invalid/chunked_09.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidChunkSize

request = InvalidChunkSize
1 change: 1 addition & 0 deletions tests/requests/invalid/chunked_10.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidChunkSize

request = InvalidChunkSize
1 change: 1 addition & 0 deletions tests/requests/invalid/chunked_11.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidChunkSize

request = InvalidChunkSize
1 change: 1 addition & 0 deletions tests/requests/invalid/chunked_12.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidChunkSize

request = InvalidChunkSize
1 change: 1 addition & 0 deletions tests/requests/invalid/chunked_13.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from gunicorn.http.errors import InvalidChunkSize

request = InvalidChunkSize
2 changes: 0 additions & 2 deletions tests/requests/invalid/invalid_field_value_01.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader

cfg = Config()
request = InvalidHeader
2 changes: 0 additions & 2 deletions tests/requests/invalid/nonascii_01.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidRequestMethod

cfg = Config()
request = InvalidRequestMethod
Loading
Loading