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:
"""
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:
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
: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 = {
: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
>>> 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('__')