mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Merge pull request #485 from mahmoud/master
Remove ctypes dependency in util
This commit is contained in:
commit
a314f5adb1
@ -4,16 +4,6 @@
|
|||||||
# See the NOTICE for more information.
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
import ctypes
|
|
||||||
except MemoryError:
|
|
||||||
# selinux execmem denial
|
|
||||||
# https://bugzilla.redhat.com/show_bug.cgi?id=488396
|
|
||||||
ctypes = None
|
|
||||||
except ImportError:
|
|
||||||
# Python on Solaris compiled with Sun Studio doesn't have ctypes
|
|
||||||
ctypes = None
|
|
||||||
|
|
||||||
import fcntl
|
import fcntl
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
@ -120,7 +110,7 @@ def load_class(uri, default="sync", section="gunicorn.workers"):
|
|||||||
return pkg_resources.load_entry_point(dist, section, name)
|
return pkg_resources.load_entry_point(dist, section, name)
|
||||||
except:
|
except:
|
||||||
exc = traceback.format_exc()
|
exc = traceback.format_exc()
|
||||||
raise RuntimeError("class uri %r invalid or not found: \n\n[%s]" % (uri,
|
raise RuntimeError("class uri %r invalid or not found: \n\n[%s]" % (uri,
|
||||||
exc))
|
exc))
|
||||||
else:
|
else:
|
||||||
components = uri.split('.')
|
components = uri.split('.')
|
||||||
@ -133,7 +123,7 @@ def load_class(uri, default="sync", section="gunicorn.workers"):
|
|||||||
section, uri)
|
section, uri)
|
||||||
except:
|
except:
|
||||||
exc = traceback.format_exc()
|
exc = traceback.format_exc()
|
||||||
raise RuntimeError("class uri %r invalid or not found: \n\n[%s]" % (uri,
|
raise RuntimeError("class uri %r invalid or not found: \n\n[%s]" % (uri,
|
||||||
exc))
|
exc))
|
||||||
|
|
||||||
klass = components.pop(-1)
|
klass = components.pop(-1)
|
||||||
@ -141,7 +131,7 @@ def load_class(uri, default="sync", section="gunicorn.workers"):
|
|||||||
mod = __import__('.'.join(components))
|
mod = __import__('.'.join(components))
|
||||||
except:
|
except:
|
||||||
exc = traceback.format_exc()
|
exc = traceback.format_exc()
|
||||||
raise RuntimeError("class uri %r invalid or not found: \n\n[%s]" % (uri,
|
raise RuntimeError("class uri %r invalid or not found: \n\n[%s]" % (uri,
|
||||||
exc))
|
exc))
|
||||||
|
|
||||||
for comp in components[1:]:
|
for comp in components[1:]:
|
||||||
@ -152,26 +142,17 @@ def load_class(uri, default="sync", section="gunicorn.workers"):
|
|||||||
def set_owner_process(uid, gid):
|
def set_owner_process(uid, gid):
|
||||||
""" set user and group of workers processes """
|
""" set user and group of workers processes """
|
||||||
if gid:
|
if gid:
|
||||||
try:
|
# versions of python < 2.6.2 don't manage unsigned int for
|
||||||
os.setgid(gid)
|
# groups like on osx or fedora
|
||||||
except OverflowError:
|
gid = abs(gid) & 0x7FFFFFFF
|
||||||
if not ctypes:
|
os.setgid(gid)
|
||||||
raise
|
|
||||||
# versions of python < 2.6.2 don't manage unsigned int for
|
|
||||||
# groups like on osx or fedora
|
|
||||||
os.setgid(-ctypes.c_int(-gid).value)
|
|
||||||
|
|
||||||
if uid:
|
if uid:
|
||||||
os.setuid(uid)
|
os.setuid(uid)
|
||||||
|
|
||||||
|
|
||||||
def chown(path, uid, gid):
|
def chown(path, uid, gid):
|
||||||
try:
|
gid = abs(gid) & 0x7FFFFFFF # see note above.
|
||||||
os.chown(path, uid, gid)
|
os.chown(path, uid, gid)
|
||||||
except OverflowError:
|
|
||||||
if not ctypes:
|
|
||||||
raise
|
|
||||||
os.chown(path, uid, -ctypes.c_int(-gid).value)
|
|
||||||
|
|
||||||
|
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
@ -232,12 +213,12 @@ def is_ipv6(addr):
|
|||||||
|
|
||||||
|
|
||||||
def parse_address(netloc, default_port=8000):
|
def parse_address(netloc, default_port=8000):
|
||||||
if netloc.startswith("unix:"):
|
|
||||||
return netloc.split("unix:")[1]
|
|
||||||
|
|
||||||
if netloc.startswith("unix://"):
|
if netloc.startswith("unix://"):
|
||||||
return netloc.split("unix://")[1]
|
return netloc.split("unix://")[1]
|
||||||
|
|
||||||
|
if netloc.startswith("unix:"):
|
||||||
|
return netloc.split("unix:")[1]
|
||||||
|
|
||||||
if netloc.startswith("tcp://"):
|
if netloc.startswith("tcp://"):
|
||||||
netloc = netloc.split("tcp://")[1]
|
netloc = netloc.split("tcp://")[1]
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user