Browse Source

Merge branch 'six' of github.com:ThomasWaldmann/flask into ThomasWaldmann-six

Conflicts:
	flask/testsuite/__init__.py
pull/736/head
Daniel Neuhäuser 12 years ago
parent
commit
8494574fdf
  1. 13
      flask/_compat.py
  2. 3
      flask/helpers.py
  3. 3
      flask/json.py
  4. 9
      flask/sessions.py
  5. 5
      flask/templating.py
  6. 3
      flask/testsuite/__init__.py
  7. 3
      flask/testsuite/basic.py
  8. 3
      flask/testsuite/blueprints.py
  9. 2
      flask/testsuite/config.py
  10. 4
      flask/testsuite/ext.py
  11. 9
      flask/testsuite/helpers.py
  12. 3
      flask/testsuite/testing.py
  13. 1
      setup.py

13
flask/_compat.py

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
"""
flask._compat
~~~~~~~~~~~~~
Some py2/py3 compatibility support that is not yet available in
"six" 1.3.0.
There are bugs open for "six" for all this stuff, so we can remove it
again from here as soon as we require a new enough "six" release.
:copyright: (c) 2013 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""

3
flask/helpers.py

@ -26,6 +26,7 @@ from functools import update_wrapper
from werkzeug.datastructures import Headers from werkzeug.datastructures import Headers
from werkzeug.exceptions import NotFound from werkzeug.exceptions import NotFound
import six
# this was moved in 0.7 # this was moved in 0.7
try: try:
@ -128,7 +129,7 @@ def stream_with_context(generator_or_function):
# pushed. This item is discarded. Then when the iteration continues the # pushed. This item is discarded. Then when the iteration continues the
# real generator is executed. # real generator is executed.
wrapped_g = generator() wrapped_g = generator()
wrapped_g.next() six.advance_iterator(wrapped_g)
return wrapped_g return wrapped_g

3
flask/json.py

@ -17,6 +17,7 @@ from werkzeug.http import http_date
# Use the same json implementation as itsdangerous on which we # Use the same json implementation as itsdangerous on which we
# depend anyways. # depend anyways.
from itsdangerous import simplejson as _json from itsdangerous import simplejson as _json
import six
# figure out if simplejson escapes slashes. This behavior was changed # figure out if simplejson escapes slashes. This behavior was changed
@ -59,7 +60,7 @@ class JSONEncoder(_json.JSONEncoder):
if isinstance(o, uuid.UUID): if isinstance(o, uuid.UUID):
return str(o) return str(o)
if hasattr(o, '__html__'): if hasattr(o, '__html__'):
return unicode(o.__html__()) return six.text_type(o.__html__())
return _json.JSONEncoder.default(self, o) return _json.JSONEncoder.default(self, o)

9
flask/sessions.py

@ -17,6 +17,7 @@ from werkzeug.datastructures import CallbackDict
from . import Markup, json from . import Markup, json
from itsdangerous import URLSafeTimedSerializer, BadSignature from itsdangerous import URLSafeTimedSerializer, BadSignature
import six
def total_seconds(td): def total_seconds(td):
@ -62,16 +63,16 @@ class TaggedJSONSerializer(object):
elif isinstance(value, uuid.UUID): elif isinstance(value, uuid.UUID):
return {' u': value.hex} return {' u': value.hex}
elif callable(getattr(value, '__html__', None)): elif callable(getattr(value, '__html__', None)):
return {' m': unicode(value.__html__())} return {' m': six.text_type(value.__html__())}
elif isinstance(value, list): elif isinstance(value, list):
return [_tag(x) for x in value] return [_tag(x) for x in value]
elif isinstance(value, datetime): elif isinstance(value, datetime):
return {' d': http_date(value)} return {' d': http_date(value)}
elif isinstance(value, dict): elif isinstance(value, dict):
return dict((k, _tag(v)) for k, v in value.iteritems()) return dict((k, _tag(v)) for k, v in six.iteritems(value))
elif isinstance(value, str): elif isinstance(value, str):
try: try:
return unicode(value) return six.text_type(value)
except UnicodeError: except UnicodeError:
raise UnexpectedUnicodeError(u'A byte string with ' raise UnexpectedUnicodeError(u'A byte string with '
u'non-ASCII data was passed to the session system ' u'non-ASCII data was passed to the session system '
@ -84,7 +85,7 @@ class TaggedJSONSerializer(object):
def object_hook(obj): def object_hook(obj):
if len(obj) != 1: if len(obj) != 1:
return obj return obj
the_key, the_value = obj.iteritems().next() the_key, the_value = six.advance_iterator(obj.iteritems())
if the_key == ' t': if the_key == ' t':
return tuple(the_value) return tuple(the_value)
elif the_key == ' u': elif the_key == ' u':

5
flask/templating.py

@ -15,6 +15,7 @@ from jinja2 import BaseLoader, Environment as BaseEnvironment, \
from .globals import _request_ctx_stack, _app_ctx_stack from .globals import _request_ctx_stack, _app_ctx_stack
from .signals import template_rendered from .signals import template_rendered
from .module import blueprint_is_module from .module import blueprint_is_module
import six
def _default_template_ctx_processor(): def _default_template_ctx_processor():
@ -79,7 +80,7 @@ class DispatchingJinjaLoader(BaseLoader):
except (ValueError, KeyError): except (ValueError, KeyError):
pass pass
for blueprint in self.app.blueprints.itervalues(): for blueprint in six.itervalues(self.app.blueprints):
if blueprint_is_module(blueprint): if blueprint_is_module(blueprint):
continue continue
loader = blueprint.jinja_loader loader = blueprint.jinja_loader
@ -92,7 +93,7 @@ class DispatchingJinjaLoader(BaseLoader):
if loader is not None: if loader is not None:
result.update(loader.list_templates()) result.update(loader.list_templates())
for name, blueprint in self.app.blueprints.iteritems(): for name, blueprint in six.iteritems(self.app.blueprints):
loader = blueprint.jinja_loader loader = blueprint.jinja_loader
if loader is not None: if loader is not None:
for template in loader.list_templates(): for template in loader.list_templates():

3
flask/testsuite/__init__.py

@ -10,6 +10,7 @@
:license: BSD, see LICENSE for more details. :license: BSD, see LICENSE for more details.
""" """
from __future__ import print_function
from __future__ import with_statement from __future__ import with_statement
import os import os
@ -221,4 +222,4 @@ def main():
try: try:
unittest.main(testLoader=BetterLoader(), defaultTest='suite') unittest.main(testLoader=BetterLoader(), defaultTest='suite')
except Exception as e: except Exception as e:
print 'Error: %s' % e print('Error: %s' % e)

3
flask/testsuite/basic.py

@ -22,6 +22,7 @@ from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning
from werkzeug.exceptions import BadRequest, NotFound from werkzeug.exceptions import BadRequest, NotFound
from werkzeug.http import parse_date from werkzeug.http import parse_date
from werkzeug.routing import BuildError from werkzeug.routing import BuildError
import six
class BasicFunctionalityTestCase(FlaskTestCase): class BasicFunctionalityTestCase(FlaskTestCase):
@ -277,7 +278,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
@app.route('/test') @app.route('/test')
def test(): def test():
return unicode(flask.session.permanent) return six.text_type(flask.session.permanent)
client = app.test_client() client = app.test_client()
rv = client.get('/') rv = client.get('/')

3
flask/testsuite/blueprints.py

@ -18,6 +18,7 @@ from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning
from werkzeug.exceptions import NotFound from werkzeug.exceptions import NotFound
from werkzeug.http import parse_cache_control_header from werkzeug.http import parse_cache_control_header
from jinja2 import TemplateNotFound from jinja2 import TemplateNotFound
import six
# import moduleapp here because it uses deprecated features and we don't # import moduleapp here because it uses deprecated features and we don't
@ -304,7 +305,7 @@ class BlueprintTestCase(FlaskTestCase):
@bp.route('/bar') @bp.route('/bar')
def bar(bar): def bar(bar):
return unicode(bar) return six.text_type(bar)
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.register_blueprint(bp, url_prefix='/1', url_defaults={'bar': 23}) app.register_blueprint(bp, url_prefix='/1', url_defaults={'bar': 23})

2
flask/testsuite/config.py

@ -113,7 +113,7 @@ class LimitedLoaderMockWrapper(object):
def __getattr__(self, name): def __getattr__(self, name):
if name in ('archive', 'get_filename'): if name in ('archive', 'get_filename'):
msg = 'Mocking a loader which does not have `%s.`' % name msg = 'Mocking a loader which does not have `%s.`' % name
raise AttributeError, msg raise AttributeError(msg)
return getattr(self.loader, name) return getattr(self.loader, name)

4
flask/testsuite/ext.py

@ -13,7 +13,7 @@ from __future__ import with_statement
import sys import sys
import unittest import unittest
from flask.testsuite import FlaskTestCase from flask.testsuite import FlaskTestCase
from six import reload_module
class ExtImportHookTestCase(FlaskTestCase): class ExtImportHookTestCase(FlaskTestCase):
@ -29,7 +29,7 @@ class ExtImportHookTestCase(FlaskTestCase):
entry == 'flaskext') and value is not None: entry == 'flaskext') and value is not None:
sys.modules.pop(entry, None) sys.modules.pop(entry, None)
from flask import ext from flask import ext
reload(ext) reload_module(ext)
# reloading must not add more hooks # reloading must not add more hooks
import_hooks = 0 import_hooks = 0

9
flask/testsuite/helpers.py

@ -18,6 +18,7 @@ from logging import StreamHandler
from StringIO import StringIO from StringIO import StringIO
from flask.testsuite import FlaskTestCase, catch_warnings, catch_stderr from flask.testsuite import FlaskTestCase, catch_warnings, catch_stderr
from werkzeug.http import parse_cache_control_header, parse_options_header from werkzeug.http import parse_cache_control_header, parse_options_header
import six
def has_encoding(name): def has_encoding(name):
@ -35,7 +36,7 @@ class JSONTestCase(FlaskTestCase):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@app.route('/json', methods=['POST']) @app.route('/json', methods=['POST'])
def return_json(): def return_json():
return unicode(flask.request.json) return six.text_type(flask.request.json)
c = app.test_client() c = app.test_client()
rv = c.post('/json', data='malformed', content_type='application/json') rv = c.post('/json', data='malformed', content_type='application/json')
self.assert_equal(rv.status_code, 400) self.assert_equal(rv.status_code, 400)
@ -44,7 +45,7 @@ class JSONTestCase(FlaskTestCase):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@app.route('/json', methods=['POST']) @app.route('/json', methods=['POST'])
def return_json(): def return_json():
return unicode(flask.request.json) return six.text_type(flask.request.json)
c = app.test_client() c = app.test_client()
rv = c.post('/json', data='malformed', content_type='application/json') rv = c.post('/json', data='malformed', content_type='application/json')
self.assert_equal(rv.status_code, 400) self.assert_equal(rv.status_code, 400)
@ -96,7 +97,7 @@ class JSONTestCase(FlaskTestCase):
app = flask.Flask(__name__) app = flask.Flask(__name__)
@app.route('/add', methods=['POST']) @app.route('/add', methods=['POST'])
def add(): def add():
return unicode(flask.request.json['a'] + flask.request.json['b']) return six.text_type(flask.request.json['a'] + flask.request.json['b'])
c = app.test_client() c = app.test_client()
rv = c.post('/add', data=flask.json.dumps({'a': 1, 'b': 2}), rv = c.post('/add', data=flask.json.dumps({'a': 1, 'b': 2}),
content_type='application/json') content_type='application/json')
@ -507,7 +508,7 @@ class StreamingTestCase(FlaskTestCase):
def close(self): def close(self):
called.append(42) called.append(42)
def next(self): def next(self):
return self._gen.next() return six.advance_iterator(self._gen)
@app.route('/') @app.route('/')
def index(): def index():
def generate(): def generate():

3
flask/testsuite/testing.py

@ -14,6 +14,7 @@ from __future__ import with_statement
import flask import flask
import unittest import unittest
from flask.testsuite import FlaskTestCase from flask.testsuite import FlaskTestCase
import six
class TestToolsTestCase(FlaskTestCase): class TestToolsTestCase(FlaskTestCase):
@ -85,7 +86,7 @@ class TestToolsTestCase(FlaskTestCase):
@app.route('/') @app.route('/')
def index(): def index():
return unicode(flask.session['foo']) return six.text_type(flask.session['foo'])
with app.test_client() as c: with app.test_client() as c:
with c.session_transaction() as sess: with c.session_transaction() as sess:

1
setup.py

@ -90,6 +90,7 @@ setup(
zip_safe=False, zip_safe=False,
platforms='any', platforms='any',
install_requires=[ install_requires=[
'six>=1.3.0',
'Werkzeug>=0.7', 'Werkzeug>=0.7',
'Jinja2>=2.4', 'Jinja2>=2.4',
'itsdangerous>=0.17' 'itsdangerous>=0.17'

Loading…
Cancel
Save