ó
âdc           @   s   d  Z  d d l Z d d l Z d d l m Z d d l m Z e Z e j	 d  Z
 d e f d     YZ d e e e  f d	     YZ d g Z d S(
   s  
A list subclass for Python 2 that behaves like Python 3's list.

The primary difference is that lists have a .copy() method in Py3.

Example use:

>>> from builtins import list
>>> l1 = list()    # instead of {} for an empty list
>>> l1.append('hello')
>>> l2 = l1.copy()

i˙˙˙˙N(   t   with_metaclass(   t	   newobjecti   t   BaseNewListc           B   s   e  Z d    Z RS(   c         C   s-   |  t  k r t | t  St | j |   Sd  S(   N(   t   newlistt
   isinstancet   _builtin_listt
   issubclasst	   __class__(   t   clst   instance(    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyt   __instancecheck__   s    (   t   __name__t
   __module__R
   (    (    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyR      s   R   c           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s7   
    A backport of the Python 3 list object to Py2
    c         C   s   t  j  |   S(   s9   
        L.copy() -> list -- a shallow copy of L
        (   t   copy(   t   self(    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyR   &   s    c         C   s+   x$ t  t |    D] } |  j   q Wd S(   s,   L.clear() -> None -- remove all items from LN(   t   ranget   lent   pop(   R   t   i(    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyt   clear,   s    c         O   sn   t  |  d k r( t t |   j |   St | d  t k rK | d } n
 | d } t t |   j |  |  S(   so   
        list() -> new empty list
        list(iterable) -> new list initialized from iterable's items
        i    (   R   t   superR   t   __new__t   type(   R   t   argst   kwargst   value(    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyR   1   s    
c         C   s   t  t t  |   j |   S(   N(   R   R   t   __add__(   R   R   (    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyR   ?   s    c         C   s!   y t  |  |  SWn t SXd S(   s    left + self N(   R   t   NotImplemented(   R   t   left(    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyt   __radd__B   s    c         C   sE   t  | t  r+ t t t |   j |   St t |   j |  Sd S(   s   
        x.__getitem__(y) <==> x[y]

        Warning: a bug in Python 2.x prevents indexing via a slice from
        returning a newlist object.
        N(   R   t   sliceR   R   t   __getitem__(   R   t   y(    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyR   I   s    c         C   s
   t  |   S(   s=   
        Hook for the future.utils.native() function
        (   t   list(   R   (    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyt
   __native__U   s    c         C   s   t  |   d k S(   Ni    (   R   (   R   (    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyt   __nonzero__[   s    (   R   R   t   __doc__R   R   R   R   R   R   R"   R#   (    (    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyR   "   s   							(   R$   t   sysR   t   future.utilsR    t   future.types.newobjectR   R!   R   t   version_infot   verR   R   R   t   __all__(    (    (    sb   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newlist.pyt   <module>   s   =                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      """
A pretty lame implementation of a memoryview object for Python 2.6.
"""

from collections import Iterable
from numbers import Integral
import string

from future.utils import istext, isbytes, PY3, with_metaclass
from future.types import no, issubset


# class BaseNewBytes(type):
#     def __instancecheck__(cls, instance):
#         return isinstance(instance, _builtin_bytes)


class newmemoryview(object):   # with_metaclass(BaseNewBytes, _builtin_bytes)):
    """
    A pretty lame backport of the Python 2.7 and Python 3.x
    memoryviewview object to Py2.6.
    """
    def __init__(self, obj):
        return obj


__all__ = ['newmemoryview']
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       """
An object subclass for Python 2 that gives new-style classes written in the
style of Python 3 (with ``__next__`` and unicode-returning ``__str__`` methods)
the appropriate Python 2-style ``next`` and ``__unicode__`` methods for compatible.

Example use::

    from builtins import object

    my_unicode_str = u'Unicode string: \u5b54\u5b50'

    class A(object):
        def __str__(self):
            return my_unicode_str

    a = A()
    print(str(a))
    
    # On Python 2, these relations hold:
    assert unicode(a) == my_unicode_string
    assert str(a) == my_unicode_string.encode('utf-8') 


Another example::

    from builtins import object

    class Upper(object):
        def __init__(self, iterable):
            self._iter = iter(iterable)
        def __next__(self):                 # note the Py3 interface
            return next(self._iter).upper()
        def __iter__(self):
            return self
    
    assert list(Upper('hello')) == list('HELLO')

"""

import sys

from future.utils import with_metaclass


_builtin_object = object
ver = sys.version_info[:2]


# We no longer define a metaclass for newobject because this breaks multiple
# inheritance and custom metaclass use with this exception:

# TypeError: Error when calling the metaclass bases
#     metaclass conflict: the metaclass of a derived class must be a
#     (non-strict) subclass of the metaclasses of all its bases

# See issues #91 and #96.


class newobject(object):
    """
    A magical object class that provides Python 2 compatibility methods::
        next
        __unicode__
        __nonzero__
    
    Subclasses of this class can merely define the Python 3 methods (__next__,
    __str__, and __bool__).
    """
    def next(self):
        if hasattr(self, '__next__'):
            return type(self).__next__(self)
        raise TypeError('newobject is not an iterator')
    
    def __unicode__(self):
        # All subclasses of the builtin object should have __str__ defined.
        # Note that old-style classes do not have __str__ defined.
        if hasattr(self, '__str__'):
            s = type(self).__str__(self)
        else:
            s = str(self)
        if isinstance(s, unicode):
            return s
        else:
            return s.decode('utf-8')

    def __nonzero__(self):
        if hasattr(self, '__bool__'):
            return type(self).__bool__(self)
        if hasattr(self, '__len__'):
            return type(self).__len__(self)
        # object has no __nonzero__ method
        return True

    # Are these ever needed?
    # def __div__(self):
    #     return self.__truediv__()

    # def __idiv__(self, other):
    #     return self.__itruediv__(other)

    def __long__(self):
        if not hasattr(self, '__int__'):
            return NotImplemented
        return self.__int__()  # not type(self).__int__(self)

    # def __new__(cls, *args, **kwargs):
    #     """
    #     dict() -> new empty dictionary
    #     dict(mapping) -> new dictionary initialized from a mapping object's
    #         (key, value) pairs
    #     dict(iterable) -> new dictionary initialized as if via:
    #         d = {}
    #         for k, v in iterable:
    #             d[k] = v
    #     dict(**kwargs) -> new dictionary initialized with the name=value pairs
    #         in the keyword argument list.  For example:  dict(one=1, two=2)
    #     """

    #     if len(args) == 0:
    #         return super(newdict, cls).__new__(cls)
    #     elif type(args[0]) == newdict:
    #         return args[0]
    #     else:
    #         value = args[0]
    #     return super(newdict, cls).__new__(cls, value)
        
    def __native__(self):
        """
        Hook for the future.utils.native() function
        """
        return object(self)


__all__ = ['newobject']
                                                                                                                                           