# The MIT License (MIT)
#
# Copyright (c) 2018 Niklas Rosenstein
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import sys

PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
if not (PY2 or PY3):
  raise EnvironmentError('neither Python 2 or Python 3??')


def with_metaclass(metaclass):
  return metaclass('{}Temp'.format(metaclass.__name__), (object,), {})


if PY2:
  def iteritems(d):
    return d.iteritems()

  def iterkeys(d):
    return d.iterkeys()

  def itervalues(d):
    return d.itervalues()

  def can_iteritems(d):
    return hasattr(d, 'iteritems')

  def can_iterkeys(d):
    return hasattr(d, 'iterkeys')

  def can_itervalues(d):
    return hasattr(d, 'itervalues')

else:
  def iteritems(d):
    return d.items()

  def iterkeys(d):
    return d.keys()

  def itervalues(d):
    return d.values()

  def can_iteritems(d):
    return hasattr(d, 'items')

  def can_iterkeys(d):
    return hasattr(d, 'keys')

  def can_itervalues(d):
    return hasattr(d, 'valyes')

@@ -1384,16 +1384,50 @@
 if PY2:%0A
+  import __builtin__ as builtins%0A%0A
   def it
@@ -1740,13 +1740,332 @@
 ')%0A%0A
-else:
+  def exec_(code, globals=None, locals=None):%0A    if globals is None:%0A      frame = sys._getframe(1)%0A      globals = frame.f_globals%0A      if locals is None:%0A        locals = frame.f_locals%0A      del frame%0A    elif locals is None:%0A      locals = globals%0A    exec(%22%22%22exec code in globals, locals%22%22%22)%0A%0Aelse:%0A  import builtins%0A
 %0A  d
@@ -2350,12 +2350,28 @@
 , 'valyes')%0A
+%0A  exec_ = exec%0A

update nr.compat