Skip to content
Myr

Fixed various issues on the Python 3 port

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 8aaf302 · Browse files · 3 files+36 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+36 added−10 removed

  • other:+36 added−10 removed

3 files+36 added−10 removed

modified:flask/_compat.py-4 removed
45 unmodified lines
46 implements_to_string = _identity47 encode_filename = _identity48 get_next = lambda x: x.__next__4950 from urllib.parse import urlparse5150else:51 unichr = unichr52 text_type = unicode53 range_type = xrange
29 unmodified lines
83 if isinstance(filename, unicode):84 return filename.encode('utf-8')85 return filename8689 from urlparse import urlparse879188def with_metaclass(meta, *bases):89 # This requires a bit of explanation: the basic idea is to make a90 # dummy metaclass for one level of class instantiation that replaces91 # itself with the actual metaclass. Because of internal type checks
20 unmodified lines
modified:flask/json.py+30 added-4 removed
6 unmodified lines
78 :copyright: (c) 2012 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11import io12import uuid13from datetime import datetime14from .globals import current_app, request14from ._compat import text_type15from ._compat import text_type, PY21617from werkzeug.http import http_date1819# Use the same json implementation as itsdangerous on which we
13 unmodified lines
33 'htmlsafe_dumps', 'JSONDecoder', 'JSONEncoder',34 'jsonify']353637def _wrap_reader_for_text(fp, encoding):38 if isinstance(fp.read(0), bytes):39 fp = io.TextIOWrapper(io.BufferedReader(fp), encoding)40 return fp414243def _wrap_writer_for_text(fp, encoding):44 try:45 fp.write('')46 except TypeError:47 fp = io.TextIOWrapper(fp, encoding)48 return fp495051class JSONEncoder(_json.JSONEncoder):52 """The default Flask JSON encoder. This one extends the default simplejson53 encoder by also supporting ``datetime`` objects, ``UUID`` as well as54 ``Markup`` objects which are serialized as RFC 822 datetime strings (same
59 unmodified lines
114 default is controlled by the ``JSON_AS_ASCII`` configuration variable115 and can be overriden by the simplejson ``ensure_ascii`` parameter.116 """117 _dump_arg_defaults(kwargs)118 encoding = kwargs.pop('encoding', None)103 return _json.dumps(obj, **kwargs)119 rv = _json.dumps(obj, **kwargs)120 if encoding is not None and isinstance(rv, text_type):121 rv = rv.encode(encoding)122 return rv123124125def dump(obj, fp, **kwargs):126 """Like :func:`dumps` but writes into a file object."""127 _dump_arg_defaults(kwargs)128 encoding = kwargs.pop('encoding', None)129 if encoding is not None:130 fp = _wrap_writer_for_text(fp, encoding)109 return _json.dump(obj, fp, **kwargs)131 _json.dump(obj, fp, **kwargs)132133134def loads(s, **kwargs):135 """Unserialize a JSON object from a string ``s`` by using the application's136 configured decoder (:attr:`~flask.Flask.json_decoder`) if there is an137 application on the stack.138 """139 _load_arg_defaults(kwargs)140 if isinstance(s, bytes):141 s = s.decode(kwargs.pop('encoding', None) or 'utf-8')142 return _json.loads(s, **kwargs)143144145def load(fp, **kwargs):146 """Like :func:`loads` but reads from a file object.147 """148 _load_arg_defaults(kwargs)149 if not PY2:150 fp = _wrap_reader_for_text(fp, kwargs.pop('encoding', None) or 'utf-8')151 return _json.load(fp, **kwargs)152153154def htmlsafe_dumps(obj, **kwargs):
18 unmodified lines
173 the given arguments with an `application/json` mimetype. The arguments174 to this function are the same as to the :class:`dict` constructor.175176 Example usage::151 177178 from flask import jsonify179180 @app.route('/_get_current_user')181 def get_current_user():
20 unmodified lines
modified:flask/testing.py+6 added-2 removed
11 unmodified lines
1213from contextlib import contextmanager14from werkzeug.test import Client, EnvironBuilder15from flask import _request_ctx_stack16from ._compat import urlparse1617try:18 from werkzeug.urls import url_parse19except ImportError:20 from urlparse import urlsplit as url_parse212223def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs):24 """Creates a new test builder with some application defaults thrown in."""25 http_host = app.config.get('SERVER_NAME')26 app_root = app.config.get('APPLICATION_ROOT')27 if base_url is None:24 url = urlparse(path)28 url = url_parse(path)29 base_url = 'http://%s/' % (url.netloc or http_host or 'localhost')30 if app_root:31 base_url += app_root.lstrip('/')32 if url.netloc:
92 unmodified lines