From: Armin Ronacher Date: Mon, 20 May 2013 16:03:46 +0000 (+0100) Subject: Removed duplication from types that was only necessary for IronPython X-Git-Tag: 2.8~116 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c5315a0b3f20c4c78c008d20b8d4fe12635f250;p=thirdparty%2Fjinja.git Removed duplication from types that was only necessary for IronPython --- diff --git a/jinja2/_compat.py b/jinja2/_compat.py index aaf79b01..f376777c 100644 --- a/jinja2/_compat.py +++ b/jinja2/_compat.py @@ -110,25 +110,6 @@ except ImportError: mapping_types = (UserDict.UserDict, UserDict.DictMixin, dict) -# common types. These do exist in the special types module too which however -# does not exist in IronPython out of the box. Also that way we don't have -# to deal with implementation specific stuff here -class _C(object): - def method(self): pass -def _func(): - yield None -function_type = type(_func) -generator_type = type(_func()) -method_type = type(_C().method) -code_type = type(_C.method.__code__) -try: - raise TypeError() -except TypeError: - _tb = sys.exc_info()[2] - traceback_type = type(_tb) - frame_type = type(_tb.tb_frame) - - try: from urllib.parse import quote_from_bytes as url_quote except ImportError: diff --git a/jinja2/debug.py b/jinja2/debug.py index 815cc18a..dc8a3982 100644 --- a/jinja2/debug.py +++ b/jinja2/debug.py @@ -12,10 +12,10 @@ """ import sys import traceback -from types import TracebackType +from types import TracebackType, CodeType from jinja2.utils import missing, internal_code from jinja2.exceptions import TemplateSyntaxError -from jinja2._compat import iteritems, reraise, code_type +from jinja2._compat import iteritems, reraise # on pypy we can take advantage of transparent proxies try: @@ -245,11 +245,11 @@ def fake_exc_info(exc_info, filename, lineno): location = 'block "%s"' % function[6:] else: location = 'template' - code = code_type(0, code.co_nlocals, code.co_stacksize, - code.co_flags, code.co_code, code.co_consts, - code.co_names, code.co_varnames, filename, - location, code.co_firstlineno, - code.co_lnotab, (), ()) + code = CodeType(0, code.co_nlocals, code.co_stacksize, + code.co_flags, code.co_code, code.co_consts, + code.co_names, code.co_varnames, filename, + location, code.co_firstlineno, + code.co_lnotab, (), ()) except: pass diff --git a/jinja2/nodes.py b/jinja2/nodes.py index 037fbe27..aa75f272 100644 --- a/jinja2/nodes.py +++ b/jinja2/nodes.py @@ -12,16 +12,16 @@ :copyright: (c) 2010 by the Jinja Team. :license: BSD, see LICENSE for more details. """ +import types import operator from collections import deque from jinja2.utils import Markup -from jinja2._compat import izip, with_metaclass, text_type, \ - method_type, function_type +from jinja2._compat import izip, with_metaclass, text_type #: the types we support for context functions -_context_function_types = (function_type, method_type) +_context_function_types = (types.FunctionType, types.MethodType) _binop_to_func = { diff --git a/jinja2/sandbox.py b/jinja2/sandbox.py index da479c1b..0b6383a2 100644 --- a/jinja2/sandbox.py +++ b/jinja2/sandbox.py @@ -12,11 +12,11 @@ :copyright: (c) 2010 by the Jinja Team. :license: BSD. """ +import types import operator from jinja2.environment import Environment from jinja2.exceptions import SecurityError -from jinja2._compat import string_types, function_type, method_type, \ - traceback_type, code_type, frame_type, generator_type, PY2 +from jinja2._compat import string_types, PY2 #: maximum number of items a range may produce @@ -131,19 +131,19 @@ def is_internal_attribute(obj, attr): >>> is_internal_attribute(str, "upper") False """ - if isinstance(obj, function_type): + if isinstance(obj, types.FunctionType): if attr in UNSAFE_FUNCTION_ATTRIBUTES: return True - elif isinstance(obj, method_type): + elif isinstance(obj, types.MethodType): if attr in UNSAFE_FUNCTION_ATTRIBUTES or \ attr in UNSAFE_METHOD_ATTRIBUTES: return True elif isinstance(obj, type): if attr == 'mro': return True - elif isinstance(obj, (code_type, traceback_type, frame_type)): + elif isinstance(obj, (types.CodeType, types.TracebackType, types.FrameType)): return True - elif isinstance(obj, generator_type): + elif isinstance(obj, types.GeneratorType): if attr in UNSAFE_GENERATOR_ATTRIBUTES: return True return attr.startswith('__')