Skip to content
Myr

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

24 files+36 added−87 removed

modified:examples/flaskr/flaskr.py+1 added-1 removed
7 unmodified lines
89 :copyright: (c) 2010 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""12from __future__ import with_statement1213from sqlite3 import dbapi2 as sqlite314from flask import Flask, request, session, g, redirect, url_for, abort, \15 render_template, flash, _app_ctx_stack16
88 unmodified lines
modified:examples/minitwit/minitwit.py+1 added-1 removed
6 unmodified lines
78 :copyright: (c) 2010 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11from __future__ import with_statement1112import time13from sqlite3 import dbapi2 as sqlite314from hashlib import md515from datetime import datetime
240 unmodified lines
modified:flask/testsuite/__init__.py+2 added-3 removed
9 unmodified lines
10 :license: BSD, see LICENSE for more details.11"""1213from __future__ import print_function14from __future__ import with_statement1415import os16import sys17import flask18import warnings19import unittest21from StringIO import StringIO20from functools import update_wrapper21from contextlib import contextmanager22from werkzeug.utils import import_string, find_modules23from flask._compat import reraise, StringIO242526def add_to_path(path):27 """Adds an entry to sys.path if it's not already there. This does
129 unmodified lines
157 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 True163164165class BetterLoader(unittest.TestLoader):
59 unmodified lines
modified:flask/testsuite/appctx.py-2 removed
7 unmodified lines
8 :copyright: (c) 2012 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import flask13import unittest14from flask.testsuite import FlaskTestCase15
85 unmodified lines
modified:flask/testsuite/basic.py+1 added-3 removed
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import re13import uuid14import flask15import pickle
1041 unmodified lines
1057 def fail_func():1058 1/010591060 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')10641065 self.assert_(flask._request_ctx_stack.top is not None)
86 unmodified lines
modified:flask/testsuite/blueprints.py-2 removed
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import flask13import unittest14import warnings15from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning
750 unmodified lines
modified:flask/testsuite/config.py-1 removed
6 unmodified lines
78 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11from __future__ import with_statement1112import os13import sys14import flask
285 unmodified lines
modified:flask/testsuite/deprecations.py+1 added-18 removed
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import flask13import unittest14from flask.testsuite import FlaskTestCase, catch_warnings151617class DeprecationsTestCase(FlaskTestCase):18 """not used currently"""1921 def test_init_jinja_globals(self):22 class MyFlask(flask.Flask):23 def init_jinja_globals(self):24 self.jinja_env.globals['foo'] = '42'2026 with catch_warnings() as log:27 app = MyFlask(__name__)28 @app.route('/')29 def foo():30 return app.jinja_env.globals['foo']3132 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']))363721def suite():22 suite = unittest.TestSuite()23 suite.addTest(unittest.makeSuite(DeprecationsTestCase))24 return suite
modified:flask/testsuite/ext.py+2 added-3 removed
6 unmodified lines
78 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11from __future__ import with_statement1112import sys13import unittest14from flask.testsuite import FlaskTestCase
5 unmodified lines
20 # 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 lines
98 from flask.ext.oldext_package.submodule import test_function99 self.assert_equal(test_function(), 42)100101 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.broken105106 def test_no_error_swallowing(self):
16 unmodified lines
modified:flask/testsuite/helpers.py+1 added-3 removed
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import os13import flask14import unittest15from logging import StreamHandler18from StringIO import StringIO16from flask.testsuite import FlaskTestCase, catch_warnings, catch_stderr17from werkzeug.http import parse_cache_control_header, parse_options_header18import six19from flask._compat import StringIO202122def has_encoding(name):23 try:
509 unmodified lines
modified:flask/testsuite/regression.py+1 added-3 removed
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import os13import gc14import sys15import flask
58 unmodified lines
74 # 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()8081 def test_safe_join_toplevel_pardir(self):82 from flask.helpers import safe_join
34 unmodified lines
modified:flask/testsuite/reqctx.py-2 removed
7 unmodified lines
8 :copyright: (c) 2012 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import flask13import unittest14try:15 from greenlet import greenlet
170 unmodified lines
modified:flask/testsuite/signals.py-1 removed
6 unmodified lines
78 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11from __future__ import with_statement1112import flask13import unittest14from flask.testsuite import FlaskTestCase
115 unmodified lines
modified:flask/testsuite/subclassing.py+1 added-1 removed
9 unmodified lines
10 :license: BSD, see LICENSE for more details.11"""12import flask13import unittest14from StringIO import StringIO14from logging import StreamHandler15from flask.testsuite import FlaskTestCase16from flask._compat import StringIO171819class FlaskSubclassingTestCase(FlaskTestCase):20
26 unmodified lines
modified:flask/testsuite/templating.py-2 removed
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import flask13import unittest14from flask.testsuite import FlaskTestCase15
287 unmodified lines
modified:flask/testsuite/testing.py-2 removed
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import flask13import unittest14from flask.testsuite import FlaskTestCase15import six
227 unmodified lines
modified:flask/testsuite/views.py+1 added-1 removed
6 unmodified lines
78 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11from __future__ import with_statement1112import flask13import flask.views14import unittest15from flask.testsuite import FlaskTestCase
154 unmodified lines
modified:flask/_compat.py+6 added
20 unmodified lines
21 unichr = chr22 range_type = range23 text_type = str24 string_types = (str,)25 integer_types = (int, )2627 iterkeys = lambda d: iter(d.keys())28 itervalues = lambda d: iter(d.values())29 iteritems = lambda d: iter(d.items())
16 unmodified lines
46 implements_to_string = _identity47 encode_filename = _identity48 get_next = lambda x: x.__next__4950 from urllib.parse import urlparse5152else:53 unichr = unichr54 text_type = unicode55 range_type = xrange56 string_types = (str, unicode)57 integer_types = (int, long)5859 iterkeys = lambda d: d.iterkeys()60 itervalues = lambda d: d.itervalues()61 iteritems = lambda d: d.iteritems()
23 unmodified lines
85 if isinstance(filename, unicode):86 return filename.encode('utf-8')87 return filename8889 from urlparse import urlparse909192def 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 checks
20 unmodified lines
modified:flask/app.py+9 added-24 removed
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import os13import sys14from threading import Lock15from datetime import timedelta
17 unmodified lines
33from .templating import DispatchingJinjaLoader, Environment, \34 _default_template_ctx_processor35from .signals import request_started, request_finished, got_request_exception, \36 request_tearing_down, appcontext_tearing_down37from flask._compat import reraise, string_types, integer_types3839# a lock used for logger initialization40_logger_lock = Lock()41
541 unmodified lines
583584 @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()588590 # 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()601602 return rv603589 @property590 def got_first_request(self):591 """This attribute is set to `True` if the application started592 handling the first request.
481 unmodified lines
1074 @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] = f
38 unmodified lines
1121 @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 lines
1367 for typecheck, handler in chain(blueprint_handlers, app_handlers):1368 if isinstance(e, typecheck):1369 return handler(e)13701386 raise exc_type, exc_value, tb1371 reraise(exc_type, exc_value, tb)13721373 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 will
13 unmodified lines
1389 # 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 e13961397 self.log_exception((exc_type, exc_value, tb))
151 unmodified lines
1549 # 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)15581559 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 lines
1617 # 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 error16231624 def preprocess_request(self):1625 """Called before the actual request dispatching and will
189 unmodified lines
modified:flask/config.py+2 added-3 removed
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import imp13import os14import errno1516from werkzeug.utils import import_string17from flask._compat import string_types181920class ConfigAttribute(object):21 """Makes an attribute forward to the config"""
134 unmodified lines
156 package because the package might be installed system wide.157158 :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 lines
modified:flask/exthook.py+2 added-1 removed
19 unmodified lines
20 :license: BSD, see LICENSE for more details.21"""22import sys23import os24from flask._compat import reraise252627class ExtensionImporter(object):28 """This importer redirects imports from this submodule to other locations.
48 unmodified lines
77 # 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 lines
modified:flask/helpers.py+4 added-5 removed
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import os13import sys14import pkgutil15import posixpath
8 unmodified lines
2425from werkzeug.datastructures import Headers26from werkzeug.exceptions import NotFound27import six28from flask._compat import string_types, text_type2930# this was moved in 0.731try:32 from werkzeug.wsgi import wrap_file
432 unmodified lines
465 :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 warn
2 unmodified lines
476477 # 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 lines
538 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 lines
modified:flask/testing.py+1 added-3 removed
8 unmodified lines
9 :copyright: (c) 2011 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""1213from __future__ import with_statement1413from contextlib import contextmanager14from werkzeug.test import Client, EnvironBuilder15from flask import _request_ctx_stack18from urlparse import urlparse16from flask._compat import urlparse171819def 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 lines
modified:scripts/flaskext_test.py-2 removed
7 unmodified lines
8 :copyright: (c) 2010 by Ali Afshar.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1312import os13import sys14import shutil15import urllib2
294 unmodified lines