
    A^                         d dl Z e j                  j                  dk\  r e j                  j                  dk\  rd dlmZ nd dlmZ  G d de      Zy)    N   )Sequencec                   X    e 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y)
CachedLista  CachedList()

       Provides an immutable list that is constructed from a function that
       could take a while to run.  This is basically the same concept as
       memoization, except that the function does not take any parameters
       and therefore there is nothing to use as a memo.

       The constructor function is provided to __init__, must not take any
       parameters, and must return a list.  The invalidate() method indicates
       that the list is no longer valid and should be reconstucted by
       calling the function again.  It is up to client code to call invalidate.
       The rest of the procedure is handled by this class.

       In all ways, this should appear to be just like a list.c                 .    d| _         g | _        || _        y)a  Construct a new CachedList.  The lstFn is a function that takes
           no parameters and returns a list.  It will be called lazily - the
           list is not constructed until the first access, which could be
           quite a while after this method is called.TN)_invalid_lst_lstFn)selflstFns     3/usr/lib/python3/dist-packages/parted/cachedlist.py__init__zCachedList.__init__.   s    
 	    c                 V    | j                   r| j                         | _        d| _         y y )NF)r   r
   r	   r   s    r   __rebuildListzCachedList.__rebuildList7   s"    ==DI!DM r   c                 X    | j                          | j                  j                  |      S N)_CachedList__rebuildListr	   __contains__r   values     r   r   zCachedList.__contains__<   s#    yy%%e,,r   c                 X    | j                          | j                  j                  |      S r   )r   r	   __getitem__)r   indexs     r   r   zCachedList.__getitem__@   s#    yy$$U++r   c                 V    | j                          | j                  j                         S r   )r   r	   __iter__r   s    r   r   zCachedList.__iter__D   s!    yy!!##r   c                 L    | j                          t        | j                        S r   )r   lenr	   r   s    r   __len__zCachedList.__len__H       499~r   c                 L    | j                          t        | j                        S r   )r   reprr	   r   s    r   __repr__zCachedList.__repr__L   s    DIIr   c                 L    | j                          t        | j                        S r   )r   strr	   r   s    r   __str__zCachedList.__str__P   r!   r   c                 *    t        t        |             S r   )hashr&   r   s    r   __hash__zCachedList.__hash__T   s    CIr   c                 X    | j                          | j                  j                  |      S r   )r   r	   countr   s     r   r,   zCachedList.countW   s!    yyu%%r   c                 b    | j                           | j                  j                  |g|i |S r   )r   r	   r   )r   r   argskwargss       r   r   zCachedList.index[   s-    tyyu6t6v66r   c                     d| _         y)zIndicate that the list is no longer valid, due to some external
           changes.  The next access to the list will result in the provided
           list construction function being called to build a new list.TN)r   r   s    r   
invalidatezCachedList.invalidate_   s     r   N)__name__
__module____qualname____doc__r   r   r   r   r   r    r$   r'   r*   r,   r   r1    r   r   r   r      sD    B"
-,$&7r   r   )sysversion_infomajorminorcollections.abcr   collectionsr   r6   r   r   <module>r=      sE   0 Q3#3#3#9#9Q#>($D Dr   