
    *iy                         S r SSKrSSKJr  SSKJrJrJrJ	r	J
r
  SSKJr  SSKJr  SSKJrJr  S	 r " S
 S\	5      r " S S\5      rg)zPersistent Data Types
    N)OrderedDict)	ItemsViewKeysViewMutableMappingSequence
ValuesView)contextmanager)rmtree   )ENOVALCachec                    ^  U 4S jnSR                  T R                  5      Ul        SnUR                  U5      Ul        U$ )z,Make compare method with Sequence semantics.c                   > [        U[        5      (       d  [        $ [        U 5      n[        U5      nX#:w  a(  T[        R
                  L a  gT[        R                  L a  g[        X5       H  u  pEXE:w  d  M  T" XE5      s  $    T" X#5      $ )z&Compare method for deque and sequence.FT)
isinstancer   NotImplementedlenopeqnezip)selfthatlen_selflen_thatalphabetaseq_ops         R/var/www/html/ai-backend/venv/lib/python3.13/site-packages/diskcache/persistent.pycompare_make_compare.<locals>.compare   sw    $))!!t9t9t?KE}e** + h))    z__{0}__z/Return True if and only if deque is {0} `that`.)format__name____doc__)r   docr   doc_strs   `   r   _make_comparer'      s;    *( !''8G?GnnS)GONr!   c                   4   \ rS rSrSrS+S jr\S,S j5       r\S 5       r	\S 5       r
\S 5       r\R                  S	 5       rS
 rS rS rS rS r\" \R(                  S5      r\" \R,                  S5      r\" \R0                  S5      r\" \R4                  S5      r\" \R8                  S5      r\" \R<                  S5      rS r S r!S r"S r#S r$S r%S r&\&r'S r(\(r)S r*\*r+S r,S r-S  r.\.r/S! r0S" r1S# r2S$ r3\3r4S% r5\5r6S& r7S' r8S-S( jr9Sr:\;S) 5       r<S*r=g).Deque1   a&  Persistent sequence with double-ended queue semantics.

Double-ended queue is an ordered collection with optimized access at its
endpoints.

Items are serialized to disk. Deque may be initialized from directory path
where items are stored.

>>> deque = Deque()
>>> deque += range(5)
>>> list(deque)
[0, 1, 2, 3, 4]
>>> for value in range(5):
...     deque.appendleft(-value)
>>> len(deque)
10
>>> list(deque)
[-4, -3, -2, -1, 0, 0, 1, 2, 3, 4]
>>> deque.pop()
4
>>> deque.popleft()
-4
>>> deque.reverse()
>>> list(deque)
[3, 2, 1, 0, 0, -1, -2, -3]

Nc                 n    [        USS9U l        Uc  [        S5      OUU l        U R	                  U5        g)zInitialize deque instance.

If directory is None then temporary directory created. The directory
will *not* be automatically removed.

:param iterable: iterable of items to append to deque
:param directory: deque directory (default None)

noneeviction_policyNinf)r   _cachefloat_maxlen_extend)r   iterable	directorymaxlens       r   __init__Deque.__init__N   s/     Iv>'-~uU|6Xr!   c                     U R                  U 5      nXl        Uc  [        S5      OUUl        UR	                  U5        U$ )a   Initialize deque using `cache`.

>>> cache = Cache()
>>> deque = Deque.fromcache(cache, [5, 6, 7, 8])
>>> deque.cache is cache
True
>>> len(deque)
4
>>> 7 in deque
True
>>> deque.popleft()
5

:param Cache cache: cache to use
:param iterable: iterable of items
:return: initialized Deque

r/   )__new__r0   r1   r2   r3   )clscacher4   r6   r   s        r   	fromcacheDeque.fromcache\   s9    * {{3'-~uU|6Xr!   c                     U R                   $ )zCache used by deque.r0   r   s    r   r<   Deque.cachew        {{r!   c                 .    U R                   R                  $ )z%Directory path where deque is stored.r0   r5   rA   s    r   r5   Deque.directory|        {{$$$r!   c                     U R                   $ )zMax length of the deque.)r2   rA   s    r   r6   Deque.maxlen   s     ||r!   c                 &   Xl         U R                  R                  SS9   [        U R                  5      U R                   :  a5  U R	                  5         [        U R                  5      U R                   :  a  M5  SSS5        g! , (       d  f       g= f)zSet max length of the deque.

Pops items from left while length greater than max.

>>> deque = Deque()
>>> deque.extendleft('abcde')
>>> deque.maxlen = 3
>>> list(deque)
['c', 'd', 'e']

:param value: max length

TretryN)r2   r0   transactr   _popleftr   values     r   r6   rI      s_     [[!!!-dkk"T\\1 dkk"T\\1 .--s   AB
Bc                    [        U 5      nUS:  aH  X:  a  [        S5      eU R                  R                  5        H  nUS:X  a   U" U5      s  $ US-  nM     OLX* :  a  [        S5      eUS-  nU R                  R                  SS9 H  nUS:X  a   U" U5      s  $ US-  nM     [        S5      e! [         a     M  f = f! [         a     MF  f = f)Nr   zdeque index out of ranger   Treverse)r   
IndexErrorr0   iterkeysKeyError)r   indexfuncr   keys        r   _indexDeque._index   s    t9A:  !;<<{{++-A:!#Cy( 
 . y  !;<<QJE{{++D+9A:!#Cy( 
 : 344# $ ! ! $ ! !s$   B1C1
B?>B?
CCc                 L    U R                  XR                  R                  5      $ )ao  deque.__getitem__(index) <==> deque[index]

Return corresponding item for `index` in deque.

See also `Deque.peekleft` and `Deque.peek` for indexing deque at index
``0`` or ``-1``.

>>> deque = Deque()
>>> deque.extend('abcde')
>>> deque[1]
'b'
>>> deque[-2]
'd'

:param int index: index of item
:return: corresponding item
:raises IndexError: if index out of range

)rZ   r0   __getitem__r   rW   s     r   r]   Deque.__getitem__   s    ( {{5++"9"9::r!   c                 8   ^ ^ U U4S jnT R                  X5        g)aM  deque.__setitem__(index, value) <==> deque[index] = value

Store `value` in deque at `index`.

>>> deque = Deque()
>>> deque.extend([None] * 3)
>>> deque[0] = 'a'
>>> deque[1] = 'b'
>>> deque[-1] = 'c'
>>> ''.join(deque)
'abc'

:param int index: index of value
:param value: value to store
:raises IndexError: if index out of range

c                 <   > TR                   R                  U T5      $ N)r0   __setitem__)rY   r   rP   s    r   
_set_value%Deque.__setitem__.<locals>._set_value   s    ;;**366r!   N)rZ   )r   rW   rP   rd   s   ` ` r   rc   Deque.__setitem__   s    &	7 	E&r!   c                 N    U R                  XR                  R                  5        g)a  deque.__delitem__(index) <==> del deque[index]

Delete item in deque at `index`.

>>> deque = Deque()
>>> deque.extend([None] * 3)
>>> del deque[0]
>>> del deque[1]
>>> del deque[-1]
>>> len(deque)
0

:param int index: index of item
:raises IndexError: if index out of range

N)rZ   r0   __delitem__r^   s     r   rh   Deque.__delitem__   s    " 	E;;223r!   c                 b    [        U 5      R                  nSR                  XR                  5      $ )zZdeque.__repr__() <==> repr(deque)

Return string with printable representation of deque.

z{0}(directory={1!r})typer#   r"   r5   r   names     r   __repr__Deque.__repr__   s(     Dz""%,,T>>BBr!   zequal toznot equal toz	less thanzgreater thanzless than or equal tozgreater than or equal toc                 (    U R                  U5        U $ )zdeque.__iadd__(iterable) <==> deque += iterable

Extend back side of deque with items from iterable.

:param iterable: iterable of items to append to deque
:return: deque with added items

)r3   )r   r4   s     r   __iadd__Deque.__iadd__	  s     	Xr!   c              #      #    U R                   nUR                  5        H
  n X   v   M     g! [         a     M  f = f7f)zQdeque.__iter__() <==> iter(deque)

Return iterator of deque from front to back.

Nr0   rU   rV   r   r0   rY   s      r   __iter__Deque.__iter__  sA      ??$Ck! %  s    ?.?
<?<?c                 ,    [        U R                  5      $ )z:deque.__len__() <==> len(deque)

Return length of deque.

r   r0   rA   s    r   __len__Deque.__len__#       4;;r!   c              #      #    U R                   nUR                  SS9 H
  n X   v   M     g! [         a     M  f = f7f)zdeque.__reversed__() <==> reversed(deque)

Return iterator of deque from back to front.

>>> deque = Deque()
>>> deque.extend('abcd')
>>> iterator = reversed(deque)
>>> next(iterator)
'd'
>>> list(iterator)
['c', 'b', 'a']

TrR   Nru   rv   s      r   __reversed__Deque.__reversed__+  sE      ??4?0Ck! 1  s   >->
;>;>c                 2    U R                   U R                  4$ rb   r5   r6   rA   s    r   __getstate__Deque.__getstate__A  s    ~~t{{**r!   c                 *    Uu  p#U R                  X#S9  g )Nr   r7   )r   stater5   r6   s       r   __setstate__Deque.__setstate__D  s    !		9r!   c                    U R                   R                  SS9   U R                   R                  USS9  [        U R                   5      U R                  :  a  U R                  5         SSS5        g! , (       d  f       g= f)zAdd `value` to back of deque.

>>> deque = Deque()
>>> deque.append('a')
>>> deque.append('b')
>>> deque.append('c')
>>> list(deque)
['a', 'b', 'c']

:param value: value to add to back of deque

TrK   N)r0   rM   pushr   r2   rN   rO   s     r   appendDeque.appendH  sZ     [[!!!-KKU$/4;;$,,. .--s   AA11
A?c                    U R                   R                  SS9   U R                   R                  USSS9  [        U R                   5      U R                  :  a  U R                  5         SSS5        g! , (       d  f       g= f)zAdd `value` to front of deque.

>>> deque = Deque()
>>> deque.appendleft('a')
>>> deque.appendleft('b')
>>> deque.appendleft('c')
>>> list(deque)
['c', 'b', 'a']

:param value: value to add to front of deque

TrK   front)siderL   N)r0   rM   r   r   r2   _poprO   s     r   
appendleftDeque.appendleft\  s\     [[!!!-KKU=4;;$,,.		 .--s   AA22
B c                 6    U R                   R                  SS9  g)zqRemove all elements from deque.

>>> deque = Deque('abc')
>>> len(deque)
3
>>> deque.clear()
>>> list(deque)
[]

TrK   Nr0   clearrA   s    r   r   Deque.clearp       	%r!   c                 N    [        U 5      nU" U R                  U R                  S9$ )z.Copy deque with same directory and max length.r   )rl   r5   r6   )r   TypeSelfs     r   copy
Deque.copy  s     :$..EEr!   c                 .   ^ [        U4S jU  5       5      $ )a  Return number of occurrences of `value` in deque.

>>> deque = Deque()
>>> deque += [num for num in range(1, 5) for _ in range(num)]
>>> deque.count(0)
0
>>> deque.count(1)
1
>>> deque.count(4)
4

:param value: value to count in deque
:return: count of items equal to value in deque

c              3   8   >#    U  H  nTU:X  d  M  S v   M     g7f)r   N ).0itemrP   s     r   	<genexpr>Deque.count.<locals>.<genexpr>  s     7$11s   
	)sumrO   s    `r   countDeque.count  s      7777r!   c                 8    U H  nU R                  U5        M     g)z]Extend back side of deque with values from `iterable`.

