Ë
    ÑÕ¯i³  ã                   ó<   — d dl mZ  G d„ de«      Z G d„ de«      Zy)é    )Ú
Collectionc                   ó`   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zd„ Zdd„Zdd„Z	dd„Z
ˆ fd	„Zˆ fd
„Zˆ xZS )ÚPaginatedCollectiona€  
    A subclass of Collection which allows cycling through pages of
    data through cursor-based pagination.

    :next_page_url contains a url for fetching the next page
    :previous_page_url contains a url for fetching the previous page

    You can use next_page_url and previous_page_url to fetch the next page
    of data by calling Resource.find(from_=page.next_page_url)
    c                 óZ  •— |j                  dd«      }|d   }t        |t        «      r@|r|j                  |j                  «       n|j                  }t
        t        | �  ||¬«       nt        t        | �  |d|xs i i|¤Ž d| j                  vrt        d«      ‚| j                  «       | j                  d<   | j                  d   j                  dd«      | _        | j                  d   j                  d	d«      | _        d| _        d| _        d| _        |j                  d
d«      | _        y)zBIf given a Collection object as an argument, inherit its metadata.ÚmetadataNr   )r   Úresource_classzNCursor-based pagination requires a "resource_class" attribute in the metadata.Ú
paginationÚnextÚpreviousÚno_iter_nextT)ÚpopÚ
isinstancer   Úupdater   Úsuperr   Ú__init__ÚAttributeErrorÚ&_PaginatedCollection__parse_paginationÚgetÚnext_page_urlÚprevious_page_urlÚ_nextÚ	_previousÚ_current_iterÚ_no_iter_next)ÚselfÚargsÚkwargsr   ÚobjÚ	__class__s        €úE/var/www/html/venv/lib/python3.12/site-packages/shopify/collection.pyr   zPaginatedCollection.__init__   s  ø€ ð —:‘:˜j¨$Ó/ˆØ�1‰gˆÜ�cœ:Ô&ÙØ—‘ §¡Õ-àŸ<™<�ÜÔ% tÑ5°cÀHÐ5ÕMäÔ% tÑ5ÐPTÐ_¸xº~È2Ð_ÐX^Ò_à  D§M¡MÑ1Ü Ð!qÓrÐrà&*×&=Ñ&=Ó&?ˆ�‰�lÑ#Ø!Ÿ]™]¨<Ñ8×<Ñ<¸VÀTÓJˆÔØ!%§¡¨|Ñ!<×!@Ñ!@ÀÈTÓ!RˆÔàˆŒ
ØˆŒØ!ˆÔØ#ŸZ™Z¨¸Ó=ˆÕó    c                 ó2  — d| j                   vri S | j                   d   j                  d| j                   d   j                  dd «      «      }|€i S i }|j                  d«      D ]0  }|j                  d«      \  }}|dd ||j                  d«      d   <   Œ2 |S )	NÚheadersÚLinkÚlinkz, z; é   éÿÿÿÿÚ")r   r   Úsplit)r   ÚvaluesÚresultÚvaluer%   Úrels         r    Ú__parse_paginationz&PaginatedCollection.__parse_pagination*   sž   € Ø˜DŸM™MÑ)ØˆIà—‘˜yÑ)×-Ñ-¨f°d·m±mÀIÑ6N×6RÑ6RÐSYÐ[_Ó6`ÓaˆØˆ>ØˆIàˆØ—\‘\ $Ö'ˆEØŸ™ DÓ)‰IˆD�#Ø(,¨Q¨r¨
ˆF�3—9‘9˜S“> !Ñ$Ò%ð (ð ˆr!   c                 ó,   — t        | j                  «      S )zBReturns true if the current page has any previous pages before it.)Úboolr   ©r   s    r    Úhas_previous_pagez%PaginatedCollection.has_previous_page8   s   € ä�D×*Ñ*Ó+Ð+r!   c                 ó,   — t        | j                  «      S )zKReturns true if the current page has any pages beyond the current position.)r0   r   r1   s    r    Úhas_next_pagez!PaginatedCollection.has_next_page<   s   € ä�D×&Ñ&Ó'Ð'r!   c                 ó    — | j                   r| j                   S | j                  «       st        d«      ‚| j                  | j                  |«      S )zÇReturns the previous page of items.

        Args:
            no_cache: If true the page will not be cached.
        Returns:
            A PaginatedCollection object with the new data set.
        zNo previous page)r   r2   Ú
