
    /hk                     R    S SK r S SKJr  S SKJr  SSKJr  SSKJr   " S S\5      r	g)	    N)pformat)UserDict   )prettify_json)	HTTPErrorc                   |   ^  \ rS rSrSrU 4S jrS rS rS rS r	\
S 5       rS	 rSS
 jr\SS.S j5       rSrU =r$ )SerpResults
   a  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                0   > [         TU ]  U5        X l        g N)super__init__client)selfdatar   	__class__s      aC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\serpapi/models.pyr   SerpResults.__init__   s        c                     U R                   $ r   r   r   s    r   __getstate__SerpResults.__getstate__   s    yyr   c                     Xl         g r   r   )r   states     r   __setstate__SerpResults.__setstate__   s    	r   c                 R    [        [        R                  " U R                  SS95      $ )zQThe visual representation of the data, which is pretty printed, for
ease of use.
   )indent)r   jsondumpsr   r   s    r   __repr__SerpResults.__repr__"   s    
 TZZ		!<==r   c                 6    U R                   R                  5       $ )zrReturns the data as a standard Python dictionary.
This can be useful when using ``json.dumps(search), for example.)r   copyr   s    r   as_dictSerpResults.as_dict)   s     yy~~r   c                 j    U R                   R                  S5      nU(       a  UR                  S5      $ g)z,The URL of the next page of results, if any.serpapi_paginationnextN)r   get)r   r+   s     r   next_page_urlSerpResults.next_page_url/   s1     "YY]]+?@%))&11 r   c                     U R                   (       aZ  SU R                  R                  0nU R                  R                  SU R                   US9n[        R                  X R                  S9$ g)z(Return the next page of results, if any.api_keyGET)pathparamsr   N)r.   r   r1   requestr	   from_http_response)r   r4   rs      r   	next_pageSerpResults.next_page8   s_     !4!45F##E0B0B6#RA11!KK1HH r   c              #      #    SnU nUR                   (       a9  X!:  a3  UR                  5       nUS-  nUv   UR                   (       a  X!:  a  M1  gggg7f)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.   r9   )r   	max_pagescurrent_page_countcurrent_pages       r   yield_pagesSerpResults.yield_pagesB   sZ      ((-?-K'113L!# ((-?-K(-K(s   A
AANr5   c                j     U " UR                  5       US9n U $ ! [         a    UR                  s $ f = f)av  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.
r5   )r"   
ValueErrortext)clsr8   r   s      r   r7   SerpResults.from_http_responseP   s6    	affhv.CJ 	66M	s    22)r   r   )i  )__name__
__module____qualname____firstlineno____doc__r   r   r   r$   r(   propertyr.   r9   r?   classmethodr7   __static_attributes____classcell__)r   s   @r   r	   r	   
   sW    >  2 2I -1  r   r	   )
r"   pprintr   collectionsr   textuir   
exceptionsr   r	    r   r   <module>rT      s"        ! !W( Wr   