ó
âdc           @   sÍ   d  Z  d d l m Z d d l Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 m Z m Z m Z m Z m Z e
 r‹ e Z n  d e f d „  ƒ  YZ d	 e e e ƒ f d
 „  ƒ  YZ d	 g Z d S(   s¨   
Backport of Python 3's int, based on Py2's long.

They are very similar. The most notable difference is:

- representation: trailing L in Python 2 removed in Python 3
iÿÿÿÿ(   t   divisionN(   t   newbytes(   t	   newobject(   t   PY3t   isintt   istextt   isbytest   with_metaclasst   nativet
   BaseNewIntc           B   s   e  Z d  „  Z RS(   c         C   s3   |  t  k r t | t t f ƒ St | j |  ƒ Sd  S(   N(   t   newintt
   isinstancet   intt   longt
   issubclasst	   __class__(   t   clst   instance(    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyt   __instancecheck__   s    (   t   __name__t
   __module__R   (    (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR	      s   R
   c           B   s|  e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d  „  Z  d! „  Z! d" „  Z" d# „  Z# d$ „  Z$ d% „  Z% d& „  Z& d' e' d( „ Z( e) d' e' d) „ ƒ Z* RS(*   s6   
    A backport of the Python 3 int object to Py2
    i    i
   c         C   si  y | j  ƒ  } Wn t k
 r) | } n+ Xt | ƒ sT t d j t | ƒ ƒ ƒ ‚ n  | d k rì t | ƒ p„ t | ƒ p„ t | t	 ƒ s– t d ƒ ‚ n  y  t
 t |  ƒ j |  | | ƒ SWqì t k
 rè t
 t |  ƒ j |  t | ƒ | ƒ SXn  y t
 t |  ƒ j |  | ƒ SWnY t k
 rdy# t
 t |  ƒ j |  t | ƒ ƒ SWqet d j t | ƒ ƒ ƒ ‚ qeXn Xd S(   s.  
        From the Py3 int docstring:

        |  int(x=0) -> integer
        |  int(x, base=10) -> integer
        |
        |  Convert a number or string to an integer, or return 0 if no
        |  arguments are given.  If x is a number, return x.__int__().  For
        |  floating point numbers, this truncates towards zero.
        |
        |  If x is not a number or if base is given, then x must be a string,
        |  bytes, or bytearray instance representing an integer literal in the
        |  given base.  The literal can be preceded by '+' or '-' and be
        |  surrounded by whitespace.  The base defaults to 10.  Valid bases are
        |  0 and 2-36. Base 0 means to interpret the base from the string as an
        |  integer literal.
        |  >>> int('0b100', base=0)
        |  4

        s   __int__ returned non-int ({0})i
   s1   int() can't convert non-string with explicit bases6   newint argument must be a string or a number,not '{0}'N(   t   __int__t   AttributeErrorR   t	   TypeErrort   formatt   typeR   R   R   t	   bytearrayt   superR
   t   __new__R   (   R   t   xt   baset   val(    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR   #   s.    
	' &#	c         C   s3   t  t |  ƒ j ƒ  } | d d k s+ t ‚ | d  S(   s&   
        Without the L suffix
        iÿÿÿÿt   L(   R   R
   t   __repr__t   AssertionError(   t   selft   value(    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR!   Y   s    c         C   s<   t  t |  ƒ j | ƒ } | t k r2 t |  ƒ | St | ƒ S(   N(   R   R
   t   __add__t   NotImplementedR   (   R#   t   otherR$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR%   a   s    c         C   s<   t  t |  ƒ j | ƒ } | t k r2 | t |  ƒ St | ƒ S(   N(   R   R
   t   __radd__R&   R   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR(   g   s    c         C   s<   t  t |  ƒ j | ƒ } | t k r2 t |  ƒ | St | ƒ S(   N(   R   R
   t   __sub__R&   R   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR)   m   s    c         C   s<   t  t |  ƒ j | ƒ } | t k r2 | t |  ƒ St | ƒ S(   N(   R   R
   t   __rsub__R&   R   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR*   s   s    c         C   sL   t  t |  ƒ j | ƒ } t | ƒ r. t | ƒ S| t k rH t |  ƒ | S| S(   N(   R   R
   t   __mul__R   R&   R   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR+   y   s    
c         C   sL   t  t |  ƒ j | ƒ } t | ƒ r. t | ƒ S| t k rH | t |  ƒ S| S(   N(   R   R
   t   __rmul__R   R&   R   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR,      s    
c         C   s7   t  |  ƒ | } t | t t  f ƒ r/ t | ƒ S| Sd  S(   N(   R   R   R   R
   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyt   __div__‰   s    
c         C   s7   | t  |  ƒ } t | t t  f ƒ r/ t | ƒ S| Sd  S(   N(   R   R   R   R
   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyt   __rdiv__“   s    
c         C   s6   |  j  | ƒ } t | t t f ƒ r. t | ƒ S| Sd  S(   N(   t   __itruediv__R   R   R   R
   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyt   __idiv__š   s    
c         C   s;   t  t |  ƒ j | ƒ } | t k r7 t |  ƒ | } n  | S(   N(   R   R
   t   __truediv__R&   R   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR1   £   s    c         C   s   t  t |  ƒ j | ƒ S(   N(   R   R
   t   __rtruediv__(   R#   R'   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR2   ©   s    c         C   s   t  |  ƒ } | | } | S(   N(   R   (   R#   R'   t   mylong(    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR/   ¬   s    
c         C   s   t  t t  |  ƒ j | ƒ ƒ S(   N(   R
   R   t   __floordiv__(   R#   R'   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR4   ²   s    c         C   s   t  t t  |  ƒ j | ƒ ƒ S(   N(   R
   R   t   __rfloordiv__(   R#   R'   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR5   µ   s    c         C   s    t  |  ƒ } | | } t | ƒ S(   N(   R   R
   (   R#   R'   R3   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyt   __ifloordiv__¸   s    
c         C   s<   t  t |  ƒ j | ƒ } | t k r2 t |  ƒ | St | ƒ S(   N(   R   R
   t   __mod__R&   R   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR7   ¾   s    c         C   s<   t  t |  ƒ j | ƒ } | t k r2 | t |  ƒ St | ƒ S(   N(   R   R
   t   __rmod__R&   R   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR8   Ä   s    c         C   s`   t  t |  ƒ j | ƒ } | t k rB t |  ƒ } | | | | f St | d ƒ t | d ƒ f S(   Ni    i   (   R   R
   t
   __divmod__R&   R   (   R#   R'   R$   R3   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR9   Ê   s
    c         C   s`   t  t |  ƒ j | ƒ } | t k rB t |  ƒ } | | | | f St | d ƒ t | d ƒ f S(   Ni    i   (   R   R
   t   __rdivmod__R&   R   (   R#   R'   R$   R3   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR:   Ñ   s
    c         C   s<   t  t |  ƒ j | ƒ } | t k r2 t |  ƒ | St | ƒ S(   N(   R   R
   t   __pow__R&   R   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR;   Ø   s    c         C   s<   t  t |  ƒ j | ƒ } | t k r2 | t |  ƒ St | ƒ S(   N(   R   R
   t   __rpow__R&   R   (   R#   R'   R$   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR<   Þ   s    c         C   sS   t  | ƒ s7 t d t |  ƒ j t | ƒ j f ƒ ‚ n  t t t |  ƒ j | ƒ ƒ S(   Ns1   unsupported operand type(s) for <<: '%s' and '%s'(   R   R   R   R   R
   R   t
   __lshift__(   R#   R'   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR=   ä   s
    %c         C   sS   t  | ƒ s7 t d t |  ƒ j t | ƒ j f ƒ ‚ n  t t t |  ƒ j | ƒ ƒ S(   Ns1   unsupported operand type(s) for >>: '%s' and '%s'(   R   R   R   R   R
   R   t
   __rshift__(   R#   R'   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR>   ë   s
    %c         C   sS   t  | ƒ s7 t d t |  ƒ j t | ƒ j f ƒ ‚ n  t t t |  ƒ j | ƒ ƒ S(   Ns0   unsupported operand type(s) for &: '%s' and '%s'(   R   R   R   R   R
   R   t   __and__(   R#   R'   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR?   ò   s
    %c         C   sS   t  | ƒ s7 t d t |  ƒ j t | ƒ j f ƒ ‚ n  t t t |  ƒ j | ƒ ƒ S(   Ns0   unsupported operand type(s) for |: '%s' and '%s'(   R   R   R   R   R
   R   t   __or__(   R#   R'   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR@   ù   s
    %c         C   sS   t  | ƒ s7 t d t |  ƒ j t | ƒ j f ƒ ‚ n  t t t |  ƒ j | ƒ ƒ S(   Ns0   unsupported operand type(s) for ^: '%s' and '%s'(   R   R   R   R   R
   R   t   __xor__(   R#   R'   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyRA      s
    %c         C   s   t  t t  |  ƒ j ƒ  ƒ S(   N(   R
   R   t   __neg__(   R#   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyRB     s    c         C   s   t  t t  |  ƒ j ƒ  ƒ S(   N(   R
   R   t   __pos__(   R#   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyRC   
  s    c         C   s   t  t t  |  ƒ j ƒ  ƒ S(   N(   R
   R   t   __abs__(   R#   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyRD     s    c         C   s   t  t t  |  ƒ j ƒ  ƒ S(   N(   R
   R   t
   __invert__(   R#   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyRE     s    c         C   s   |  S(   N(    (   R#   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR     s    c         C   s
   |  j  ƒ  S(   N(   t   __bool__(   R#   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyt   __nonzero__  s    c         C   s   t  t |  ƒ j ƒ  S(   s<   
        So subclasses can override this, Py3-style
        (   R   R
   RG   (   R#   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyRF     s    c         C   s
   t  |  ƒ S(   N(   R   (   R#   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyt
   __native__  s    t   bigc   	      C   s˜  | d k  r t  d ƒ ‚ n  | d k r: |  d k r: t ƒ  S| r‚ |  d k  r‚ | d } d | |  } | d k r£ t d ƒ ‚ q£ n! |  d k  r t d ƒ ‚ n  |  } | d k r¾ t  d	 ƒ ‚ n  d
 | } t d t | ƒ d | j | d ƒ j d ƒ ƒ } | rV| d d @} |  d k r1| r1t d ƒ ‚ n  |  d k  rV| rVt d ƒ ‚ qVn  t | ƒ | k rwt d ƒ ‚ n  | d k r‡| S| d d d … S(   sG  
        Return an array of bytes representing an integer.

        The integer is represented using length bytes.  An OverflowError is
        raised if the integer is not representable with the given number of
        bytes.

        The byteorder argument determines the byte order used to represent the
        integer.  If byteorder is 'big', the most significant byte is at the
        beginning of the byte array.  If byteorder is 'little', the most
        significant byte is at the end of the byte array.  To request the native
        byte order of the host system, use `sys.byteorder' as the byte order value.

        The signed keyword-only argument determines whether two's complement is
        used to represent the integer.  If signed is False and a negative integer
        is given, an OverflowError is raised.
        i    s$   length argument must be non-negativei   i   s   int too smal to converts&   can't convert negative int to unsignedt   littleRI   s*   byteorder must be either 'little' or 'big's   %xt   0t   hexi€   s   int too big to converts   int too small to convertNiÿÿÿÿ(   RJ   RI   (   t
   ValueErrorR   t   OverflowErrort   lent   zfillt   decode(	   R#   t   lengtht	   byteordert   signedt   bitst   numt   ht   st   high_set(    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyt   to_bytes"  s2    

4c         C   sñ   | d k r t  d ƒ ‚ n  t | t ƒ r9 t d ƒ ‚ n! t | t j ƒ rZ t | ƒ } n  | d k rl | n | d d d … } t | ƒ d k rš d } n  t t	 | ƒ j
 d	 ƒ d
 ƒ } | rç | d d @rç | d t | ƒ d } n  |  | ƒ S(   s'  
        Return the integer represented by the given array of bytes.

        The mybytes argument must either support the buffer protocol or be an
        iterable object producing bytes.  Bytes and bytearray are examples of
        built-in objects that support the buffer protocol.

        The byteorder argument determines the byte order used to represent the
        integer.  If byteorder is 'big', the most significant byte is at the
        beginning of the byte array.  If byteorder is 'little', the most
        significant byte is at the end of the byte array.  To request the native
        byte order of the host system, use `sys.byteorder' as the byte order value.

        The signed keyword-only argument indicates whether two's complement is
        used to represent the integer.
        RJ   RI   s*   byteorder must be either 'little' or 'big's'   cannot convert unicode objects to bytesNiÿÿÿÿi    s    RL   i   i€   i   i   (   RJ   RI   (   RM   R   t   unicodeR   t   collectionst   IterableR   RO   R   R   t   encode(   R   t   mybytesRS   RT   t   bRV   (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyt
   from_bytesO  s    %	(+   R   R   t   __doc__R   R!   R%   R(   R)   R*   R+   R,   R-   R.   R0   R1   R2   R/   R4   R5   R6   R7   R8   R9   R:   R;   R<   R=   R>   R?   R@   RA   RB   RC   RD   RE   R   RG   RF   RH   t   FalseRZ   t   classmethodRa   (    (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyR
      sP   6								
																												-(   Rb   t
   __future__R    t   structR\   t   future.types.newbytesR   t   future.types.newobjectR   t   future.utilsR   R   R   R   R   R   R   R   R   R	   R
   t   __all__(    (    (    sa   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newint.pyt   <module>   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()

"""

import sys
import copy

from future.utils import with_metaclass
from future.types.newobject import newobject


_builtin_list = list
ver = sys.version_info[:2]


class BaseNewList(type):
    def __instancecheck__(cls, instance):
        if cls == newlist:
            return isinstance(instance, _builtin_list)
        else:
            return issubclass(instance.__class__, cls)


class newlist(with_metaclass(BaseNewList, _builtin_list)):
    """
    A backport of the Python 3 list object to Py2
    """
    def copy(self):
        """
        L.copy() -> list -- a shallow copy of L
        """
        return copy.copy(self)

    def clear(self):
        """L.clear() -> None -- remove all items from L"""
        for i in range(len(self)):
            self.pop()

    def __new__(cls, *args, **kwargs):
        """
        list() -> new empty list
        list(iterable) -> new list initialized from iterable's items
        """

        if len(args) == 0:
            return super(newlist, cls).__new__(cls)
        elif type(args[0]) == newlist:
            value = args[0]
        else:
            value = args[0]
        return super(newlist, cls).__new__(cls, value)

    def __add__(self, value):
        return newlist(super(newlist, self).__add__(value))

    def __radd__(self, left):
        " left + self "
        try:
            return newlist(left) + self
        except:
            return NotImplemented

    def __getitem__(self, y):
        """
        x.__getitem__(y) <==> x[y]

        Warning: a bug in Python 2.x prevents indexing via a slice from
        returning a newlist object.
        """
        if isinstance(y, slice):
            return newlist(super(newlist, self).__getitem__(y))
        else:
            return super(newlist, self).__getitem__(y)

    def __native__(self):
        """
        Hook for the future.utils.native() function
        """
        return list(self)

    def __nonzero__(self):
        return len(self) > 0


__all__ = ['newlist']
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     