:param iterable: iterable of values

N)_appendr   r4   rP   s      r   extendDeque.extend  s     ELL r!   c                 8    U H  nU R                  U5        M     g)zExtend front side of deque with value from `iterable`.

>>> deque = Deque()
>>> deque.extendleft('abc')
>>> list(deque)
['c', 'b', 'a']

:param iterable: iterable of values

N)_appendleftr   s      r   
extendleftDeque.extendleft  s     EU# r!   c                 x    S[         4nU R                  R                  USSS9u  p#U[         L a  [        S5      eU$ )aS  Peek at value at back of deque.

Faster than indexing deque at -1.

If deque is empty then raise IndexError.

>>> deque = Deque()
>>> deque.peek()
Traceback (most recent call last):
    ...
IndexError: peek from an empty deque
>>> deque += 'abc'
>>> deque.peek()
'c'

:return: value at back of deque
:raises IndexError: if deque is empty

NbackTdefaultr   rL   peek from an empty dequer   r0   peekrT   r   r   _rP   s       r   r   
Deque.peek  sB    ( ,;;##G&#MF?788r!   c                 x    S[         4nU R                  R                  USSS9u  p#U[         L a  [        S5      eU$ )a\  Peek at value at front of deque.

Faster than indexing deque at 0.

If deque is empty then raise IndexError.

>>> deque = Deque()
>>> deque.peekleft()
Traceback (most recent call last):
    ...
IndexError: peek from an empty deque
>>> deque += 'abc'
>>> deque.peekleft()
'a'

:return: value at front of deque
:raises IndexError: if deque is empty

Nr   Tr   r   r   r   s       r   peekleftDeque.peekleft  sB    ( ,;;##G'#NF?788r!   c                 x    S[         4nU R                  R                  USSS9u  p#U[         L a  [        S5      eU$ )aJ  Remove and return value at back of deque.

If deque is empty then raise IndexError.

>>> deque = Deque()
>>> deque += 'ab'
>>> deque.pop()
'b'
>>> deque.pop()
'a'
>>> deque.pop()
Traceback (most recent call last):
    ...
IndexError: pop from an empty deque

:return: value at back of deque
:raises IndexError: if deque is empty

Nr   Tr   pop from an empty dequer   r0   pullrT   r   s       r   pop	Deque.pop  sB    ( ,;;##G&#MF?677r!   c                 v    S[         4nU R                  R                  USS9u  p#U[         L a  [        S5      eU$ )a.  Remove and return value at front of deque.

>>> deque = Deque()
>>> deque += 'ab'
>>> deque.popleft()
'a'
>>> deque.popleft()
'b'
>>> deque.popleft()
Traceback (most recent call last):
    ...
IndexError: pop from an empty deque

:return: value at front of deque
:raises IndexError: if deque is empty

NTr   rL   r   r   r   s       r   popleftDeque.popleft  s@    $ ,;;##G4#@F?677r!   c                     U R                   nUR                  5        H  n X#   nX:X  a   X#	   gM     [        S5      e! [         a     M.  f = f! [         a     M?  f = f)aq  Remove first occurrence of `value` in deque.

>>> deque = Deque()
>>> deque += 'aab'
>>> deque.remove('a')
>>> list(deque)
['a', 'b']
>>> deque.remove('b')
>>> list(deque)
['a']
>>> deque.remove('c')
Traceback (most recent call last):
    ...
ValueError: deque.remove(value): value not in deque

:param value: value to remove
:raises ValueError: if value not in deque

Nz'deque.remove(value): value not in deque)r0   rU   rV   
ValueError)r   rP   r0   rY   r   s        r   removeDeque.remove  sz    ( ??$C
{ =!"K  ! % BCC	 $ ! !  s    A>
AA
AAc                     [        [        U 5      S9nU R                  5         U R                  U5        UR                  nUR
                  R                  5         A[        U5        g)zuReverse deque in place.

>>> deque = Deque()
>>> deque += 'abc'
>>> deque.reverse()
>>> list(deque)
['c', 'b', 'a']

)r4   N)r)   reversed_clearr3   r5   r0   closer
   )r   tempr5   s      r   rS   Deque.reverse>  sK      htn-TNN	yr!   c                    [        U[        5      (       d#  [        U5      R                  n[	        SU-  5      e[        U 5      nU(       d  gUS:  a9  X-  n[        U5       H%  n U R                  5       nU R                  U5        M'     gUS-  nX-  n[        U5       H%  n U R                  5       nU R                  U5        M'     g! [         a       gf = f! [         a       gf = f)a  Rotate deque right by `steps`.

If steps is negative then rotate left.

>>> deque = Deque()
>>> deque += range(5)
>>> deque.rotate(2)
>>> list(deque)
[3, 4, 0, 1, 2]
>>> deque.rotate(-1)
>>> list(deque)
[4, 0, 1, 2, 3]

:param int steps: number of steps to rotate (default 1)

z!integer argument expected, got %sNr   )r   intrl   r#   	TypeErrorr   ranger   r   rT   rN   r   )r   steps	type_namer   r   rP   s         r   rotateDeque.rotateV  s    " %%%U,,I?)KLLt9A:E5\, IIKE $$U+ " RKEE5\( MMOE LL' " "  " s$   %C	#C	
CC
C('C(c              #   z   #    U R                   R                  SS9   Sv   SSS5        g! , (       d  f       g= f7f)a  Context manager to perform a transaction by locking the deque.

While the deque is locked, no other write operation is permitted.
Transactions should therefore be as short as possible. Read and write
operations performed in a transaction are atomic. Read operations may
occur concurrent to a transaction.

Transactions may be nested and may not be shared between threads.

>>> from diskcache import Deque
>>> deque = Deque()
>>> deque += range(5)
>>> with deque.transact():  # Atomically rotate elements.
...     value = deque.pop()
...     deque.appendleft(value)
>>> list(deque)
[4, 0, 1, 2, 3]

:return: context manager for use in `with` statement

TrK   Nr0   rM   rA   s    r   rM   Deque.transact  s*     . [[!!!- .--   ;*	;
8;)r0   r2   )r   NN)r   N)r   )>r#   
__module____qualname____firstlineno__r$   r7   classmethodr=   propertyr<   r5   r6   setterrZ   r]   rc   rh   ro   r'   r   r   __eq__r   __ne__lt__lt__gt__gt__le__le__ge__ge__rr   rw   r{   r   r   r   r   r   r   r   r   r   r   r   r   r3   r   r   r   r   r   r   rN   r   rS   r   __hash__r	   rM   __static_attributes__r   r!   r   r)   r)   1   s   8  4   % %   ]]   &5<;,'04&C 255*-F255.1F255+.F255.1F255"9:F255"<=F
 ,+: $ G$ K& FF
8$  G$444 D0 H#DJ0.(` H r!   r)   c                      \ rS rSrSrS r\R                  r\	S 5       r
\S 5       r\S 5       rS rS rS	 rS S jrS!S jr\4S jrS!S jrS"S jrS#S jrS rS rS rS rS rS rS rS
rS r S r!S r"S r#S$S jr$\%S 5       r&S r'Sr(g
)%Indexi  a  Persistent mutable mapping with insertion order iteration.

