__init__.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. """
  2. A selection of cross-compatible functions for Python 2 and 3.
  3. This module exports useful functions for 2/3 compatible code:
  4. * bind_method: binds functions to classes
  5. * ``native_str_to_bytes`` and ``bytes_to_native_str``
  6. * ``native_str``: always equal to the native platform string object (because
  7. this may be shadowed by imports from future.builtins)
  8. * lists: lrange(), lmap(), lzip(), lfilter()
  9. * iterable method compatibility:
  10. - iteritems, iterkeys, itervalues
  11. - viewitems, viewkeys, viewvalues
  12. These use the original method if available, otherwise they use items,
  13. keys, values.
  14. * types:
  15. * text_type: unicode in Python 2, str in Python 3
  16. * string_types: basestring in Python 2, str in Python 3
  17. * binary_type: str in Python 2, bytes in Python 3
  18. * integer_types: (int, long) in Python 2, int in Python 3
  19. * class_types: (type, types.ClassType) in Python 2, type in Python 3
  20. * bchr(c):
  21. Take an integer and make a 1-character byte string
  22. * bord(c)
  23. Take the result of indexing on a byte string and make an integer
  24. * tobytes(s)
  25. Take a text string, a byte string, or a sequence of characters taken
  26. from a byte string, and make a byte string.
  27. * raise_from()
  28. * raise_with_traceback()
  29. This module also defines these decorators:
  30. * ``python_2_unicode_compatible``
  31. * ``with_metaclass``
  32. * ``implements_iterator``
  33. Some of the functions in this module come from the following sources:
  34. * Jinja2 (BSD licensed: see
  35. https://github.com/mitsuhiko/jinja2/blob/master/LICENSE)
  36. * Pandas compatibility module pandas.compat
  37. * six.py by Benjamin Peterson
  38. * Django
  39. """
  40. import types
  41. import sys
  42. import numbers
  43. import functools
  44. import copy
  45. import inspect
  46. PY3 = sys.version_info[0] >= 3
  47. PY34_PLUS = sys.version_info[0:2] >= (3, 4)
  48. PY35_PLUS = sys.version_info[0:2] >= (3, 5)
  49. PY36_PLUS = sys.version_info[0:2] >= (3, 6)
  50. PY2 = sys.version_info[0] == 2
  51. PY26 = sys.version_info[0:2] == (2, 6)
  52. PY27 = sys.version_info[0:2] == (2, 7)
  53. PYPY = hasattr(sys, 'pypy_translation_info')
  54. def python_2_unicode_compatible(cls):
  55. """
  56. A decorator that defines __unicode__ and __str__ methods under Python
  57. 2. Under Python 3, this decorator is a no-op.
  58. To support Python 2 and 3 with a single code base, define a __str__
  59. method returning unicode text and apply this decorator to the class, like
  60. this::
  61. >>> from future.utils import python_2_unicode_compatible
  62. >>> @python_2_unicode_compatible
  63. ... class MyClass(object):
  64. ... def __str__(self):
  65. ... return u'Unicode string: \u5b54\u5b50'
  66. >>> a = MyClass()
  67. Then, after this import:
  68. >>> from future.builtins import str
  69. the following is ``True`` on both Python 3 and 2::
  70. >>> str(a) == a.encode('utf-8').decode('utf-8')
  71. True
  72. and, on a Unicode-enabled terminal with the right fonts, these both print the
  73. Chinese characters for Confucius::
  74. >>> print(a)
  75. >>> print(str(a))
  76. The implementation comes from django.utils.encoding.
  77. """
  78. if not PY3:
  79. cls.__unicode__ = cls.__str__
  80. cls.__str__ = lambda self: self.__unicode__().encode('utf-8')
  81. return cls
  82. def with_metaclass(meta, *bases):
  83. """
  84. Function from jinja2/_compat.py. License: BSD.
  85. Use it like this::
  86. class BaseForm(object):
  87. pass
  88. class FormType(type):
  89. pass
  90. class Form(with_metaclass(FormType, BaseForm)):
  91. pass
  92. This requires a bit of explanation: the basic idea is to make a
  93. dummy metaclass for one level of class instantiation that replaces
  94. itself with the actual metaclass. Because of internal type checks
  95. we also need to make sure that we downgrade the custom metaclass
  96. for one level to something closer to type (that's why __call__ and
  97. __init__ comes back from type etc.).
  98. This has the advantage over six.with_metaclass of not introducing
  99. dummy classes into the final MRO.
  100. """
  101. class metaclass(meta):
  102. __call__ = type.__call__
  103. __init__ = type.__init__
  104. def __new__(cls, name, this_bases, d):
  105. if this_bases is None:
  106. return type.__new__(cls, name, (), d)
  107. return meta(name, bases, d)
  108. return metaclass('temporary_class', None, {})
  109. # Definitions from pandas.compat and six.py follow:
  110. if PY3:
  111. def bchr(s):
  112. return bytes([s])
  113. def bstr(s):
  114. if isinstance(s, str):
  115. return bytes(s, 'latin-1')
  116. else:
  117. return bytes(s)
  118. def bord(s):
  119. return s
  120. string_types = str,
  121. integer_types = int,
  122. class_types = type,
  123. text_type = str
  124. binary_type = bytes
  125. else:
  126. # Python 2
  127. def bchr(s):
  128. return chr(s)
  129. def bstr(s):
  130. return str(s)
  131. def bord(s):
  132. return ord(s)
  133. string_types = basestring,
  134. integer_types = (int, long)
  135. class_types = (type, types.ClassType)
  136. text_type = unicode
  137. binary_type = str
  138. ###
  139. if PY3:
  140. def tobytes(s):
  141. if isinstance(s, bytes):
  142. return s
  143. else:
  144. if isinstance(s, str):
  145. return s.encode('latin-1')
  146. else:
  147. return bytes(s)
  148. else:
  149. # Python 2
  150. def tobytes(s):
  151. if isinstance(s, unicode):
  152. return s.encode('latin-1')
  153. else:
  154. return ''.join(s)
  155. tobytes.__doc__ = """
  156. Encodes to latin-1 (where the first 256 chars are the same as
  157. ASCII.)
  158. """
  159. if PY3:
  160. def native_str_to_bytes(s, encoding='utf-8'):
  161. return s.encode(encoding)
  162. def bytes_to_native_str(b, encoding='utf-8'):
  163. return b.decode(encoding)
  164. def text_to_native_str(t, encoding=None):
  165. return t
  166. else:
  167. # Python 2
  168. def native_str_to_bytes(s, encoding=None):
  169. from future.types import newbytes # to avoid a circular import
  170. return newbytes(s)
  171. def bytes_to_native_str(b, encoding=None):
  172. return native(b)
  173. def text_to_native_str(t, encoding='ascii'):
  174. """
  175. Use this to create a Py2 native string when "from __future__ import
  176. unicode_literals" is in effect.
  177. """
  178. return unicode(t).encode(encoding)
  179. native_str_to_bytes.__doc__ = """
  180. On Py3, returns an encoded string.
  181. On Py2, returns a newbytes type, ignoring the ``encoding`` argument.
  182. """
  183. if PY3:
  184. # list-producing versions of the major Python iterating functions
  185. def lrange(*args, **kwargs):
  186. return list(range(*args, **kwargs))
  187. def lzip(*args, **kwargs):
  188. return list(zip(*args, **kwargs))
  189. def lmap(*args, **kwargs):
  190. return list(map(*args, **kwargs))
  191. def lfilter(*args, **kwargs):
  192. return list(filter(*args, **kwargs))
  193. else:
  194. import __builtin__
  195. # Python 2-builtin ranges produce lists
  196. lrange = __builtin__.range
  197. lzip = __builtin__.zip
  198. lmap = __builtin__.map
  199. lfilter = __builtin__.filter
  200. def isidentifier(s, dotted=False):
  201. '''
  202. A function equivalent to the str.isidentifier method on Py3
  203. '''
  204. if dotted:
  205. return all(isidentifier(a) for a in s.split('.'))
  206. if PY3:
  207. return s.isidentifier()
  208. else:
  209. import re
  210. _name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$")
  211. return bool(_name_re.match(s))
  212. def viewitems(obj, **kwargs):
  213. """
  214. Function for iterating over dictionary items with the same set-like
  215. behaviour on Py2.7 as on Py3.
  216. Passes kwargs to method."""
  217. func = getattr(obj, "viewitems", None)
  218. if not func:
  219. func = obj.items
  220. return func(**kwargs)
  221. def viewkeys(obj, **kwargs):
  222. """
  223. Function for iterating over dictionary keys with the same set-like
  224. behaviour on Py2.7 as on Py3.
  225. Passes kwargs to method."""
  226. func = getattr(obj, "viewkeys", None)
  227. if not func:
  228. func = obj.keys
  229. return func(**kwargs)
  230. def viewvalues(obj, **kwargs):
  231. """
  232. Function for iterating over dictionary values with the same set-like
  233. behaviour on Py2.7 as on Py3.
  234. Passes kwargs to method."""
  235. func = getattr(obj, "viewvalues", None)
  236. if not func:
  237. func = obj.values
  238. return func(**kwargs)
  239. def iteritems(obj, **kwargs):
  240. """Use this only if compatibility with Python versions before 2.7 is
  241. required. Otherwise, prefer viewitems().
  242. """
  243. func = getattr(obj, "iteritems", None)
  244. if not func:
  245. func = obj.items
  246. return func(**kwargs)
  247. def iterkeys(obj, **kwargs):
  248. """Use this only if compatibility with Python versions before 2.7 is
  249. required. Otherwise, prefer viewkeys().
  250. """
  251. func = getattr(obj, "iterkeys", None)
  252. if not func:
  253. func = obj.keys
  254. return func(**kwargs)
  255. def itervalues(obj, **kwargs):
  256. """Use this only if compatibility with Python versions before 2.7 is
  257. required. Otherwise, prefer viewvalues().
  258. """
  259. func = getattr(obj, "itervalues", None)
  260. if not func:
  261. func = obj.values
  262. return func(**kwargs)
  263. def bind_method(cls, name, func):
  264. """Bind a method to class, python 2 and python 3 compatible.
  265. Parameters
  266. ----------
  267. cls : type
  268. class to receive bound method
  269. name : basestring
  270. name of method on class instance
  271. func : function
  272. function to be bound as method
  273. Returns
  274. -------
  275. None
  276. """
  277. # only python 2 has an issue with bound/unbound methods
  278. if not PY3:
  279. setattr(cls, name, types.MethodType(func, None, cls))
  280. else:
  281. setattr(cls, name, func)
  282. def getexception():
  283. return sys.exc_info()[1]
  284. def _get_caller_globals_and_locals():
  285. """
  286. Returns the globals and locals of the calling frame.
  287. Is there an alternative to frame hacking here?
  288. """
  289. caller_frame = inspect.stack()[2]
  290. myglobals = caller_frame[0].f_globals
  291. mylocals = caller_frame[0].f_locals
  292. return myglobals, mylocals
  293. def _repr_strip(mystring):
  294. """
  295. Returns the string without any initial or final quotes.
  296. """
  297. r = repr(mystring)
  298. if r.startswith("'") and r.endswith("'"):
  299. return r[1:-1]
  300. else:
  301. return r
  302. if PY3:
  303. def raise_from(exc, cause):
  304. """
  305. Equivalent to:
  306. raise EXCEPTION from CAUSE
  307. on Python 3. (See PEP 3134).
  308. """
  309. myglobals, mylocals = _get_caller_globals_and_locals()
  310. # We pass the exception and cause along with other globals
  311. # when we exec():
  312. myglobals = myglobals.copy()
  313. myglobals['__python_future_raise_from_exc'] = exc
  314. myglobals['__python_future_raise_from_cause'] = cause
  315. execstr = "raise __python_future_raise_from_exc from __python_future_raise_from_cause"
  316. exec(execstr, myglobals, mylocals)
  317. def raise_(tp, value=None, tb=None):
  318. """
  319. A function that matches the Python 2.x ``raise`` statement. This
  320. allows re-raising exceptions with the cls value and traceback on
  321. Python 2 and 3.
  322. """
  323. if isinstance(tp, BaseException):
  324. # If the first object is an instance, the type of the exception
  325. # is the class of the instance, the instance itself is the value,
  326. # and the second object must be None.
  327. if value is not None:
  328. raise TypeError("instance exception may not have a separate value")
  329. exc = tp
  330. elif isinstance(tp, type) and not issubclass(tp, BaseException):
  331. # If the first object is a class, it becomes the type of the
  332. # exception.
  333. raise TypeError("class must derive from BaseException, not %s" % tp.__name__)
  334. else:
  335. # The second object is used to determine the exception value: If it
  336. # is an instance of the class, the instance becomes the exception
  337. # value. If the second object is a tuple, it is used as the argument
  338. # list for the class constructor; if it is None, an empty argument
  339. # list is used, and any other object is treated as a single argument
  340. # to the constructor. The instance so created by calling the
  341. # constructor is used as the exception value.
  342. if isinstance(value, tp):
  343. exc = value
  344. elif isinstance(value, tuple):
  345. exc = tp(*value)
  346. elif value is None:
  347. exc = tp()
  348. else:
  349. exc = tp(value)
  350. if exc.__traceback__ is not tb:
  351. raise exc.with_traceback(tb)
  352. raise exc
  353. def raise_with_traceback(exc, traceback=Ellipsis):
  354. if traceback == Ellipsis:
  355. _, _, traceback = sys.exc_info()
  356. raise exc.with_traceback(traceback)
  357. else:
  358. def raise_from(exc, cause):
  359. """
  360. Equivalent to:
  361. raise EXCEPTION from CAUSE
  362. on Python 3. (See PEP 3134).
  363. """
  364. # Is either arg an exception class (e.g. IndexError) rather than
  365. # instance (e.g. IndexError('my message here')? If so, pass the
  366. # name of the class undisturbed through to "raise ... from ...".
  367. if isinstance(exc, type) and issubclass(exc, Exception):
  368. e = exc()
  369. # exc = exc.__name__
  370. # execstr = "e = " + _repr_strip(exc) + "()"
  371. # myglobals, mylocals = _get_caller_globals_and_locals()
  372. # exec(execstr, myglobals, mylocals)
  373. else:
  374. e = exc
  375. e.__suppress_context__ = False
  376. if isinstance(cause, type) and issubclass(cause, Exception):
  377. e.__cause__ = cause()
  378. e.__cause__.__traceback__ = sys.exc_info()[2]
  379. e.__suppress_context__ = True
  380. elif cause is None:
  381. e.__cause__ = None
  382. e.__suppress_context__ = True
  383. elif isinstance(cause, BaseException):
  384. e.__cause__ = cause
  385. object.__setattr__(e.__cause__, '__traceback__', sys.exc_info()[2])
  386. e.__suppress_context__ = True
  387. else:
  388. raise TypeError("exception causes must derive from BaseException")
  389. e.__context__ = sys.exc_info()[1]
  390. raise e
  391. exec('''
  392. def raise_(tp, value=None, tb=None):
  393. raise tp, value, tb
  394. def raise_with_traceback(exc, traceback=Ellipsis):
  395. if traceback == Ellipsis:
  396. _, _, traceback = sys.exc_info()
  397. raise exc, None, traceback
  398. '''.strip())
  399. raise_with_traceback.__doc__ = (
  400. """Raise exception with existing traceback.
  401. If traceback is not passed, uses sys.exc_info() to get traceback."""
  402. )
  403. # Deprecated alias for backward compatibility with ``future`` versions < 0.11:
  404. reraise = raise_
  405. def implements_iterator(cls):
  406. '''
  407. From jinja2/_compat.py. License: BSD.
  408. Use as a decorator like this::
  409. @implements_iterator
  410. class UppercasingIterator(object):
  411. def __init__(self, iterable):
  412. self._iter = iter(iterable)
  413. def __iter__(self):
  414. return self
  415. def __next__(self):
  416. return next(self._iter).upper()
  417. '''
  418. if PY3:
  419. return cls
  420. else:
  421. cls.next = cls.__next__
  422. del cls.__next__
  423. return cls
  424. if PY3:
  425. get_next = lambda x: x.next
  426. else:
  427. get_next = lambda x: x.__next__
  428. def encode_filename(filename):
  429. if PY3:
  430. return filename
  431. else:
  432. if isinstance(filename, unicode):
  433. return filename.encode('utf-8')
  434. return filename
  435. def is_new_style(cls):
  436. """
  437. Python 2.7 has both new-style and old-style classes. Old-style classes can
  438. be pesky in some circumstances, such as when using inheritance. Use this
  439. function to test for whether a class is new-style. (Python 3 only has
  440. new-style classes.)
  441. """
  442. return hasattr(cls, '__class__') and ('__dict__' in dir(cls)
  443. or hasattr(cls, '__slots__'))
  444. # The native platform string and bytes types. Useful because ``str`` and
  445. # ``bytes`` are redefined on Py2 by ``from future.builtins import *``.
  446. native_str = str
  447. native_bytes = bytes
  448. def istext(obj):
  449. """
  450. Deprecated. Use::
  451. >>> isinstance(obj, str)
  452. after this import:
  453. >>> from future.builtins import str
  454. """
  455. return isinstance(obj, type(u''))
  456. def isbytes(obj):
  457. """
  458. Deprecated. Use::
  459. >>> isinstance(obj, bytes)
  460. after this import:
  461. >>> from future.builtins import bytes
  462. """
  463. return isinstance(obj, type(b''))
  464. def isnewbytes(obj):
  465. """
  466. Equivalent to the result of ``type(obj) == type(newbytes)``
  467. in other words, it is REALLY a newbytes instance, not a Py2 native str
  468. object?
  469. Note that this does not cover subclasses of newbytes, and it is not
  470. equivalent to ininstance(obj, newbytes)
  471. """
  472. return type(obj).__name__ == 'newbytes'
  473. def isint(obj):
  474. """
  475. Deprecated. Tests whether an object is a Py3 ``int`` or either a Py2 ``int`` or
  476. ``long``.
  477. Instead of using this function, you can use:
  478. >>> from future.builtins import int
  479. >>> isinstance(obj, int)
  480. The following idiom is equivalent:
  481. >>> from numbers import Integral
  482. >>> isinstance(obj, Integral)
  483. """
  484. return isinstance(obj, numbers.Integral)
  485. def native(obj):
  486. """
  487. On Py3, this is a no-op: native(obj) -> obj
  488. On Py2, returns the corresponding native Py2 types that are
  489. superclasses for backported objects from Py3:
  490. >>> from builtins import str, bytes, int
  491. >>> native(str(u'ABC'))
  492. u'ABC'
  493. >>> type(native(str(u'ABC')))
  494. unicode
  495. >>> native(bytes(b'ABC'))
  496. b'ABC'
  497. >>> type(native(bytes(b'ABC')))
  498. bytes
  499. >>> native(int(10**20))
  500. 100000000000000000000L
  501. >>> type(native(int(10**20)))
  502. long
  503. Existing native types on Py2 will be returned unchanged:
  504. >>> type(native(u'ABC'))
  505. unicode
  506. """
  507. if hasattr(obj, '__native__'):
  508. return obj.__native__()
  509. else:
  510. return obj
  511. # Implementation of exec_ is from ``six``:
  512. if PY3:
  513. import builtins
  514. exec_ = getattr(builtins, "exec")
  515. else:
  516. def exec_(code, globs=None, locs=None):
  517. """Execute code in a namespace."""
  518. if globs is None:
  519. frame = sys._getframe(1)
  520. globs = frame.f_globals
  521. if locs is None:
  522. locs = frame.f_locals
  523. del frame
  524. elif locs is None:
  525. locs = globs
  526. exec("""exec code in globs, locs""")
  527. # Defined here for backward compatibility:
  528. def old_div(a, b):
  529. """
  530. DEPRECATED: import ``old_div`` from ``past.utils`` instead.
  531. Equivalent to ``a / b`` on Python 2 without ``from __future__ import
  532. division``.
  533. TODO: generalize this to other objects (like arrays etc.)
  534. """
  535. if isinstance(a, numbers.Integral) and isinstance(b, numbers.Integral):
  536. return a // b
  537. else:
  538. return a / b
  539. def as_native_str(encoding='utf-8'):
  540. '''
  541. A decorator to turn a function or method call that returns text, i.e.
  542. unicode, into one that returns a native platform str.
  543. Use it as a decorator like this::
  544. from __future__ import unicode_literals
  545. class MyClass(object):
  546. @as_native_str(encoding='ascii')
  547. def __repr__(self):
  548. return next(self._iter).upper()
  549. '''
  550. if PY3:
  551. return lambda f: f
  552. else:
  553. def encoder(f):
  554. @functools.wraps(f)
  555. def wrapper(*args, **kwargs):
  556. return f(*args, **kwargs).encode(encoding=encoding)
  557. return wrapper
  558. return encoder
  559. # listvalues and listitems definitions from Nick Coghlan's (withdrawn)
  560. # PEP 496:
  561. try:
  562. dict.iteritems
  563. except AttributeError:
  564. # Python 3
  565. def listvalues(d):
  566. return list(d.values())
  567. def listitems(d):
  568. return list(d.items())
  569. else:
  570. # Python 2
  571. def listvalues(d):
  572. return d.values()
  573. def listitems(d):
  574. return d.items()
  575. if PY3:
  576. def ensure_new_type(obj):
  577. return obj
  578. else:
  579. def ensure_new_type(obj):
  580. from future.types.newbytes import newbytes
  581. from future.types.newstr import newstr
  582. from future.types.newint import newint
  583. from future.types.newdict import newdict
  584. native_type = type(native(obj))
  585. # Upcast only if the type is already a native (non-future) type
  586. if issubclass(native_type, type(obj)):
  587. # Upcast
  588. if native_type == str: # i.e. Py2 8-bit str
  589. return newbytes(obj)
  590. elif native_type == unicode:
  591. return newstr(obj)
  592. elif native_type == int:
  593. return newint(obj)
  594. elif native_type == long:
  595. return newint(obj)
  596. elif native_type == dict:
  597. return newdict(obj)
  598. else:
  599. return obj
  600. else:
  601. # Already a new type
  602. assert type(obj) in [newbytes, newstr]
  603. return obj
  604. __all__ = ['PY2', 'PY26', 'PY3', 'PYPY',
  605. 'as_native_str', 'binary_type', 'bind_method', 'bord', 'bstr',
  606. 'bytes_to_native_str', 'class_types', 'encode_filename',
  607. 'ensure_new_type', 'exec_', 'get_next', 'getexception',
  608. 'implements_iterator', 'integer_types', 'is_new_style', 'isbytes',
  609. 'isidentifier', 'isint', 'isnewbytes', 'istext', 'iteritems',
  610. 'iterkeys', 'itervalues', 'lfilter', 'listitems', 'listvalues',
  611. 'lmap', 'lrange', 'lzip', 'native', 'native_bytes', 'native_str',
  612. 'native_str_to_bytes', 'old_div',
  613. 'python_2_unicode_compatible', 'raise_',
  614. 'raise_with_traceback', 'reraise', 'string_types',
  615. 'text_to_native_str', 'text_type', 'tobytes', 'viewitems',
  616. 'viewkeys', 'viewvalues', 'with_metaclass'
  617. ]