o
    ä›eÇ  ã                   @   s(   d dl Z d dlmZ G dd„ deƒZdS )é    N©ÚTwilioExceptionc                   @   s„   e Zd ZdZh d£Zdd„ Zdd„ Zdd„ Zd	d
„ Ze	dd„ ƒZ
dd„ Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚPagez¤
    Represents a page of records in a collection.

    A `Page` lets you iterate over its records and fetch the next and previous
    pages in the collection.
    >   ÚendÚuriÚpageÚstartÚtotalÚ	num_pagesÚ	page_sizeÚlast_page_uriÚnext_page_uriÚfirst_page_uriÚprevious_page_uric                 C   s0   |   |¡}|| _|| _i | _t|  |¡ƒ| _d S ©N)Úprocess_responseÚ_versionÚ_payloadÚ	_solutionÚiterÚ	load_pageÚ_records)ÚselfÚversionÚresponseÚpayload© r   úC/var/www/html/venv/lib/python3.10/site-packages/twilio/base/page.pyÚ__init__   s
   
zPage.__init__c                 C   s   | S )z/
        A `Page` is a valid iterator.
        r   ©r   r   r   r   Ú__iter__#   s   zPage.__iter__c                 C   s   |   ¡ S r   )Únextr   r   r   r   Ú__next__)   s   zPage.__next__c                 C   s   |   t| jƒ¡S )z8
        Returns the next record in the `Page`.
        )Úget_instancer!   r   r   r   r   r   r!   ,   s   z	Page.nextc                 C   s    |j dkr
td|ƒ‚t |j¡S )zŒ
        Load a JSON response.

        :param Response response: The HTTP response.
        :return dict: The JSON-loaded content.
        éÈ   zUnable to fetch page)Ústatus_coder   ÚjsonÚloadsÚtext)Úclsr   r   r   r   r   2   s   

zPage.process_responsec                 C   sZ   d|v rd|d v r||d d  S t | ¡ ƒ}|| j }t|ƒdkr)|| ¡  S tdƒ‚)z«
        Parses the collection of records out of a list payload.

        :param dict payload: The JSON-loaded content.
        :return list: The list of records.
        ÚmetaÚkeyé   z$Page Records can not be deserialized)ÚsetÚkeysÚ	META_KEYSÚlenÚpopr   )r   r   r.   r+   r   r   r   r   ?   s   
zPage.load_pagec                 C   óR   d| j v rd| j d v r| j d d S d| j v r'| j d r'| jj | j d ¡S dS )z`
        :return str: Returns a link to the previous_page_url or None if doesn't exist.
        r*   Úprevious_page_urlr   N©r   r   ÚdomainÚabsolute_urlr   r   r   r   r3   P   ó
   zPage.previous_page_urlc                 C   r2   )z\
        :return str: Returns a link to the next_page_url or None if doesn't exist.
        r*   Únext_page_urlr   Nr4   r   r   r   r   r8   \   r7   zPage.next_page_urlc                 C   s   t dƒ‚)zŽ
        :param dict payload: A JSON-loaded representation of an instance record.
        :return: A rich, resource-dependent object.
        z<Page.get_instance() must be implemented in the derived classr   )r   r   r   r   r   r#   h   s   zPage.get_instancec                 C   ó6   | j sdS | jjj d| j ¡}t| ƒ}|| j|| jƒS )zX
        Return the `Page` after this one.
        :return Page: The next page.
        NÚGET)r8   r   r5   ÚtwilioÚrequestÚtyper   ©r   r   r)   r   r   r   Ú	next_pageo   ó
   zPage.next_pagec                 C   r9   )z]
        Return the `Page` before this one.
        :return Page: The previous page.
        Nr:   )r3   r   r5   r;   r<   r=   r   r>   r   r   r   Úprevious_page{   r@   zPage.previous_pagec                 C   s   dS )Nz<Page>r   r   r   r   r   Ú__repr__‡   s   zPage.__repr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r/   r   r    r"   r!   Úclassmethodr   r   Úpropertyr3   r8   r#   r?   rA   rB   r   r   r   r   r      s$    


r   )r&   Útwilio.base.exceptionsr   Úobjectr   r   r   r   r   Ú<module>   s    