Items are serialized to disk. Index may be initialized from directory path
where items are stored.

Hashing protocol is not used. Keys are looked up by their serialized
format. See ``diskcache.Disk`` for details.

>>> index = Index()
>>> index.update([('a', 1), ('b', 2), ('c', 3)])
>>> index['a']
1
>>> list(index)
['a', 'b', 'c']
>>> len(index)
3
>>> del index['b']
>>> index.popitem()
('c', 3)

c                     U(       a)  [        US   [        [        45      (       a  US   nUSS nOU(       a  US   c  USS nSn[        USS9U l        U R
                  " U0 UD6  g)ak  Initialize index in directory and update items.

Optional first argument may be string specifying directory where items
are stored. When None or not given, temporary directory is created.

>>> index = Index({'a': 1, 'b': 2, 'c': 3})
>>> len(index)
3
>>> directory = index.directory
>>> inventory = Index(directory, d=4)
>>> inventory['b']
2
>>> len(inventory)
4

r   r   Nr,   r-   )r   bytesstrr   r0   _update)r   argskwargsr5   s       r   r7   Index.__init__  si    " JtAw55QI8DQABxIIv>d%f%r!   c                 X    U R                  U 5      nXl        UR                  " U0 UD6  U$ )aa  Initialize index using `cache` and update items.

>>> cache = Cache()
>>> index = Index.fromcache(cache, {'a': 1, 'b': 2, 'c': 3})
>>> index.cache is cache
True
>>> len(index)
3
>>> 'b' in index
True
>>> index['c']
3

:param Cache cache: cache to use
:param args: mapping or sequence of items
:param kwargs: mapping of items
:return: initialized Index

)r:   r0   r   )r;   r<   r   r   r   s        r   r=   Index.fromcache  s-    , {{3d%f%r!   c                     U R                   $ )zCache used by index.r@   rA   s    r   r<   Index.cache  rC   r!   c                 .    U R                   R                  $ )z&Directory path where items are stored.rE   rA   s    r   r5   Index.directory  rG   r!   c                      U R                   U   $ )aj  index.__getitem__(key) <==> index[key]

