Revert changes to 'upstream-derived' file

This commit is contained in:
Hugo 2017-12-18 16:05:02 +02:00
parent 711deb51b7
commit 127b097022

@ -89,15 +89,17 @@ except ImportError: # pragma: no cover
def json_dumps(data): def json_dumps(data):
raise ImportError( raise ImportError(
"JSON support requires simplejson.") "JSON support requires Python 2.6 or simplejson.")
json_lds = json_dumps json_lds = json_dumps
# We now try to fix 2.x/3.x incompatibilities. # We now try to fix 2.5/2.6/3.1/3.2 incompatibilities.
# It ain't pretty but it works... Sorry for the mess. # It ain't pretty but it works... Sorry for the mess.
py = sys.version_info py = sys.version_info
py3k = py >= (3, 0, 0) py3k = py >= (3, 0, 0)
py25 = py < (2, 6, 0)
py31 = (3, 1, 0) <= py < (3, 2, 0)
# Workaround for the missing "as" keyword in py3k. # Workaround for the missing "as" keyword in py3k.
def _e(): def _e():
@ -142,6 +144,16 @@ else: # 2.x
from StringIO import StringIO as BytesIO from StringIO import StringIO as BytesIO
from ConfigParser import SafeConfigParser as ConfigParser, \ from ConfigParser import SafeConfigParser as ConfigParser, \
Error as ConfigParserError Error as ConfigParserError
if py25:
msg = "Python 2.5 support may be dropped in future versions of Bottle."
warnings.warn(msg, DeprecationWarning)
from UserDict import DictMixin
def next(it):
return it.next()
bytes = str
else: # 2.6, 2.7
from collections import MutableMapping as DictMixin from collections import MutableMapping as DictMixin
unicode = unicode unicode = unicode
json_loads = json_lds json_loads = json_lds
@ -162,6 +174,15 @@ def touni(s, enc='utf8', err='strict'):
tonat = touni if py3k else tob tonat = touni if py3k else tob
# 3.2 fixes cgi.FieldStorage to accept bytes (which makes a lot of sense).
# 3.1 needs a workaround.
if py31:
from io import TextIOWrapper
class NCTextIOWrapper(TextIOWrapper):
def close(self):
pass # Keep wrapped buffer open.
# A bug in functools causes it to break if the wrapper is an instance method # A bug in functools causes it to break if the wrapper is an instance method
def update_wrapper(wrapper, wrapped, *a, **ka): def update_wrapper(wrapper, wrapped, *a, **ka):
@ -1274,7 +1295,11 @@ class BaseRequest(object):
for key in ('REQUEST_METHOD', 'CONTENT_TYPE', 'CONTENT_LENGTH'): for key in ('REQUEST_METHOD', 'CONTENT_TYPE', 'CONTENT_LENGTH'):
if key in self.environ: safe_env[key] = self.environ[key] if key in self.environ: safe_env[key] = self.environ[key]
args = dict(fp=self.body, environ=safe_env, keep_blank_values=True) args = dict(fp=self.body, environ=safe_env, keep_blank_values=True)
if py3k: if py31:
args['fp'] = NCTextIOWrapper(args['fp'],
encoding='utf8',
newline='\n')
elif py3k:
args['encoding'] = 'utf8' args['encoding'] = 'utf8'
data = cgi.FieldStorage(**args) data = cgi.FieldStorage(**args)
self['_cgi.FieldStorage'] = data #http://bugs.python.org/issue18394 self['_cgi.FieldStorage'] = data #http://bugs.python.org/issue18394
@ -1380,7 +1405,7 @@ class BaseRequest(object):
basic = parse_auth(self.environ.get('HTTP_AUTHORIZATION', '')) basic = parse_auth(self.environ.get('HTTP_AUTHORIZATION', ''))
if basic: return basic if basic: return basic
ruser = self.environ.get('REMOTE_USER') ruser = self.environ.get('REMOTE_USER')
if ruser: return ruser, None if ruser: return (ruser, None)
return None return None
@property @property
@ -1503,10 +1528,10 @@ class BaseResponse(object):
# Header blacklist for specific response codes # Header blacklist for specific response codes
# (rfc2616 section 10.2.3 and 10.3.5) # (rfc2616 section 10.2.3 and 10.3.5)
bad_headers = { bad_headers = {
204: {'Content-Type'}, 204: set(('Content-Type', )),
304: {'Allow', 'Content-Encoding', 'Content-Language', 304: set(('Allow', 'Content-Encoding', 'Content-Language',
'Content-Length', 'Content-Range', 'Content-Type', 'Content-Md5', 'Content-Length', 'Content-Range', 'Content-Type',
'Last-Modified'} 'Content-Md5', 'Last-Modified'))
} }
def __init__(self, body='', status=None, headers=None, **more_headers): def __init__(self, body='', status=None, headers=None, **more_headers):
@ -1671,7 +1696,7 @@ class BaseResponse(object):
:param path: limits the cookie to a given path (default: current path) :param path: limits the cookie to a given path (default: current path)
:param secure: limit the cookie to HTTPS connections (default: off). :param secure: limit the cookie to HTTPS connections (default: off).
:param httponly: prevents client-side javascript to read this cookie :param httponly: prevents client-side javascript to read this cookie
(default: off). (default: off, requires Python 2.6 or newer).
If neither `expires` nor `max_age` is set (default), the cookie will If neither `expires` nor `max_age` is set (default), the cookie will
expire at the end of the browser session (as soon as the browser expire at the end of the browser session (as soon as the browser