ported some more stuff to py 3.3
Before adoption: this commit came in with the history the project adopted, so no landing records it.
removed init_jinja_globals hack from app.py after consulting mitsuhiko (didn't work on py 3.3 "as is") removed with_statement future imports, not needed any more needs more work on 2.7 as well as on 3.3
authored by Thomas Waldmann · committed by Thomas Waldmann · parent a503520 · Browse files · 24 files·+36 added−87 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
24 files+36 added−87 removed
- other:+36 added−87 removed
Provenance
- Commit
e1d356f- Tree
5b4942e- Author
Thomas Waldmann <tw@waldmann-edv.de>- Committer
Thomas Waldmann <tw@waldmann-edv.de>- Parent
a503520
24 files changed+36 added−87 removed
modified:examples/flaskr/flaskr.py+1 added-1 removed
7 unmodified lines8 9 :copyright: (c) 2010 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11 """12-from __future__ import with_statement12+13 from sqlite3 import dbapi2 as sqlite314 from flask import Flask, request, session, g, redirect, url_for, abort, \15 render_template, flash, _app_ctx_stack16 88 unmodified linesmodified:examples/minitwit/minitwit.py+1 added-1 removed
6 unmodified lines7 8 :copyright: (c) 2010 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11-from __future__ import with_statement11+12 import time13 from sqlite3 import dbapi2 as sqlite314 from hashlib import md515 from datetime import datetime240 unmodified linesmodified:flask/testsuite/__init__.py+2 added-3 removed
9 unmodified lines10 :license: BSD, see LICENSE for more details.11 """12 13 from __future__ import print_function14-from __future__ import with_statement14 15 import os16 import sys17 import flask18 import warnings19 import unittest21-from StringIO import StringIO20 from functools import update_wrapper21 from contextlib import contextmanager22 from werkzeug.utils import import_string, find_modules23+from flask._compat import reraise, StringIO24 25 26 def add_to_path(path):27 """Adds an entry to sys.path if it's not already there. This does129 unmodified lines157 if exc_type is None:158 self.test_case.fail('Expected exception of type %r' %159 exception_name)160 elif not issubclass(exc_type, self.exc_type):162- raise exc_type, exc_value, tb161+ reraise(exc_type, exc_value, tb)162 return True163 164 165 class BetterLoader(unittest.TestLoader):59 unmodified linesmodified:flask/testsuite/appctx.py-2 removed
7 unmodified lines8 :copyright: (c) 2012 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import flask13 import unittest14 from flask.testsuite import FlaskTestCase15 85 unmodified linesmodified:flask/testsuite/basic.py+1 added-3 removed
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import re13 import uuid14 import flask15 import pickle1041 unmodified lines1057 def fail_func():1058 1/01059 1060 c = app.test_client()1063- for x in xrange(3):1061+ for x in range(3):1062 with self.assert_raises(ZeroDivisionError):1063 c.get('/fail')1064 1065 self.assert_(flask._request_ctx_stack.top is not None)86 unmodified linesmodified:flask/testsuite/blueprints.py-2 removed
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import flask13 import unittest14 import warnings15 from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning750 unmodified linesmodified:flask/testsuite/config.py-1 removed
6 unmodified lines7 8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11-from __future__ import with_statement11 12 import os13 import sys14 import flask285 unmodified linesmodified:flask/testsuite/deprecations.py+1 added-18 removed
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import flask13 import unittest14 from flask.testsuite import FlaskTestCase, catch_warnings15 16 17 class DeprecationsTestCase(FlaskTestCase):18+ """not used currently"""19 21- def test_init_jinja_globals(self):22- class MyFlask(flask.Flask):23- def init_jinja_globals(self):24- self.jinja_env.globals['foo'] = '42'20 26- with catch_warnings() as log:27- app = MyFlask(__name__)28- @app.route('/')29- def foo():30- return app.jinja_env.globals['foo']31-32- c = app.test_client()33- self.assert_equal(c.get('/').data, '42')34- self.assert_equal(len(log), 1)35- self.assert_('init_jinja_globals' in str(log[0]['message']))36-37-21 def suite():22 suite = unittest.TestSuite()23 suite.addTest(unittest.makeSuite(DeprecationsTestCase))24 return suitemodified:flask/testsuite/ext.py+2 added-3 removed
6 unmodified lines7 8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11-from __future__ import with_statement11 12 import sys13 import unittest14 from flask.testsuite import FlaskTestCase5 unmodified lines20 # we clear this out for various reasons. The most important one is21 # that a real flaskext could be in there which would disable our22 # fake package. Secondly we want to make sure that the flaskext23 # import hook does not break on reloading.25- for entry, value in sys.modules.items():24+ for entry, value in list(sys.modules.items()):25 if (entry.startswith('flask.ext.') or26 entry.startswith('flask_') or27 entry.startswith('flaskext.') or28 entry == 'flaskext') and value is not None:69 unmodified lines98 from flask.ext.oldext_package.submodule import test_function99 self.assert_equal(test_function(), 42)100 101 def test_flaskext_broken_package_no_module_caching(self):103- for x in xrange(2):102+ for x in range(2):103 with self.assert_raises(ImportError):104 import flask.ext.broken105 106 def test_no_error_swallowing(self):16 unmodified linesmodified:flask/testsuite/helpers.py+1 added-3 removed
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import os13 import flask14 import unittest15 from logging import StreamHandler18-from StringIO import StringIO16 from flask.testsuite import FlaskTestCase, catch_warnings, catch_stderr17 from werkzeug.http import parse_cache_control_header, parse_options_header18 import six19+from flask._compat import StringIO20 21 22 def has_encoding(name):23 try:509 unmodified linesmodified:flask/testsuite/regression.py+1 added-3 removed
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import os13 import gc14 import sys15 import flask58 unmodified lines74 # This test only works on CPython 2.7.75 if sys.version_info >= (2, 7) and \76 not hasattr(sys, 'pypy_translation_info'):77 with self.assert_no_leak():80- for x in xrange(10):78+ for x in range(10):79 fire()80 81 def test_safe_join_toplevel_pardir(self):82 from flask.helpers import safe_join34 unmodified linesmodified:flask/testsuite/reqctx.py-2 removed
7 unmodified lines8 :copyright: (c) 2012 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import flask13 import unittest14 try:15 from greenlet import greenlet170 unmodified linesmodified:flask/testsuite/signals.py-1 removed
6 unmodified lines7 8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11-from __future__ import with_statement11 12 import flask13 import unittest14 from flask.testsuite import FlaskTestCase115 unmodified linesmodified:flask/testsuite/subclassing.py+1 added-1 removed
9 unmodified lines10 :license: BSD, see LICENSE for more details.11 """12 import flask13 import unittest14-from StringIO import StringIO14 from logging import StreamHandler15 from flask.testsuite import FlaskTestCase16+from flask._compat import StringIO17 18 19 class FlaskSubclassingTestCase(FlaskTestCase):20 26 unmodified linesmodified:flask/testsuite/templating.py-2 removed
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import flask13 import unittest14 from flask.testsuite import FlaskTestCase15 287 unmodified linesmodified:flask/testsuite/testing.py-2 removed
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import flask13 import unittest14 from flask.testsuite import FlaskTestCase15 import six227 unmodified linesmodified:flask/testsuite/views.py+1 added-1 removed
6 unmodified lines7 8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11-from __future__ import with_statement11+12 import flask13 import flask.views14 import unittest15 from flask.testsuite import FlaskTestCase154 unmodified linesmodified:flask/_compat.py+6 added
20 unmodified lines21 unichr = chr22 range_type = range23 text_type = str24 string_types = (str,)25+ integer_types = (int, )26 27 iterkeys = lambda d: iter(d.keys())28 itervalues = lambda d: iter(d.values())29 iteritems = lambda d: iter(d.items())16 unmodified lines46 implements_to_string = _identity47 encode_filename = _identity48 get_next = lambda x: x.__next__49 50+ from urllib.parse import urlparse51+52 else:53 unichr = unichr54 text_type = unicode55 range_type = xrange56 string_types = (str, unicode)57+ integer_types = (int, long)58 59 iterkeys = lambda d: d.iterkeys()60 itervalues = lambda d: d.itervalues()61 iteritems = lambda d: d.iteritems()23 unmodified lines85 if isinstance(filename, unicode):86 return filename.encode('utf-8')87 return filename88 89+ from urlparse import urlparse90 91+92 def with_metaclass(meta, *bases):93 # This requires a bit of explanation: the basic idea is to make a94 # dummy metaclass for one level of class instanciation that replaces95 # itself with the actual metaclass. Because of internal type checks20 unmodified linesmodified:flask/app.py+9 added-24 removed
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import os13 import sys14 from threading import Lock15 from datetime import timedelta17 unmodified lines33 from .templating import DispatchingJinjaLoader, Environment, \34 _default_template_ctx_processor35 from .signals import request_started, request_finished, got_request_exception, \36 request_tearing_down, appcontext_tearing_down37+from flask._compat import reraise, string_types, integer_types38 39 # a lock used for logger initialization40 _logger_lock = Lock()41 541 unmodified lines583 584 @locked_cached_property585 def jinja_env(self):586 """The Jinja2 environment used to load templates."""588- rv = self.create_jinja_environment()587+ return self.create_jinja_environment()588 590- # Hack to support the init_jinja_globals method which is supported591- # until 1.0 but has an API deficiency.592- if getattr(self.init_jinja_globals, 'im_func', None) is not \593- Flask.init_jinja_globals.__func__:594- from warnings import warn595- warn(DeprecationWarning('This flask class uses a customized '596- 'init_jinja_globals() method which is deprecated. '597- 'Move the code from that method into the '598- 'create_jinja_environment() method instead.'))599- self.__dict__['jinja_env'] = rv600- self.init_jinja_globals()601-602- return rv603-589 @property590 def got_first_request(self):591 """This attribute is set to `True` if the application started592 handling the first request.481 unmodified lines1074 @setupmethod1075 def _register_error_handler(self, key, code_or_exception, f):1076 if isinstance(code_or_exception, HTTPException):1077 code_or_exception = code_or_exception.code1093- if isinstance(code_or_exception, (int, long)):1078+ if isinstance(code_or_exception, integer_types):1079 assert code_or_exception != 500 or key is None, \1080 'It is currently not possible to register a 500 internal ' \1081 'server error on a per-blueprint level.'1082 self.error_handler_spec.setdefault(key, {})[code_or_exception] = f38 unmodified lines1121 @app.template_test()1122 def is_prime(n):1123 if n == 2:1124 return True1140- for i in xrange(2, int(math.ceil(math.sqrt(n))) + 1):1125+ for i in range(2, int(math.ceil(math.sqrt(n))) + 1):1126 if n % i == 0:1127 return False1128 return True1129 237 unmodified lines1367 for typecheck, handler in chain(blueprint_handlers, app_handlers):1368 if isinstance(e, typecheck):1369 return handler(e)1370 1386- raise exc_type, exc_value, tb1371+ reraise(exc_type, exc_value, tb)1372 1373 def handle_exception(self, e):1374 """Default exception handling that kicks in when an exception1375 occurs that is not caught. In debug mode the exception will13 unmodified lines1389 # raise it with the whole traceback in case we can do that1390 # (the function was actually called from the except part)1391 # otherwise, we just raise the error again1392 if exc_value is e:1408- raise exc_type, exc_value, tb1393+ reraise(exc_type, exc_value, tb)1394 else:1395 raise e1396 1397 self.log_exception((exc_type, exc_value, tb))151 unmodified lines1549 # When we create a response object directly, we let the constructor1550 # set the headers and status. We do this because there can be1551 # some extra logic involved when creating these objects with1552 # specific values (like defualt content type selection).1568- if isinstance(rv, basestring):1553+ if isinstance(rv, string_types):1554 rv = self.response_class(rv, headers=headers, status=status)1555 headers = status = None1556 else:1557 rv = self.response_class.force_type(rv, request.environ)1558 1559 if status is not None:1575- if isinstance(status, basestring):1560+ if isinstance(status, string_types):1561 rv.status = status1562 else:1563 rv.status_code = status1564 if headers:52 unmodified lines1617 # At this point we want to reraise the exception. If the error is1618 # still the same one we can reraise it with the original traceback,1619 # otherwise we raise it from here.1620 if error is exc_value:1636- raise exc_type, exc_value, tb1621+ reraise(exc_type, exc_value, tb)1622 raise error1623 1624 def preprocess_request(self):1625 """Called before the actual request dispatching and will189 unmodified linesmodified:flask/config.py+2 added-3 removed
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import imp13 import os14 import errno15 16 from werkzeug.utils import import_string17+from flask._compat import string_types18 19 20 class ConfigAttribute(object):21 """Makes an attribute forward to the config"""134 unmodified lines156 package because the package might be installed system wide.157 158 :param obj: an import name or object159 """161- if isinstance(obj, basestring):160+ if isinstance(obj, string_types):161 obj = import_string(obj)162 for key in dir(obj):163 if key.isupper():164 self[key] = getattr(obj, key)3 unmodified linesmodified:flask/exthook.py+2 added-1 removed
19 unmodified lines20 :license: BSD, see LICENSE for more details.21 """22 import sys23 import os24+from flask._compat import reraise25 26 27 class ExtensionImporter(object):28 """This importer redirects imports from this submodule to other locations.48 unmodified lines77 # If it's an important traceback we reraise it, otherwise78 # we swallow it and try the next choice. The skipped frame79 # is the one from __import__ above which we don't care about80 if self.is_important_traceback(realname, tb):80- raise exc_type, exc_value, tb.tb_next81+ reraise(exc_type, exc_value, tb.tb_next)82 continue83 module = sys.modules[fullname] = sys.modules[realname]84 if '.' not in modname:85 setattr(sys.modules[self.wrapper_module], modname, module)35 unmodified linesmodified:flask/helpers.py+4 added-5 removed
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import os13 import sys14 import pkgutil15 import posixpath8 unmodified lines24 25 from werkzeug.datastructures import Headers26 from werkzeug.exceptions import NotFound27 import six28+from flask._compat import string_types, text_type29 30 # this was moved in 0.731 try:32 from werkzeug.wsgi import wrap_file432 unmodified lines465 :meth:`~Flask.get_send_file_max_age` of466 :data:`~flask.current_app`.467 """468 mtime = None470- if isinstance(filename_or_fp, basestring):469+ if isinstance(filename_or_fp, string_types):470 filename = filename_or_fp471 file = None472 else:473 from warnings import warn2 unmodified lines476 477 # XXX: this behavior is now deprecated because it was unreliable.478 # removed in Flask 1.0479 if not attachment_filename and not mimetype \481- and isinstance(filename, basestring):480+ and isinstance(filename, string_types):481 warn(DeprecationWarning('The filename support for file objects '482 'passed to send_file is now deprecated. Pass an '483 'attach_filename if you want mimetypes to be guessed.'),484 stacklevel=2)53 unmodified lines538 rv.set_etag('flask-%s-%s-%s' % (539 os.path.getmtime(filename),540 os.path.getsize(filename),541 adler32(543- filename.encode('utf-8') if isinstance(filename, unicode)542+ filename.encode('utf-8') if isinstance(filename, text_type)543 else filename544 ) & 0xffffffff545 ))546 if conditional:299 unmodified linesmodified:flask/testing.py+1 added-3 removed
8 unmodified lines9 :copyright: (c) 2011 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11 """12 13-from __future__ import with_statement14-13 from contextlib import contextmanager14 from werkzeug.test import Client, EnvironBuilder15 from flask import _request_ctx_stack18-from urlparse import urlparse16+from flask._compat import urlparse17 18 19 def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs):20 """Creates a new test builder with some application defaults thrown in."""100 unmodified linesmodified:scripts/flaskext_test.py-2 removed
7 unmodified lines8 :copyright: (c) 2010 by Ali Afshar.9 :license: BSD, see LICENSE for more details.10 """11 12-from __future__ import with_statement13-12 import os13 import sys14 import shutil15 import urllib2294 unmodified lines