Return corresponding value for `key` in index.

>>> index = Index()
>>> index.update({'a': 1, 'b': 2})
>>> index['a']
1
>>> index['b']
2
>>> index['c']
Traceback (most recent call last):
    ...
KeyError: 'c'

:param key: key for item
:return: value for item in index with given key
:raises KeyError: if key is not found

r@   r   rY   s     r   r]   Index.__getitem__  s    * {{3r!   c                      X R                   U'   g)zindex.__setitem__(key, value) <==> index[key] = value

Set `key` and `value` item in index.

>>> index = Index()
>>> index['a'] = 1
>>> index[0] = None
>>> len(index)
2

:param key: key for item
:param value: value for item

Nr@   )r   rY   rP   s      r   rc   Index.__setitem__  s     !Cr!   c                     U R                   U	 g)aX  index.__delitem__(key) <==> del index[key]

Delete corresponding item for `key` from index.

>>> index = Index()
>>> index.update({'a': 1, 'b': 2})
>>> del index['a']
>>> del index['b']
>>> len(index)
0
>>> del index['c']
Traceback (most recent call last):
    ...
KeyError: 'c'

:param key: key for item
:raises KeyError: if key is not found

Nr@   r   s     r   rh   Index.__delitem__$  s    ( KKr!   Nc                 j    U R                   n  X1   $ ! [         a    UR                  XSS9   Of = fM'  )a  Set and get value for `key` in index using `default`.

If `key` is not in index then set corresponding value to `default`. If
`key` is in index then ignore `default` and return existing value.

>>> index = Index()
>>> index.setdefault('a', 0)
0
>>> index.setdefault('a', 1)
0

:param key: key for item
:param default: value if key is missing (default None)
:return: value for item in index with given key

TrK   )r0   rV   add)r   rY   r   r0   s       r   
setdefaultIndex.setdefault:  sA    " 5{" 5

