Codebase list gunicorn / f0bc798
Update upstream source from tag 'upstream/20.0.4' Update to upstream version '20.0.4' with Debian dir 3a682ad0fd06219121c19b07faae31e7fbd49757 Chris Lamb 4 years ago
9 changed file(s) with 32 addition(s) and 140 deletion(s). Raw diff Collapse all Expand all
1515 <div class="logo-div">
1616 <div class="latest">
1717 Latest version: <strong><a
18 href="https://docs.gunicorn.org/en/stable/">20.0.1</a></strong>
18 href="https://docs.gunicorn.org/en/stable/">20.0.3</a></strong>
1919 </div>
2020
2121 <div class="logo"><img src="images/logo.jpg" ></div>
5050 Configuration File
5151 ==================
5252
53 The configuration file should be a valid Python source file. It only needs to
54 be readable from the file system. More specifically, it does not need to be
55 importable. Any Python is valid. Just consider that this will be run every time
56 you start Gunicorn (including when you signal Gunicorn to reload).
53 The configuration file should be a valid Python source file with a **python
54 extension** (e.g. `gunicorn.conf.py`). It only needs to be readable from the
55 file system. More specifically, it does not have to be on the module path
56 (sys.path, PYTHONPATH). Any Python is valid. Just consider that this will be
57 run every time you start Gunicorn (including when you signal Gunicorn to reload).
5758
5859 To set a parameter, just assign to it. There's no special syntax. The values
5960 you provide will be used for the configuration values.
00 =========
11 Changelog
22 =========
3
4 20.0.4 / 2019/11/26
5 ===================
6
7 - fix binding a socket using the file descriptor
8 - remove support for the `bdist_rpm` build
9
10 20.0.3 / 2019/11/24
11 ===================
12
13 - fixed load of a config file without a Python extension
14 - fixed `socketfromfd.fromfd` when defaults are not set
15
16 .. note:: we now warn when we load a config file without Python Extension
317
418 20.0.2 / 2019/11/23
519 ===================
22 # This file is part of gunicorn released under the MIT license.
33 # See the NOTICE for more information.
44
5 version_info = (20, 0, 2)
5 version_info = (20, 0, 4)
66 __version__ = ".".join([str(v) for v in version_info])
77 SERVER_SOFTWARE = "gunicorn/%s" % __version__
22 # This file is part of gunicorn released under the MIT license.
33 # See the NOTICE for more information.
44 import importlib.util
5 import importlib.machinery
56 import os
67 import sys
78 import traceback
9394 if not os.path.exists(filename):
9495 raise RuntimeError("%r doesn't exist" % filename)
9596
97 ext = os.path.splitext(filename)[1]
98
9699 try:
97100 module_name = '__config__'
98 spec = importlib.util.spec_from_file_location(module_name, filename)
101 if ext in [".py", ".pyc"]:
102 spec = importlib.util.spec_from_file_location(module_name, filename)
103 else:
104 msg = "configuration file should have a valid Python extension.\n"
105 util.warn(msg)
106 loader_ = importlib.machinery.SourceFileLoader(module_name, filename)
107 spec = importlib.util.spec_from_file_location(module_name, filename, loader=loader_)
99108 mod = importlib.util.module_from_spec(spec)
100109 sys.modules[module_name] = mod
101110 spec.loader.exec_module(mod)
1010 import time
1111
1212 from gunicorn import util
13 from gunicorn.socketfromfd import fromfd
1413
1514
1615 class BaseSocket(object):
167166 # sockets are already bound
168167 if fdaddr:
169168 for fd in fdaddr:
170 sock = fromfd(fd)
169 sock = socket.fromfd(fd, socket.AF_UNIX, socket.SOCK_STREAM)
171170 sock_name = sock.getsockname()
172171 sock_type = _sock_type(sock_name)
173172 listener = sock_type(sock_name, conf, log, fd=fd)
+0
-109
gunicorn/socketfromfd.py less more
0 # Copyright (C) 2016 Christian Heimes
1 """socketfromfd -- socket.fromd() with auto-discovery
2
3 ATTENTION: Do not remove this backport till the minimum required version is
4 Python 3.7. See https://bugs.python.org/issue28134 for details.
5 """
6 from __future__ import print_function
7
8 import ctypes
9 import os
10 import socket
11 import sys
12 import platform
13
14 from .util import find_library
15
16 __all__ = ('fromfd',)
17
18 SO_DOMAIN = getattr(socket, 'SO_DOMAIN', 39)
19 SO_TYPE = getattr(socket, 'SO_TYPE', 3)
20 SO_PROTOCOL = getattr(socket, 'SO_PROTOCOL', 38)
21
22 _libc_name = find_library('c')
23 if _libc_name is not None:
24 if sys.platform.startswith("aix"):
25 member = (
26 '(shr_64.o)' if ctypes.sizeof(ctypes.c_voidp) == 8 else '(shr.o)')
27 # 0x00040000 correspondes to RTLD_MEMBER, undefined in Python <= 3.6
28 dlopen_mode = (ctypes.DEFAULT_MODE | 0x00040000 | os.RTLD_NOW)
29 libc = ctypes.CDLL(_libc_name+member,
30 use_errno=True,
31 mode=dlopen_mode)
32 else:
33 libc = ctypes.CDLL(_libc_name, use_errno=True)
34 else:
35 raise OSError('libc not found')
36
37
38 def _errcheck_errno(result, func, arguments):
39 """Raise OSError by errno for -1
40 """
41 if result == -1:
42 errno = ctypes.get_errno()
43 raise OSError(errno, os.strerror(errno))
44 return arguments
45
46
47 if platform.system() == 'SunOS':
48 _libc_getsockopt = libc._so_getsockopt
49 else:
50 _libc_getsockopt = libc.getsockopt
51 _libc_getsockopt.argtypes = [
52 ctypes.c_int, # int sockfd
53 ctypes.c_int, # int level
54 ctypes.c_int, # int optname
55 ctypes.c_void_p, # void *optval
56 ctypes.POINTER(ctypes.c_uint32) # socklen_t *optlen
57 ]
58 _libc_getsockopt.restype = ctypes.c_int # 0: ok, -1: err
59 _libc_getsockopt.errcheck = _errcheck_errno
60
61
62 def _raw_getsockopt(fd, level, optname):
63 """Make raw getsockopt() call for int32 optval
64
65 :param fd: socket fd
66 :param level: SOL_*
67 :param optname: SO_*
68 :return: value as int
69 """
70 optval = ctypes.c_int(0)
71 optlen = ctypes.c_uint32(4)
72 _libc_getsockopt(fd, level, optname,
73 ctypes.byref(optval), ctypes.byref(optlen))
74 return optval.value
75
76
77 def fromfd(fd, keep_fd=True):
78 """Create a socket from a file descriptor
79
80 socket domain (family), type and protocol are auto-detected. By default
81 the socket uses a dup()ed fd. The original fd can be closed.
82
83 The parameter `keep_fd` influences fd duplication. Under Python 2 the
84 fd is still duplicated but the input fd is closed. Under Python 3 and
85 with `keep_fd=True`, the new socket object uses the same fd.
86
87 :param fd: socket fd
88 :type fd: int
89 :param keep_fd: keep input fd
90 :type keep_fd: bool
91 :return: socket.socket instance
92 :raises OSError: for invalid socket fd
93 """
94 family = _raw_getsockopt(fd, socket.SOL_SOCKET, SO_DOMAIN)
95 typ = _raw_getsockopt(fd, socket.SOL_SOCKET, SO_TYPE)
96 proto = _raw_getsockopt(fd, socket.SOL_SOCKET, SO_PROTOCOL)
97 if sys.version_info.major == 2:
98 # Python 2 has no fileno argument and always duplicates the fd
99 sockobj = socket.fromfd(fd, family, typ, proto)
100 sock = socket.socket(None, None, None, _sock=sockobj)
101 if not keep_fd:
102 os.close(fd)
103 return sock
104 else:
105 if keep_fd:
106 return socket.fromfd(fd, family, typ, proto)
107 else:
108 return socket.socket(family, typ, proto, fileno=fd)
+0
-16
rpm/install less more
0 %{__python} setup.py install --skip-build --root=$RPM_BUILD_ROOT
1
2 # Build the HTML documentation using the default theme.
3 %{__python} setup.py build_sphinx
4
5 %if ! (0%{?fedora} > 12 || 0%{?rhel} > 5)
6 %{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
7 %{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
8 %endif
9
10 INSTALLED_FILES="\
11 %{python_sitelib}/*
12 %{_bindir}/*
13 %doc LICENSE NOTICE README.rst THANKS build/sphinx/html examples/example_config.py
14 "
15 echo "$INSTALLED_FILES" > INSTALLED_FILES
0 [bdist_rpm]
1 build-requires = python2-devel python-setuptools python-sphinx
2 requires = python-setuptools >= 0.6c6 python-ctypes
3 install_script = rpm/install
4 group = System Environment/Daemons
5
60 [tool:pytest]
71 norecursedirs = examples lib local src
82 testpaths = tests/