ó
âdc           @   sX   d  Z  d d l Z d d l m Z e Z e j d  Z d e f d „  ƒ  YZ d g Z	 d S(   sÓ  
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')

iÿÿÿÿN(   t   with_metaclassi   t	   newobjectc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sô   
    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__).
    c         C   s2   t  |  d ƒ r" t |  ƒ j |  ƒ St d ƒ ‚ d  S(   Nt   __next__s   newobject is not an iterator(   t   hasattrt   typeR   t	   TypeError(   t   self(    (    sd   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newobject.pyt   nextE   s    c         C   sW   t  |  d ƒ r' t |  ƒ j |  ƒ } n t |  ƒ } t | t ƒ rF | S| j d ƒ Sd  S(   Nt   __str__s   utf-8(   R   R   R   t   strt
   isinstancet   unicodet   decode(   R   t   s(    (    sd   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newobject.pyt   __unicode__J   s    c         C   sH   t  |  d ƒ r" t |  ƒ j |  ƒ St  |  d ƒ rD t |  ƒ j |  ƒ St S(   Nt   __bool__t   __len__(   R   R   R   R   t   True(   R   (    (    sd   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newobject.pyt   __nonzero__V   s
    c         C   s   t  |  d ƒ s t S|  j ƒ  S(   Nt   __int__(   R   t   NotImplementedR   (   R   (    (    sd   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newobject.pyt   __long__e   s    c         C   s
   t  |  ƒ S(   s=   
        Hook for the future.utils.native() function
        (   t   object(   R   (    (    sd   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newobject.pyt
   __native__   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    sd   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newobject.pyR   ;   s   					(
   R   t   syst   future.utilsR    R   t   _builtin_objectt   version_infot   verR   t   __all__(    (    (    sd   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_lib/future/future/types/newobject.pyt   <module>&   s   K                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              """
A substitute for the Python 3 open() function.

Note that io.open() is more complete but maybe slower. Even so, the
completeness may be a better default. TODO: compare these
"""

_builtin_open = open

class newopen(object):
    """Wrapper providing key part of Python 3 open() interface.

    From IPython's py3compat.py module. License: BSD.
    """
    def __init__(self, fname, mode="r", encoding="utf-8"):
        self.f = _builtin_open(fname, mode)
        self.enc = encoding

    def write(self, s):
        return self.f.write(s.encode(self.enc))

    def read(self, size=-1):
        return self.f.read(size).decode(self.enc)

    def close(self):
        return self.f.close()

    def __enter__(self):
        return self

    def __exit__(self, etype, value, traceback):
        self.f.close()

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    """
Nearly identical to xrange.py, by Dan Crosta, from

    https://github.com/dcrosta/xrange.git

This is included here in the ``future`` package rather than pointed to as
a dependency because there is no package for ``xrange`` on PyPI. It is
also tweaked to appear like a regular Python 3 ``range`` object rather
than a Python 2 xrange.

From Dan Crosta's README:

    "A pure-Python implementation of Python 2.7's xrange built-in, with
    some features backported from the Python 3.x range built-in (which
    replaced xrange) in that version."

    Read more at
        https://late.am/post/2012/06/18/what-the-heck-is-an-xrange
"""
from __future__ import absolute_import

from collections import Sequence, Iterator
from itertools import islice

from future.backports.misc import count   # with step parameter on Py2.6
# For backward compatibility with python-future versions < 0.14.4:
_count = count


class newrange(Sequence):
    """
    Pure-Python backport of Python 3's range object.  See `the CPython
    documentation for details:
    <http://docs.python.org/py3k/library/functions.html#range>`_
    """

    def __init__(self, *args):
        if len(args) == 1:
            start, stop, step = 0, args[0], 1
        elif len(args) == 2:
            start, stop, step = args[0], args[1], 1
        elif len(args) == 3:
            start, stop, step = args
        else:
            raise TypeError('range() requires 1-3 int arguments')

        try:
            start, stop, step = int(start), int(stop), int(step)
        except ValueError:
            raise TypeError('an integer is required')

        if step == 0:
            raise ValueError('range() arg 3 must not be zero')
        elif step < 0:
            stop = min(stop, start)
        else:
            stop = max(stop, start)

        self._start = start
        self._stop = stop
        self._step = step
        self._len = (stop - start) // step + bool((stop - start) % step)

    @property
    def start(self):
        return self._start

    @property
    def stop(self):
        return self._stop

    @property
    def step(self):
        return self._step

    def __repr__(self):
        if self._step == 1:
            return 'range(%d, %d)' % (self._start, self._stop)
        return 'range(%d, %d, %d)' % (self._start, self._stop, self._step)

    def __eq__(self, other):
        return (isinstance(other, newrange) and
                (self._len == 0 == other._len or
                 (self._start, self._step, self._len) ==
                 (other._start, other._step, self._len)))

    def __len__(self):
        return self._len

    def index(self, value):
        """Return the 0-based position of integer `value` in
        the sequence this range represents."""
        diff = value - self._start
        quotient, remainder = divmod(diff, self._step)
        if remainder == 0 and 0 <= quotient < self._len:
            return abs(quotient)
        raise ValueError('%r is not in range' % value)

    def count(self, value):
        """Return the number of ocurrences of integer `value`
        in the sequence this range represents."""
        # a value can occur exactly zero or one times
        return int(value in self)

    def __contains__(self, value):
        """Return ``True`` if the integer `value` occurs in
        the sequence this range represents."""
        try:
            self.index(value)
            return True
        except ValueError:
            return False

    def __reversed__(self):
        return iter(self[::-1])

    def __getitem__(self, index):
        """Return the element at position ``index`` in the sequence
        this range represents, or raise :class:`IndexError` if the
        position is out of range."""
        if isinstance(index, slice):
            return self.__getitem_slice(index)
        if index < 0:
            # negative indexes access from the end
            index = self._len + index
        if index < 0 or index >= self._len:
            raise IndexError('range object index out of range')
        return self._start + index * self._step

    def __getitem_slice(self, slce):
        """Return a range which represents the requested slce
        of the sequence represented by this range.
        """
        scaled_indices = (self._step * n for n in slce.indices(self._len))
        start_offset, stop_offset, new_step = scaled_indices
        return newrange(self._start + start_offset,
                        self._start + stop_offset,
                        new_step)

    def __iter__(self):
        """Return an iterator which enumerates the elements of the
        sequence this range represents."""
        return range_iterator(self)


class range_iterator(Iterator):
    """An iterator for a :class:`range`.
    """
    def __init__(self, range_):
        self._stepper = islice(count(range_.start, range_.step), len(range_))

    def __iter__(self):
        return self

    def next(self):
        return next(self._stepper)


__all__ = ['newrange']
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        