3t
45 s    00c                 6    U R                   R                  USS9$ )ah  Peek at key and value item pair in index based on iteration order.

>>> index = Index()
>>> for num, letter in enumerate('xyz'):
...     index[letter] = num
>>> index.peekitem()
('z', 2)
>>> index.peekitem(last=False)
('x', 0)

:param bool last: last item in iteration order (default True)
:return: key and value item pair
:raises KeyError: if cache is empty

TrK   )r0   peekitem)r   lasts     r   r  Index.peekitemR  s      {{##D#55r!   c                 f    U R                   nUR                  XSS9nU[        L a  [        U5      eU$ )a"  Remove corresponding item for `key` from index and return value.

If `key` is missing then return `default`. If `default` is `ENOVAL`
then raise KeyError.

>>> index = Index({'a': 1, 'b': 2})
>>> index.pop('a')
1
>>> index.pop('b')
2
>>> index.pop('c', default=3)
3
>>> index.pop('d')
Traceback (most recent call last):
    ...
KeyError: 'd'

:param key: key for item
:param default: return value if key is missing (default ENOVAL)
:return: value for item if key is found else default
:raises KeyError: if key is not found and default is ENOVAL

Tr   )r0   r   r   rV   )r   rY   r   r0   rP   s        r   r   	Index.popd  s5    0 

