
    gk                     R    d dl Z d dlmZ d dlmZ ddlmZ ddlmZ  G d de      Z	y)	    N)pformat)UserDict   )prettify_json)	HTTPErrorc                   n     e Zd ZdZ fdZd Zd Zd Zd Ze	d        Z
d Zdd	Zed
dd       Z xZS )SerpResultsa  A dictionary-like object that represents the results of a SerpApi request.

    .. code-block:: python

        >>> search = serpapi.search(q="Coffee", location="Austin, Texas, United States")

        >>> print(search["search_metadata"].keys())
        dict_keys(['id', 'status', 'json_endpoint', 'created_at', 'processed_at', 'google_url', 'raw_html_file', 'total_time_taken'])

    An instance of this class is returned if the response is a valid JSON object.
    It can be used like a dictionary, but also has some additional methods.
    c                2    t         |   |       || _        y N)super__init__client)selfdatar   	__class__s      K/var/www/html/Manimaran/venv/lib/python3.12/site-packages/serpapi/models.pyr   zSerpResults.__init__   s        c                     | j                   S r   r   r   s    r   __getstate__zSerpResults.__getstate__   s    yyr   c                     || _         y r   r   )r   states     r   __setstate__zSerpResults.__setstate__   s	    	r   c                 V    t        t        j                  | j                  d            S )zaThe visual representation of the data, which is pretty printed, for
        ease of use.
           )indent)r   jsondumpsr   r   s    r   __repr__zSerpResults.__repr__"   s    
 TZZ		!<==r   c                 6    | j                   j                         S )zzReturns the data as a standard Python dictionary.
        This can be useful when using ``json.dumps(search), for example.)r   copyr   s    r   as_dictzSerpResults.as_dict)   s     yy~~r   c                 `    | j                   j                  d      }|r|j                  d      S y)z,The URL of the next page of results, if any.serpapi_paginationnextN)r   get)r   r%   s     r   next_page_urlzSerpResults.next_page_url/   s1     "YY]]+?@%))&11 r   c                     | j                   rad| j                  j                  i}| j                  j                  d| j                   |      }t        j                  || j                        S y)z(Return the next page of results, if any.api_keyGET)pathparamsr   N)r(   r   r*   requestr	   from_http_response)r   r-   rs      r   	next_pagezSerpResults.next_page8   sa     !4!45F##E0B0B6#RA11!DKK1HH r   c              #      K   d}| }|j                   r3||k  r-|j                         }|dz  }| |j                   r||k  r+yyyyw)zA generator that ``yield`` s the next ``n`` pages of search results, if any.

        :param max_pages: limit the number of pages yielded to ``n``.
        r   r   N)r(   r2   )r   	max_pagescurrent_page_countcurrent_pages       r   yield_pageszSerpResults.yield_pagesB   s_      ((-?)-K'113L!# ((-?)-K(-K(s   A AANr.   c                n    	  | |j                         |      } | S # t        $ r |j                  cY S w xY w)a  Construct a SerpResults object from an HTTP response.

        :param assert_200: if ``True`` (default), raise an exception if the status code is not 200.
        :param client: the Client instance which was used to send this request.

        An instance of this class is returned if the response is a valid JSON object.
        Otherwise, the raw text (as a properly decoded unicode string) is returned.
        r.   )r   
ValueErrortext)clsr1   r   s      r   r0   zSerpResults.from_http_responseP   s6    	affhv.CJ 	66M	s    44)i  )__name__
__module____qualname____doc__r   r   r   r    r#   propertyr(   r2   r7   classmethodr0   __classcell__)r   s   @r   r	   r	   
   sW    >  2 2I -1  r   r	   )
r   pprintr   collectionsr   textuir   
exceptionsr   r	    r   r   <module>rH      s"        ! !W( Wr   