9
9
:license: BSD, see LICENSE for more details.
10
10
"""
11
11
12
- from __future__ import with_statement
13
-
14
12
import os
15
13
import sys
16
14
from threading import Lock
36
34
_default_template_ctx_processor
37
35
from .signals import request_started , request_finished , got_request_exception , \
38
36
request_tearing_down , appcontext_tearing_down
37
+ from flask ._compat import reraise , string_types , integer_types
39
38
40
39
# a lock used for logger initialization
41
40
_logger_lock = Lock ()
@@ -585,21 +584,7 @@ def logger(self):
585
584
@locked_cached_property
586
585
def jinja_env (self ):
587
586
"""The Jinja2 environment used to load templates."""
588
- rv = self .create_jinja_environment ()
589
-
590
- # Hack to support the init_jinja_globals method which is supported
591
- # 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 warn
595
- 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' ] = rv
600
- self .init_jinja_globals ()
601
-
602
- return rv
587
+ return self .create_jinja_environment ()
603
588
604
589
@property
605
590
def got_first_request (self ):
@@ -1090,7 +1075,7 @@ def register_error_handler(self, code_or_exception, f):
1090
1075
def _register_error_handler (self , key , code_or_exception , f ):
1091
1076
if isinstance (code_or_exception , HTTPException ):
1092
1077
code_or_exception = code_or_exception .code
1093
- if isinstance (code_or_exception , ( int , long ) ):
1078
+ if isinstance (code_or_exception , integer_types ):
1094
1079
assert code_or_exception != 500 or key is None , \
1095
1080
'It is currently not possible to register a 500 internal ' \
1096
1081
'server error on a per-blueprint level.'
@@ -1137,7 +1122,7 @@ def template_test(self, name=None):
1137
1122
def is_prime(n):
1138
1123
if n == 2:
1139
1124
return True
1140
- 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):
1141
1126
if n % i == 0:
1142
1127
return False
1143
1128
return True
@@ -1383,7 +1368,7 @@ def handle_user_exception(self, e):
1383
1368
if isinstance (e , typecheck ):
1384
1369
return handler (e )
1385
1370
1386
- raise exc_type , exc_value , tb
1371
+ reraise ( exc_type , exc_value , tb )
1387
1372
1388
1373
def handle_exception (self , e ):
1389
1374
"""Default exception handling that kicks in when an exception
@@ -1405,7 +1390,7 @@ def handle_exception(self, e):
1405
1390
# (the function was actually called from the except part)
1406
1391
# otherwise, we just raise the error again
1407
1392
if exc_value is e :
1408
- raise exc_type , exc_value , tb
1393
+ reraise ( exc_type , exc_value , tb )
1409
1394
else :
1410
1395
raise e
1411
1396
@@ -1565,14 +1550,14 @@ def make_response(self, rv):
1565
1550
# set the headers and status. We do this because there can be
1566
1551
# some extra logic involved when creating these objects with
1567
1552
# specific values (like defualt content type selection).
1568
- if isinstance (rv , basestring ):
1553
+ if isinstance (rv , string_types ):
1569
1554
rv = self .response_class (rv , headers = headers , status = status )
1570
1555
headers = status = None
1571
1556
else :
1572
1557
rv = self .response_class .force_type (rv , request .environ )
1573
1558
1574
1559
if status is not None :
1575
- if isinstance (status , basestring ):
1560
+ if isinstance (status , string_types ):
1576
1561
rv .status = status
1577
1562
else :
1578
1563
rv .status_code = status
@@ -1633,7 +1618,7 @@ def handle_url_build_error(self, error, endpoint, values):
1633
1618
# still the same one we can reraise it with the original traceback,
1634
1619
# otherwise we raise it from here.
1635
1620
if error is exc_value :
1636
- raise exc_type , exc_value , tb
1621
+ reraise ( exc_type , exc_value , tb )
1637
1622
raise error
1638
1623
1639
1624
def preprocess_request (self ):
0 commit comments