3t
<F?3-r!   c                     U R                   nUR                  SS9   UR                  US9u  p4X#	 SSS5        X44$ ! , (       d  f       WW4$ = f)aJ  Remove and return item pair.

Item pairs are returned in last-in-first-out (LIFO) order if last is
True else first-in-first-out (FIFO) order. LIFO order imitates a stack
and FIFO order imitates a queue.

>>> index = Index()
>>> index.update([('a', 1), ('b', 2), ('c', 3)])
>>> index.popitem()
('c', 3)
>>> index.popitem(last=False)
('a', 1)
>>> index.popitem()
('b', 2)
>>> index.popitem()
Traceback (most recent call last):
  ...
KeyError: 'dictionary is empty'

:param bool last: pop last item pair (default True)
:return: key and value item pair
:raises KeyError: if index is empty

TrK   )r  N)r0   rM   r  )r   r  r0   rY   rP   s        r   popitemIndex.popitem  sV    4 __4_(d3JC ) z	 )( Ezs	   ;
Ac                 8    U R                   R                  XUSS9$ )a>  Push `value` onto `side` of queue in index identified by `prefix`.

When prefix is None, integer keys are used. Otherwise, string keys are
used in the format "prefix-integer". Integer starts at 500 trillion.

Defaults to pushing value on back of queue. Set side to 'front' to push
value on front of queue. Side must be one of 'back' or 'front'.

See also `Index.pull`.

>>> index = Index()
>>> print(index.push('apples'))
500000000000000
>>> print(index.push('beans'))
500000000000001
>>> print(index.push('cherries', side='front'))
499999999999999
>>> index[500000000000001]
'beans'
>>> index.push('dates', prefix='fruit')
'fruit-500000000000000'

:param value: value for item
:param str prefix: key prefix (default None, key is integer)
:param str side: either 'back' or 'front' (default 'back')
:return: key for item in cache

