]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Removed duplication from types that was only necessary for IronPython
authorArmin Ronacher <armin.ronacher@active-4.com>
Mon, 20 May 2013 16:03:46 +0000 (17:03 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Mon, 20 May 2013 16:03:46 +0000 (17:03 +0100)
jinja2/_compat.py
jinja2/debug.py
jinja2/nodes.py
jinja2/sandbox.py

index aaf79b012e2dbb47c13707aeac83da154a878b82..f376777ccb394a2fd4c94e7709d15b2a8f8b287f 100644 (file)
@@ -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:
index 815cc18a4f8fd76e747835f24c1297a7d2264628..dc8a39825e652c1df9733d2ebce23398a5351756 100644 (file)
 """
 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
 
index 037fbe279c8824ed029312bf0fef0b41e97a4fba..aa75f27247fc1ddd9492f8f3c68013b121156bb0 100644 (file)
     :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 = {
index da479c1ba27847f5d33653825ef531d46c7b041b..0b6383a202585bc91010984215f86eba4065d158 100644 (file)
     :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('__')