Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/jinja2/_compat.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
| author | bcclaywell |
|---|---|
| date | Mon, 12 Oct 2015 17:43:33 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d67268158946 |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 """ | |
| 3 jinja2._compat | |
| 4 ~~~~~~~~~~~~~~ | |
| 5 | |
| 6 Some py2/py3 compatibility support based on a stripped down | |
| 7 version of six so we don't have to depend on a specific version | |
| 8 of it. | |
| 9 | |
| 10 :copyright: Copyright 2013 by the Jinja team, see AUTHORS. | |
| 11 :license: BSD, see LICENSE for details. | |
| 12 """ | |
| 13 import sys | |
| 14 | |
| 15 PY2 = sys.version_info[0] == 2 | |
| 16 PYPY = hasattr(sys, 'pypy_translation_info') | |
| 17 _identity = lambda x: x | |
| 18 | |
| 19 | |
| 20 if not PY2: | |
| 21 unichr = chr | |
| 22 range_type = range | |
| 23 text_type = str | |
| 24 string_types = (str,) | |
| 25 integer_types = (int,) | |
| 26 | |
| 27 iterkeys = lambda d: iter(d.keys()) | |
| 28 itervalues = lambda d: iter(d.values()) | |
| 29 iteritems = lambda d: iter(d.items()) | |
| 30 | |
| 31 import pickle | |
| 32 from io import BytesIO, StringIO | |
| 33 NativeStringIO = StringIO | |
| 34 | |
| 35 def reraise(tp, value, tb=None): | |
| 36 if value.__traceback__ is not tb: | |
| 37 raise value.with_traceback(tb) | |
| 38 raise value | |
| 39 | |
| 40 ifilter = filter | |
| 41 imap = map | |
| 42 izip = zip | |
| 43 intern = sys.intern | |
| 44 | |
| 45 implements_iterator = _identity | |
| 46 implements_to_string = _identity | |
| 47 encode_filename = _identity | |
| 48 get_next = lambda x: x.__next__ | |
| 49 | |
| 50 else: | |
| 51 unichr = unichr | |
| 52 text_type = unicode | |
| 53 range_type = xrange | |
| 54 string_types = (str, unicode) | |
| 55 integer_types = (int, long) | |
| 56 | |
| 57 iterkeys = lambda d: d.iterkeys() | |
| 58 itervalues = lambda d: d.itervalues() | |
| 59 iteritems = lambda d: d.iteritems() | |
| 60 | |
| 61 import cPickle as pickle | |
| 62 from cStringIO import StringIO as BytesIO, StringIO | |
| 63 NativeStringIO = BytesIO | |
| 64 | |
| 65 exec('def reraise(tp, value, tb=None):\n raise tp, value, tb') | |
| 66 | |
| 67 from itertools import imap, izip, ifilter | |
| 68 intern = intern | |
| 69 | |
| 70 def implements_iterator(cls): | |
| 71 cls.next = cls.__next__ | |
| 72 del cls.__next__ | |
| 73 return cls | |
| 74 | |
| 75 def implements_to_string(cls): | |
| 76 cls.__unicode__ = cls.__str__ | |
| 77 cls.__str__ = lambda x: x.__unicode__().encode('utf-8') | |
| 78 return cls | |
| 79 | |
| 80 get_next = lambda x: x.next | |
| 81 | |
| 82 def encode_filename(filename): | |
| 83 if isinstance(filename, unicode): | |
| 84 return filename.encode('utf-8') | |
| 85 return filename | |
| 86 | |
| 87 | |
| 88 def with_metaclass(meta, *bases): | |
| 89 # This requires a bit of explanation: the basic idea is to make a | |
| 90 # dummy metaclass for one level of class instanciation that replaces | |
| 91 # itself with the actual metaclass. Because of internal type checks | |
| 92 # we also need to make sure that we downgrade the custom metaclass | |
| 93 # for one level to something closer to type (that's why __call__ and | |
| 94 # __init__ comes back from type etc.). | |
| 95 # | |
| 96 # This has the advantage over six.with_metaclass in that it does not | |
| 97 # introduce dummy classes into the final MRO. | |
| 98 class metaclass(meta): | |
| 99 __call__ = type.__call__ | |
| 100 __init__ = type.__init__ | |
| 101 def __new__(cls, name, this_bases, d): | |
| 102 if this_bases is None: | |
| 103 return type.__new__(cls, name, (), d) | |
| 104 return meta(name, bases, d) | |
| 105 return metaclass('temporary_class', None, {}) | |
| 106 | |
| 107 | |
| 108 try: | |
| 109 from urllib.parse import quote_from_bytes as url_quote | |
| 110 except ImportError: | |
| 111 from urllib import quote as url_quote |