TrK   )r0   r   )r   rP   prefixr   s       r   r   
Index.push  s     : {{t4@@r!   c                 8    U R                   R                  XUSS9$ )a  Pull key and value item pair from `side` of queue in index.

When prefix is None, integer keys are used. Otherwise, string keys are
used in the format "prefix-integer". Integer starts at 500 trillion.

If queue is empty, return default.

Defaults to pulling key and value item pairs from front of queue. Set
side to 'back' to pull from back of queue. Side must be one of 'front'
or 'back'.

See also `Index.push`.

>>> index = Index()
>>> for letter in 'abc':
...     print(index.push(letter))
500000000000000
500000000000001
500000000000002
>>> key, value = index.pull()
>>> print(key)
500000000000000
>>> value
'a'
>>> _, value = index.pull(side='back')
>>> value
'c'
>>> index.pull(prefix='fruit')
(None, None)

:param str prefix: key prefix (default None, key is integer)
:param default: value to return if key is missing
    (default (None, None))
:param str side: either 'front' or 'back' (default 'front')
:return: key and value item pair or default if queue is empty

TrK   )r0   r   )r   r  r   r   s       r   r   
Index.pull  s!    L {{TBBr!   c                 6    U R                   R                  SS9  g)zRemove all items from index.

>>> index = Index({'a': 0, 'b': 1, 'c': 2})
>>> len(index)
3
>>> index.clear()
>>> dict(index)
{}

TrK   Nr   rA   s    r   r   Index.clear  r   r!   c                 ,    [        U R                  5      $ )zVindex.__iter__() <==> iter(index)

Return iterator of index keys in insertion order.

)iterr0   rA   s    r   rw   Index.__iter__  s     DKK  r!   c                 ,    [        U R                  5      $ )a  index.__reversed__() <==> reversed(index)

Return iterator of index keys in reversed insertion order.

>>> index = Index()
>>> index.update([('a', 1), ('b', 2), ('c', 3)])
>>> iterator = reversed(index)
>>> next(iterator)
'c'
>>> list(iterator)
['b', 'a']

)r   r0   rA   s    r   r   Index.__reversed__   s     $$r!   c                 ,    [        U R                  5      $ )z:index.__len__() <==> len(index)

Return length of index.

rz   rA   s    r   r{   Index.__len__  r}   r!   c                     [        U 5      $ )zSet-like object providing a view of index keys.

>>> index = Index()
>>> index.update({'a': 1, 'b': 2, 'c': 3})
>>> keys_view = index.keys()
>>> 'b' in keys_view
True

:return: keys view

)r   rA   s    r   keys
Index.keys  s     ~r!   c                     [        U 5      $ )zSet-like object providing a view of index values.

>>> index = Index()
>>> index.update({'a': 1, 'b': 2, 'c': 3})
>>> values_view = index.values()
>>> 2 in values_view
True

:return: values view

)r   rA   s    r   valuesIndex.values&  s     $r!   c                     [        U 5      $ )zSet-like object providing a view of index items.

>>> index = Index()
>>> index.update({'a': 1, 'b': 2, 'c': 3})
>>> items_view = index.items()
>>> ('b', 2) in items_view
True