IndexErrorÚ _PaginatedCollection__fetch_pager   ©r   Úno_caches     r    Úprevious_pagez!PaginatedCollection.previous_page@   sF   € ð �>Š>Ø—>‘>Ð!Ø×'Ñ'Ô)ÜÐ/Ó0Ð0Ø× Ñ  ×!7Ñ!7¸ÓBÐBr!   c                 ó    — | j                   r| j                   S | j                  «       st        d«      ‚| j                  | j                  |«      S )zÃReturns the next page of items.

        Args:
            no_cache: If true the page will not be cached.
        Returns:
            A PaginatedCollection object with the new data set.
        zNo next page)r   r4   r6   r7   r   r8   s     r    Ú	next_pagezPaginatedCollection.next_pageN   sE   € ð �:Š:Ø—:‘:ÐØ×#Ñ#Ô%Ü˜^Ó,Ð,Ø× Ñ  ×!3Ñ!3°XÓ>Ð>r!   c                 óš   — | j                   d   j                  |¬«      }|s|| _        | | j                  _        | j                  |_        |S )Nr   )Úfrom_)r   Úfindr   r   r   )r   Úurlr9   r
   s       r    Ú__fetch_pagez PaginatedCollection.__fetch_page\   sH   € Ø�}‰}Ð-Ñ.×3Ñ3¸#Ð3Ó>ˆÙØˆDŒJØ#'ˆD�J‰JÔ Ø!×/Ñ/ˆÔØˆr!   c              #   óø   •K  — t         t        | �  «       D ]  }|–— Œ | j                  ry	 | j                  s| | _        | j                  «       | _        | j                  D ]  }|–— Œ y# t        $ r Y yw xY w­w)z6Iterates through all items, also fetching other pages.N)r   r   Ú__iter__r   r   r<   r6   )r   Úitemr   s     €r    rC   zPaginatedCollection.__iter__d   s{   øè ø€ äÔ-¨tÑ=Ö?ˆDØ‹Jð @ð ×ÒØð	Ø×%Ò%Ø%)�Ô"Ø!%§¡Ó!1ˆDÔà×*Ô*�Ø“
ñ +øäò 	Ùð	üs(   ƒ)A:­=A+ Á*A:Á+	A7Á4A:Á6A7Á7A:c                 óv   •— | j                   rt        | j                   «      }nd}|t        t        | �  «       z   S )zIf fetched count all the pages.r   )r   Úlenr   r   Ú__len__)r   Úcountr   s     €r    rG   zPaginatedCollection.__len__v   s4   ø€ ð �:Š:Ü˜Ÿ
™
“O‰EàˆEØ”uÔ0°$Ñ?ÓAÑAÐAr!   )F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r2   r4   r:   r<   r7   rC   rG   Ú__classcell__)r   s   @r    r   r      s=   ø„ ñ	ô>ò4ò,ò(óCó?óô÷$Bð Br!   r   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚPaginatedIteratora•  
    This class implements an iterator over paginated collections which aims to
    be more memory-efficient by not keeping more than one page in memory at a
    time.

    >>> from shopify import Product, PaginatedIterator
    >>> for page in PaginatedIterator(Product.find()):
    ...     for item in page:
    ...         do_something(item)
    ...
    # every page and the page items are iterated
    c                 ój   — t        |t        «      st        d«      ‚|| _        d| j                  _        y )Nz8PaginatedIterator expects a PaginatedCollection instanceT)r   r   Ú	TypeErrorÚ
collectionr   )r   rR   s     r    r   zPaginatedIterator.__init__Ž   s,   € Ü˜*Ô&9Ô:ÜÐVÓWÐWØ$ˆŒØ(,ˆ�‰Õ%r!   c              #   ór   K  — | j                   }	 |–— 	 |j                  d¬«      }Œ# t        $ r Y yw xY w­w)z1Iterate over pages, returning one page at a time.T)r9   N)rR   r<   r6   )r   Úcurrent_pages     r    rC   zPaginatedIterator.__iter__”   sH   è ø€ à—‘ˆØØÒðØ+×5Ñ5¸tÐ5ÓD�ð øô ò Ùðüs   ‚7•( §7¨	4±7³4´7N)rI   rJ   rK   rL   r   rC   © r!   r    rO   rO   €   s   „ ñò-ór!   rO   N)Úpyactiveresource.collectionr   r   ÚobjectrO   rU   r!   r    Ú<module>rX      s%   ðÝ 2ôyB˜*ô yBôx˜õ r!   