mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
miscellaneous fixes
This commit is contained in:
parent
039bf47c3d
commit
60644b12af
@ -3,17 +3,15 @@
|
||||
# This file is part of gunicorn released under the MIT license.
|
||||
# See the NOTICE for more information.
|
||||
|
||||
import errno
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
|
||||
from gunicorn.glogging import Logger
|
||||
from gunicorn import util
|
||||
from gunicorn.arbiter import Arbiter
|
||||
from gunicorn.config import Config
|
||||
from gunicorn import debug
|
||||
from gunicorn.six import execfile_
|
||||
|
||||
class Application(object):
|
||||
"""\
|
||||
@ -62,7 +60,7 @@ class Application(object):
|
||||
"__package__": None
|
||||
}
|
||||
try:
|
||||
execfile(opts.config, cfg, cfg)
|
||||
execfile_(opts.config, cfg, cfg)
|
||||
except Exception:
|
||||
print("Failed to read config file: %s" % opts.config)
|
||||
traceback.print_exc()
|
||||
@ -104,15 +102,12 @@ class Application(object):
|
||||
def run(self):
|
||||
if self.cfg.check_config:
|
||||
try:
|
||||
|
||||
self.load()
|
||||
except:
|
||||
sys.stderr.write("\nError while loading the application:\n\n")
|
||||
traceback.print_exc()
|
||||
|
||||
sys.stderr.flush()
|
||||
sys.exit(1)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
if self.cfg.spew:
|
||||
|
||||
@ -10,10 +10,12 @@ import re
|
||||
import sys
|
||||
import time
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
from io import StringIO
|
||||
from imp import reload
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.validation import get_validation_errors
|
||||
from django.utils import translation
|
||||
|
||||
@ -49,7 +49,7 @@ def make_default_env(cfg):
|
||||
sys.path.insert(0, pythonpath)
|
||||
|
||||
try:
|
||||
_ = os.environ['DJANGO_SETTINGS_MODULE']
|
||||
os.environ['DJANGO_SETTINGS_MODULE']
|
||||
except KeyError:
|
||||
# not settings env set, try to build one.
|
||||
project_path, settings_name = find_settings_module(os.getcwd())
|
||||
|
||||
@ -6,7 +6,11 @@
|
||||
import os
|
||||
import pkg_resources
|
||||
import sys
|
||||
import ConfigParser
|
||||
|
||||
try:
|
||||
import configparser as ConfigParser
|
||||
except ImportError:
|
||||
import ConfigParser
|
||||
|
||||
from paste.deploy import loadapp, loadwsgi
|
||||
SERVER = loadwsgi.SERVER
|
||||
|
||||
@ -15,6 +15,7 @@ import types
|
||||
from gunicorn import __version__
|
||||
from gunicorn.errors import ConfigError
|
||||
from gunicorn import util
|
||||
from gunicorn.six import string_types
|
||||
|
||||
KNOWN_SETTINGS = []
|
||||
|
||||
@ -181,7 +182,7 @@ class Setting(object):
|
||||
def validate_bool(val):
|
||||
if isinstance(val, types.BooleanType):
|
||||
return val
|
||||
if not isinstance(val, basestring):
|
||||
if not isinstance(val, string_types):
|
||||
raise TypeError("Invalid type for casting: %s" % val)
|
||||
if val.lower().strip() == "true":
|
||||
return True
|
||||
@ -208,7 +209,7 @@ def validate_pos_int(val):
|
||||
def validate_string(val):
|
||||
if val is None:
|
||||
return None
|
||||
if not isinstance(val, basestring):
|
||||
if not isinstance(val, string_types):
|
||||
raise TypeError("Not a string: %s" % val)
|
||||
return val.strip()
|
||||
|
||||
@ -229,7 +230,7 @@ def validate_class(val):
|
||||
|
||||
def validate_callable(arity):
|
||||
def _validate_callable(val):
|
||||
if isinstance(val, basestring):
|
||||
if isinstance(val, string_types):
|
||||
try:
|
||||
mod_name, obj_name = val.rsplit(".", 1)
|
||||
except ValueError:
|
||||
|
||||
@ -6,13 +6,15 @@
|
||||
import datetime
|
||||
import logging
|
||||
logging.Logger.manager.emittedNoHandlerWarning = 1
|
||||
from logging.config import fileConfig
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
import threading
|
||||
|
||||
from logging.config import fileConfig
|
||||
|
||||
from gunicorn import util
|
||||
from gunicorn.six import string_types
|
||||
|
||||
CONFIG_DEFAULTS = dict(
|
||||
version = 1,
|
||||
@ -175,7 +177,7 @@ class Logger(object):
|
||||
self.error_log.exception(msg, *args)
|
||||
|
||||
def log(self, lvl, msg, *args, **kwargs):
|
||||
if isinstance(lvl, basestring):
|
||||
if isinstance(lvl, string_types):
|
||||
lvl = self.LOG_LEVELS.get(lvl.lower(), logging.INFO)
|
||||
self.error_log.log(lvl, msg, *args, **kwargs)
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import sys
|
||||
|
||||
from gunicorn.http.errors import (NoMoreData, ChunkMissingTerminator,
|
||||
InvalidChunkSize)
|
||||
from gunicorn.six import StringIO, bytes_to_str
|
||||
from gunicorn.six import StringIO, bytes_to_str, integer_types
|
||||
|
||||
class ChunkedReader(object):
|
||||
def __init__(self, req, unreader):
|
||||
@ -16,7 +16,7 @@ class ChunkedReader(object):
|
||||
self.buf = StringIO()
|
||||
|
||||
def read(self, size):
|
||||
if not isinstance(size, (int, long)):
|
||||
if not isinstance(size, integer_types):
|
||||
raise TypeError("size must be an integral type")
|
||||
if size <= 0:
|
||||
raise ValueError("Size must be positive.")
|
||||
@ -111,7 +111,7 @@ class LengthReader(object):
|
||||
self.length = length
|
||||
|
||||
def read(self, size):
|
||||
if not isinstance(size, (int, long)):
|
||||
if not isinstance(size, integer_types):
|
||||
raise TypeError("size must be an integral type")
|
||||
|
||||
size = min(self.length, size)
|
||||
@ -142,7 +142,7 @@ class EOFReader(object):
|
||||
self.finished = False
|
||||
|
||||
def read(self, size):
|
||||
if not isinstance(size, (int, long)):
|
||||
if not isinstance(size, integer_types):
|
||||
raise TypeError("size must be an integral type")
|
||||
if size < 0:
|
||||
raise ValueError("Size must be positive.")
|
||||
@ -189,7 +189,7 @@ class Body(object):
|
||||
def getsize(self, size):
|
||||
if size is None:
|
||||
return sys.maxint
|
||||
elif not isinstance(size, (int, long)):
|
||||
elif not isinstance(size, integer_types):
|
||||
raise TypeError("size must be an integral type")
|
||||
elif size < 0:
|
||||
return sys.maxint
|
||||
|
||||
@ -5,10 +5,7 @@
|
||||
|
||||
import os
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
from gunicorn.six import integer_types, StringIO
|
||||
|
||||
# Classes that can undo reading data from
|
||||
# a given type of data source.
|
||||
@ -21,7 +18,7 @@ class Unreader(object):
|
||||
raise NotImplementedError()
|
||||
|
||||
def read(self, size=None):
|
||||
if size is not None and not isinstance(size, (int, long)):
|
||||
if size is not None and not isinstance(size, integer_types):
|
||||
raise TypeError("size parameter must be an int or long.")
|
||||
if size == 0:
|
||||
return ""
|
||||
|
||||
@ -8,7 +8,8 @@ import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from gunicorn.six import unquote, string_types, binary_type, reraise
|
||||
from gunicorn.six import (unquote, string_types, binary_type, reraise,
|
||||
text_type)
|
||||
from gunicorn import SERVER_SOFTWARE
|
||||
import gunicorn.util as util
|
||||
|
||||
@ -117,7 +118,7 @@ def create(req, sock, client, server, cfg):
|
||||
|
||||
environ['wsgi.url_scheme'] = url_scheme
|
||||
|
||||
if isinstance(forward, basestring):
|
||||
if isinstance(forward, string_types):
|
||||
# we only took the last one
|
||||
# http://en.wikipedia.org/wiki/X-Forwarded-For
|
||||
if forward.find(",") >= 0:
|
||||
@ -144,7 +145,7 @@ def create(req, sock, client, server, cfg):
|
||||
environ['REMOTE_ADDR'] = remote[0]
|
||||
environ['REMOTE_PORT'] = str(remote[1])
|
||||
|
||||
if isinstance(server, basestring):
|
||||
if isinstance(server, string_types):
|
||||
server = server.split(":")
|
||||
if len(server) == 1:
|
||||
if url_scheme == "http":
|
||||
@ -208,7 +209,7 @@ class Response(object):
|
||||
|
||||
def process_headers(self, headers):
|
||||
for name, value in headers:
|
||||
assert isinstance(name, basestring), "%r is not a string" % name
|
||||
assert isinstance(name, string_types), "%r is not a string" % name
|
||||
lname = name.lower().strip()
|
||||
if lname == "content-length":
|
||||
self.response_length = int(value)
|
||||
|
||||
@ -294,6 +294,10 @@ if PY3:
|
||||
print_ = getattr(builtins, "print")
|
||||
del builtins
|
||||
|
||||
def execfile_(file, globals=globals(), locals=locals()):
|
||||
with open(file, "r") as fh:
|
||||
exec_(fh.read()+"\n", globals, locals)
|
||||
|
||||
else:
|
||||
def exec_(code, globs=None, locs=None):
|
||||
"""Execute code in a namespace."""
|
||||
@ -312,6 +316,7 @@ else:
|
||||
raise tp, value, tb
|
||||
""")
|
||||
|
||||
execfile_ = execfile
|
||||
|
||||
def print_(*args, **kwargs):
|
||||
"""The new-style print function."""
|
||||
|
||||
@ -10,7 +10,7 @@ import sys
|
||||
import time
|
||||
|
||||
from gunicorn import util
|
||||
|
||||
from gunicorn.six import string_types
|
||||
|
||||
class BaseSocket(object):
|
||||
|
||||
@ -108,7 +108,7 @@ def create_socket(conf, log):
|
||||
sock_type = TCP6Socket
|
||||
else:
|
||||
sock_type = TCPSocket
|
||||
elif isinstance(addr, basestring):
|
||||
elif isinstance(addr, string_types):
|
||||
sock_type = UnixSocket
|
||||
else:
|
||||
raise TypeError("Unable to create socket from: %r" % addr)
|
||||
|
||||
@ -25,7 +25,7 @@ import textwrap
|
||||
import time
|
||||
import inspect
|
||||
|
||||
from gunicorn.six import text_type
|
||||
from gunicorn.six import text_type, string_types
|
||||
|
||||
MAXFD = 1024
|
||||
if (hasattr(os, "devnull")):
|
||||
@ -75,7 +75,7 @@ except ImportError:
|
||||
if not hasattr(package, 'rindex'):
|
||||
raise ValueError("'package' not set to a string")
|
||||
dot = len(package)
|
||||
for x in xrange(level, 1, -1):
|
||||
for x in range(level, 1, -1):
|
||||
try:
|
||||
dot = package.rindex('.', 0, dot)
|
||||
except ValueError:
|
||||
@ -217,14 +217,14 @@ try:
|
||||
except ImportError:
|
||||
def closerange(fd_low, fd_high):
|
||||
# Iterate through and close all file descriptors.
|
||||
for fd in xrange(fd_low, fd_high):
|
||||
for fd in range(fd_low, fd_high):
|
||||
try:
|
||||
os.close(fd)
|
||||
except OSError: # ERROR, fd wasn't open to begin with (ignored)
|
||||
pass
|
||||
|
||||
def write_chunk(sock, data):
|
||||
if instance(data, text_type):
|
||||
if isinstance(data, text_type):
|
||||
data = data.decode('utf-8')
|
||||
chunk_size = "%X\r\n" % len(data)
|
||||
chunk = b"".join([chunk_size.decode('utf-8'), data, b"\r\n"])
|
||||
@ -263,7 +263,7 @@ def write_error(sock, status_int, reason, mesg):
|
||||
</html>
|
||||
""") % {"reason": reason, "mesg": mesg}
|
||||
|
||||
headers = textwrap.dedent("""\
|
||||
http = textwrap.dedent("""\
|
||||
HTTP/1.1 %s %s\r
|
||||
Connection: close\r
|
||||
Content-Type: text/html\r
|
||||
@ -313,7 +313,7 @@ def http_date(timestamp=None):
|
||||
|
||||
def to_bytestring(s):
|
||||
""" convert to bytestring an unicode """
|
||||
if not isinstance(s, basestring):
|
||||
if not isinstance(s, string_types):
|
||||
return s
|
||||
if isinstance(s, unicode):
|
||||
return s.encode('utf-8')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user