:return: items view

)r   rA   s    r   itemsIndex.items4  s     r!   c                     U R                   $ rb   )r5   rA   s    r   r   Index.__getstate__D  s    ~~r!   c                 &    U R                  U5        g rb   r   )r   r   s     r   r   Index.__setstate__G  s    er!   c                   ^ ^ [        T 5      [        T5      :w  a  g[        T[        [        45      (       a:  U 4S jT  5       nU4S jT 5       n[	        X#5      n[        S U 5       5      (       + $ [        UU 4S jT  5       5      $ )a  index.__eq__(other) <==> index == other

Compare equality for index and `other`.

Comparison to another index or ordered dictionary is
order-sensitive. Comparison to all other mappings is order-insensitive.

>>> index = Index()
>>> pairs = [('a', 1), ('b', 2), ('c', 3)]
>>> index.update(pairs)
>>> from collections import OrderedDict
>>> od = OrderedDict(pairs)
>>> index == od
True
>>> index == {'c': 3, 'b': 2, 'a': 1}
True

:param other: other mapping in equality comparison
:return: True if index equals other

Fc              3   0   >#    U  H  oTU   4v   M     g 7frb   r   )r   rY   r   s     r   r   Index.__eq__.<locals>.<genexpr>d  s     6#49%   c              3   0   >#    U  H  oTU   4v   M     g 7frb   r   )r   rY   others     r   r   r0  e  s     7#%*%r1  c              3   N   #    U  H  u  u  pu  p4X:g  =(       d    X$:g  v   M     g 7frb   r   )r   abxys        r   r   r0  g  s$     H%16+QV+%s   #%c              3   \   >#    U  H!  nTU   TR                  U[        5      :H  v   M#     g 7frb   )getr   )r   rY   r3  r   s     r   r   r0  i  s%     KdstCyEIIc6$::ds   ),)r   r   r   r   r   anyall)r   r3  r   r   pairss   ``   r   r   Index.__eq__J  sm    , t9E
"ee[12266E77D$EH%HHHHKdKKKr!   c                     X:X  + $ )a  index.__ne__(other) <==> index != other

Compare inequality for index and `other`.

Comparison to another index or ordered dictionary is
order-sensitive. Comparison to all other mappings is order-insensitive.

>>> index = Index()
>>> index.update([('a', 1), ('b', 2), ('c', 3)])
>>> from collections import OrderedDict
>>> od = OrderedDict([('c', 3), ('b', 2), ('a', 1)])
>>> index != od
True
>>> index != {'a': 1, 'b': 2}
True

:param other: other mapping in inequality comparison
:return: True if index does not equal other

r   )r   r3  s     r   r   Index.__ne__k  s    *   r!   c                 6    U R                   R                  XUS9$ )a  Memoizing cache decorator.

Decorator to wrap callable with memoizing function using cache.
Repeated calls with the same arguments will lookup result in cache and
avoid function evaluation.

If name is set to None (default), the callable name will be determined
automatically.

If typed is set to True, function arguments of different types will be
cached separately. For example, f(3) and f(3.0) will be treated as
distinct calls with distinct results.

The original underlying function is accessible through the __wrapped__
attribute. This is useful for introspection, for bypassing the cache,
or for rewrapping the function with a different cache.

>>> from diskcache import Index
>>> mapping = Index()
>>> @mapping.memoize()
... def fibonacci(number):
...     if number == 0:
...         return 0
...     elif number == 1:
...         return 1
...     else:
...         return fibonacci(number - 1) + fibonacci(number - 2)
>>> print(fibonacci(100))
354224848179261915075

An additional `__cache_key__` attribute can be used to generate the
cache key used for the given arguments.

>>> key = fibonacci.__cache_key__(100)
>>> print(mapping[key])
354224848179261915075

Remember to call memoize when decorating a callable. If you forget,
then a TypeError will occur. Note the lack of parenthenses after
memoize below:

>>> @mapping.memoize
... def test():
...     pass
Traceback (most recent call last):
    ...
TypeError: name cannot be callable

:param str name: name given for callable (default None, automatic)
:param bool typed: cache different types separately (default False)
:param set ignore: positional or keyword args to ignore (default ())
:return: callable decorator

)ignore)r0   memoize)r   rn   typedrB  s       r   rC  Index.memoize  s    n {{""4v">>r!   c              #   z   #    U R                   R                  SS9   Sv   SSS5        g! , (       d  f       g= f7f)a  Context manager to perform a transaction by locking the index.

While the index is locked, no other write operation is permitted.
Transactions should therefore be as short as possible. Read and write
operations performed in a transaction are atomic. Read operations may
occur concurrent to a transaction.

Transactions may be nested and may not be shared between threads.

>>> from diskcache import Index
>>> mapping = Index()
>>> with mapping.transact():  # Atomically increment two keys.
...     mapping['total'] = mapping.get('total', 0) + 123.4
...     mapping['count'] = mapping.get('count', 0) + 1
>>> with mapping.transact():  # Atomically calculate average.
...     average = mapping['total'] / mapping['count']
>>> average
123.4

:return: context manager for use in `with` statement

TrK   Nr   rA   s    r   rM   Index.transact  s*     0 [[!!!- .--r   c                 b    [        U 5      R                  nSR                  XR                  5      $ )zZindex.__repr__() <==> repr(index)

Return string with printable representation of index.

z
{0}({1!r})rk   rm   s     r   ro   Index.__repr__  s(     Dz""""488r!   r@   rb   )T)Nr   )N)NNr   )NFr   ))r#   r   r   r   r$   r7   r   updater   r   r=   r   r<   r5   r]   rc   rh   r  r  r   r   r  r   r   r   rw   r   r{   r"  r%  r(  r   r   r   r   r   rC  r	   rM   ro   r   r   r!   r   r   r     s    ,&6 ##G 4   % % .!",506$  & < DA>&CP&!%    HLB!.7?r  49r!   r   )r$   operatorr   collectionsr   collections.abcr   r   r   r   r   
contextlibr	   shutilr
   corer   r   r'   r)   r   r   r!   r   <module>rQ     sI     #  &  <o	H o	dz9N z9r!   