Ë
    ÑÕ¯i%  ã                   ó\   — d Z dZddlmZ ddlmZ ddlmZ  G d„ de«      Z G d„ d	e	«      Z
y
)z"A fake HTTP connection for testingzMark Roach (mrroach@google.com)é    )Úurllib)Ú
connection)Úformatsc                   ó   — e Zd ZdZy)ÚErrorz)The base exception class for this module.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úS/var/www/html/venv/lib/python3.12/site-packages/pyactiveresource/fake_connection.pyr   r      s   „ Ú3r   r   c                   ól   — e Zd ZdZej
                  fd„Zd„ Zdd„Z	 dd„Z	d„ Z
dd„Zdd	„Zdd
„Zdd„Zy)ÚFakeConnectiona=  A fake HTTP connection for testing.
    
    Inspired by ActiveResource's HttpMock class. This class is designed to
    take a list of inputs and their corresponding outputs.
    
    Inputs will be matched on the method, path, query and data arguments
    
    Example:
    >>> connection = FakeConnection()
    >>> body = '<?json ... />'
    >>> connection.respond_to('get', '/foos/1.json', None, None, body)
    >>> class Foo(resource.Resource):
    ...     _site = 'http://localhost/'
    ...
    >>> Foo._connection_obj = connection
    >>> Foo.find(1)
    foo(1)
    c                 ó.   — || _         i | _        d| _        y)z&Constructor for FakeConnection object.FN)ÚformatÚ_request_mapÚ_debug_only)Úselfr   s     r   Ú__init__zFakeConnection.__init__"   s   € àˆŒØˆÔØ ˆÕr   c                 óÖ   — t         j                  j                  |«      \  }}|r;t        |j	                  d«      D �cg c]  }|j	                  d«      ‘Œ c}«      }||fS i }||fS c c}w )z5Return the path and the query string as a dictionary.Ú&Ú=)r   ÚparseÚ
splitqueryÚdictÚsplit)r   ÚpathÚ	path_onlyÚquery_stringÚiÚ
query_dicts         r   Ú_split_pathzFakeConnection._split_path(   sq   € ä"(§,¡,×"9Ñ"9¸$Ó"?Ñˆ	�<ÙÜ°\×5GÑ5GÈÔ5LÓMÑ5L°˜qŸw™w s�|Ð5LÑMÓNˆJð ˜*Ð$Ð$ð ˆJØ˜*Ð$Ð$ùò Ns   ½A&c                 ó   — || _         y ©N)r   )r   Údebugs     r   Ú
debug_onlyzFakeConnection.debug_only1   s
   € Ø ˆÕr   Nc                 óš   — | j                  |«      \  }}|€i }| j                  j                  |g «      j                  ||||f||ff«       y)a  Set the response for a given request.
        
        Args:
            method: The http method (e.g. 'get', 'put' etc.).
            path: The path being requested (e.g. '/collection/id.json')
            headers: Dictionary of headers passed along with the request.
            data: The data being passed in as the request body.
            body: The string that should be returned for a matching request.
            response_headers: The headers returned for a matching request
        Returns:
            None
        N)r#   r   Ú
setdefaultÚappend)	r   Úmethodr   ÚheadersÚdataÚbodyÚresponse_headersr   Úquerys	            r   Ú
respond_tozFakeConnection.respond_to4   s^   € ð  ×+Ñ+¨DÓ1Ñˆ	�5ØÐ#Ø!ÐØ×Ñ×$Ñ$ V¨RÓ0×7Ñ7Ø˜U G¨TÐ2°TÐ;KÐ4LÐMõ	Or   c                 óè   — | j                  |«      \  }}| j                  j                  |i «      D ],  \  }}|||||fk(  sŒ|\  }	}
t        j                  d|	|
«      c S  t        d|›d|›d|›�«      ‚)NéÈ   zInvalid or unknown request: Ú Ú
)r#   r   Úgetr   ÚResponser   )r   r+   r   r,   r-   r   r0   ÚkeyÚvalueÚresponse_bodyr/   s              r   Ú_lookup_responsezFakeConnection._lookup_responseH   s…   € Ø×+Ñ+¨DÓ1Ñˆ	�5Ø×+Ñ+×/Ñ/°¸Ö;‰JˆC�Ø�y %¨°$Ð7Ó7Ø27Ñ/�Ð/Ü!×*Ñ*¨3°Ð?OÓPÒPð <õ Úš7¡Dð*ó +ð 	+r   c                 óp   — | j                   j                  | j                  d||d«      j                  «      S )zPerform an HTTP get request.r6   N)r   Údecoder;   r.   ©r   r   r,   s      r   r6   zFakeConnection.getQ   s5   € à�{‰{×!Ñ!Ø×!Ñ! %¨¨w¸Ó=×BÑBóDð 	Dr   c                 ó*   — | j                  d|||«      S )úPerform an HTTP post request.Úpost©r;   ©r   r   r,   r-   s       r   rA   zFakeConnection.postV   s   € à×$Ñ$ V¨T°7¸DÓAÐAr   c                 ó*   — | j                  d|||«      S )r@   ÚputrB   rC   s       r   rE   zFakeConnection.putZ   s   € à×$Ñ$ U¨D°'¸4Ó@Ð@r   c                 ó*   — | j                  d||d«      S )zPerform an HTTP delete request.ÚdeleteNrB   r>   s      r   rG   zFakeConnection.delete^   s   € à×$Ñ$ X¨t°W¸dÓCÐCr   )Tr%   )NN)r   r	   r
   r   r   Ú
JSONFormatr   r#   r'   r1   r;   r6   rA   rE   rG   r   r   r   r   r      sI   „ ñð$ &×0Ñ0ó !ò%ó!ð %)óOò(+óDó
BóAôDr   r   N)r   Ú
__author__Ú	six.movesr   Úpyactiveresourcer   r   Ú	Exceptionr   Úobjectr   r   r   r   Ú<module>rN      s4   ðñ )à.€
å Ý 'Ý $ô4ˆIô 4ôQD�Võ QDr   