o
    ~j6h7  ã                   @   s  d Z ddlmZ dZddlZddlZddlZddlZddlZddl	m
Z ddlmZ z
ddlmZ dZW n ey?   d	ZY nw ejZe ¡ Ze e¡Zd	Zd
d„ ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZ G dd„ deƒZ!dd„ Z"dS )zäModel objects for requests and responses.

Each API may support one or more serializations, such
as JSON, Atom, etc. The model classes are responsible
for converting between the wire format and the Python
object representation.
é    )Úabsolute_importz$jcgregorio@google.com (Joe Gregorio)N)Úversion)Ú	HttpError)ÚAPI_VERSION_METADATA_KEYTFc                   C   s   t dƒ‚)Nz"You need to override this function)ÚNotImplementedError© r   r   úd/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/googleapiclient/model.pyÚ	_abstract2   ó   r	   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚModelzÄModel base class.

    All Model classes should implement this interface.
    The Model serializes and de-serializes between a wire
    format such as JSON and a Python object representation.
    c                 C   ó
   t ƒ  dS )a¬  Updates outgoing requests with a serialized body.

        Args:
          headers: dict, request headers
          path_params: dict, parameters that appear in the request path
          query_params: dict, parameters that appear in the query
          body_value: object, the request body as a Python object, which must be
                      serializable.
        Returns:
          A tuple of (headers, path_params, query, body)

          headers: dict, request headers
          path_params: dict, parameters that appear in the request path
          query: string, query part of the request URI
          body: string, the body serialized in the desired wire format.
        N©r	   )ÚselfÚheadersÚpath_paramsÚquery_paramsÚ
body_valuer   r   r   Úrequest>   s   
zModel.requestc                 C   r   )áu  Convert the response wire format into a Python object.

        Args:
          resp: httplib2.Response, the HTTP response headers and status
          content: string, the body of the HTTP response

        Returns:
          The body de-serialized as a Python object.

        Raises:
          googleapiclient.errors.HttpError if a non 2xx response is received.
        Nr   ©r   ÚrespÚcontentr   r   r   ÚresponseQ   s   
zModel.responseN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   6   s    r   c                   @   sZ   e Zd ZdZdZdZdZdZdd„ Zddd„Z	dd„ Z
d	d
„ Zdd„ Zdd„ Zdd„ ZdS )Ú	BaseModelaú  Base model class.

    Subclasses should provide implementations for the "serialize" and
    "deserialize" methods, as well as values for the following class attributes.

    Attributes:
      accept: The value to use for the HTTP Accept header.
      content_type: The value to use for the HTTP Content-type header.
      no_content_response: The value to return when deserializing a 204 "No
          Content" response.
      alt_param: The value to supply as the "alt" query parameter for requests.
    Nc                 C   s    t rNt d¡ t d¡ | ¡ D ]\}}t d||¡ qt d¡ t d¡ | ¡ D ]\}}t d||¡ q*t d¡ t d|¡ t d|¡ t d	¡ d
S d
S )z:Logs debugging information about the request if requested.z--request-start--z-headers-start-ú%s: %sz-headers-end-z-path-parameters-start-z-path-parameters-end-zbody: %sz	query: %sz--request-end--N©Údump_request_responseÚLOGGERÚinfoÚitems)r   r   r   ÚqueryÚbodyÚhÚvr   r   r   Ú_log_requestt   s   




ôzBaseModel._log_requestc                 C   sà   |   |¡}| j|d< d|d< d|v r|d  d7  < nd|d< |d  d7  < d|v r4|d  d7  < nd|d< |d  d	ttf 7  < |rMtrM||t< n|rTt d
¡ |durb| j|d< |  	|¡}|  
||||¡ ||||fS )aX  Updates outgoing requests with a serialized body.

        Args:
          headers: dict, request headers
          path_params: dict, parameters that appear in the request path
          query_params: dict, parameters that appear in the query
          body_value: object, the request body as a Python object, which must be
              serializable by json.
          api_version: str, The precise API version represented by this request,
              which will result in an API Version header being sent along with the
              HTTP request.
        Returns:
          A tuple of (headers, path_params, query, body)

          headers: dict, request headers
          path_params: dict, parameters that appear in the request path
          query: string, query part of the request URI
          body: string, the body serialized as JSON
        Úacceptzgzip, deflatezaccept-encodingz
user-agentú Ú z(gzip)zx-goog-api-clientzgdcl/%s gl-python/%sz¢The `api_version` argument is ignored as a newer version of `google-api-core` is required to use this feature.Please upgrade `google-api-core` to 2.19.0 or newer.Nzcontent-type)Ú_build_queryr)   Ú_LIBRARY_VERSIONÚ_PY_VERSIONÚHAS_API_VERSIONr   ÚwarningsÚwarnÚcontent_typeÚ	serializer(   )r   r   r   r   r   Úapi_versionr$   r   r   r   r   „   s2   



þ
ÿ

zBaseModel.requestc                 C   s    | j dur| d| j i¡ g }| ¡ D ]4\}}t|ƒtg ƒkr1|D ]}| d¡}| ||f¡ q!qt|tƒr@t|jƒr@| d¡}| ||f¡ qdt	j
 |¡ S )z¼Builds a query string.

        Args:
          params: dict, the query parameters

        Returns:
          The query parameters properly encoded into an HTTP URI query string.
        NÚaltúutf-8ú?)Ú	alt_paramÚupdater#   ÚtypeÚencodeÚappendÚ
isinstanceÚstrÚcallableÚurllibÚparseÚ	urlencode)r   ÚparamsÚastuplesÚkeyÚvalueÚxr   r   r   r,   ¸   s   
	
þ
zBaseModel._build_queryc                 C   sN   t r%t d¡ | ¡ D ]\}}t d||¡ q|rt |¡ t d¡ dS dS )z;Logs debugging information about the response if requested.z--response-start--r   z--response-end--Nr   )r   r   r   r&   r'   r   r   r   Ú_log_responseÏ   s   

úzBaseModel._log_responsec                 C   sH   |   ||¡ |jdk r|jdkr| jS |  |¡S t d| ¡ t||ƒ‚)r   i,  éÌ   z Content from bad request was: %r)rH   ÚstatusÚno_content_responseÚdeserializer!   Údebugr   r   r   r   r   r   Ù   s   



zBaseModel.responsec                 C   r   )zËPerform the actual Python object serialization.

        Args:
          body_value: object, the request body as a Python object.

        Returns:
          string, the body in serialized form.
        Nr   ©r   r   r   r   r   r3   ó   s   
	zBaseModel.serializec                 C   r   )zéPerform the actual deserialization from response string to Python
        object.

        Args:
          content: string, the body of the HTTP response

        Returns:
          The body de-serialized as a Python object.
        Nr   ©r   r   r   r   r   rL   þ   ó   

zBaseModel.deserialize©N)r   r   r   r   r)   r2   rK   r8   r(   r   r,   rH   r   r3   rL   r   r   r   r   r   a   s    
4
r   c                   @   sB   e Zd ZdZdZdZdZddd„Zdd„ Zd	d
„ Z	e
dd„ ƒZdS )Ú	JsonModelz—Model class for JSON.

    Serializes and de-serializes between JSON and the Python
    object representation of HTTP request and response bodies.
    úapplication/jsonÚjsonFc                 C   ó
   || _ dS )z}Construct a JsonModel.

        Args:
          data_wrapper: boolean, wrap requests and responses in a data wrapper
        N)Ú_data_wrapper)r   Údata_wrapperr   r   r   Ú__init__  s   
zJsonModel.__init__c                 C   s*   t |tƒrd|vr| jrd|i}t |¡S )NÚdata)r=   ÚdictrV   rT   ÚdumpsrN   r   r   r   r3     s   ÿÿ
zJsonModel.serializec                 C   sh   z|  d¡}W n	 ty   Y nw zt |¡}W n tjjy&   |}Y |S w | jr2d|v r2|d }|S )Nr6   rY   )ÚdecodeÚAttributeErrorrT   ÚloadsÚdecoderÚJSONDecodeErrorrV   )r   r   r%   r   r   r   rL   '  s   ÿûzJsonModel.deserializec                 C   s   i S rQ   r   ©r   r   r   r   rK   5  ó   zJsonModel.no_content_responseN)F©r   r   r   r   r)   r2   r8   rX   r3   rL   ÚpropertyrK   r   r   r   r   rR     s    
	rR   c                   @   s0   e Zd ZdZdZdZdZdd„ Zedd„ ƒZ	dS )	ÚRawModelzÒModel class for requests that don't return JSON.

    Serializes and de-serializes between JSON and the Python
    object representation of HTTP request, and returns the raw bytes
    of the response body.
    ú*/*rS   Nc                 C   ó   |S rQ   r   rO   r   r   r   rL   F  ó   zRawModel.deserializec                 C   ó   dS ©Nr+   r   ra   r   r   r   rK   I  rb   zRawModel.no_content_response©
r   r   r   r   r)   r2   r8   rL   rd   rK   r   r   r   r   re   :  ó    re   c                   @   s0   e Zd ZdZdZdZdZdd„ Zedd„ ƒZ	d	S )
Ú
MediaModelzÍModel class for requests that return Media.

    Serializes and de-serializes between JSON and the Python
    object representation of HTTP request, and returns the raw bytes
    of the response body.
    rf   rS   Úmediac                 C   rg   rQ   r   rO   r   r   r   rL   Z  rh   zMediaModel.deserializec                 C   ri   rj   r   ra   r   r   r   rK   ]  rb   zMediaModel.no_content_responseNrk   r   r   r   r   rm   N  rl   rm   c                   @   s@   e Zd ZdZdZdZdZdd„ Zdd„ Zdd	„ Z	e
d
d„ ƒZdS )ÚProtocolBufferModelz•Model class for protocol buffers.

    Serializes and de-serializes the binary protocol buffer sent in the HTTP
    request and response bodies.
    zapplication/x-protobufÚprotoc                 C   rU   )a0  Constructs a ProtocolBufferModel.

        The serialized protocol buffer returned in an HTTP response will be
        de-serialized using the given protocol buffer class.

        Args:
          protocol_buffer: The protocol buffer class used to de-serialize a
          response from the API.
        N©Ú_protocol_buffer)r   Úprotocol_bufferr   r   r   rX   m  rP   zProtocolBufferModel.__init__c                 C   s   |  ¡ S rQ   )ÚSerializeToStringrN   r   r   r   r3   y  r
   zProtocolBufferModel.serializec                 C   s   | j  |¡S rQ   )rr   Ú
FromStringrO   r   r   r   rL   |  s   zProtocolBufferModel.deserializec                 C   s   |   ¡ S rQ   rq   ra   r   r   r   rK     s   z'ProtocolBufferModel.no_content_responseNrc   r   r   r   r   ro   b  s    ro   c                 C   sŠ   i }|   ¡ D ]-\}}| |d¡}|du rd||< q||kr2t|ƒti ƒkr-t||ƒ||< q|||< q	 q|D ]}|| vrB|| ||< q6|S )a7  Create a patch object.

    Some methods support PATCH, an efficient way to send updates to a resource.
    This method allows the easy construction of patch bodies by looking at the
    differences between a resource before and after it was modified.

    Args:
      original: object, the original deserialized resource
      modified: object, the modified deserialized resource
    Returns:
      An object that contains only the changes from original to modified, in a
      form suitable to pass to a PATCH method.

    Example usage:
      item = service.activities().get(postid=postid, userid=userid).execute()
      original = copy.deepcopy(item)
      item['object']['content'] = 'This is updated.'
      service.activities.patch(postid=postid, userid=userid,
        body=makepatch(original, item)).execute()
    N)r#   Úgetr:   Ú	makepatch)ÚoriginalÚmodifiedÚpatchrE   Úoriginal_valueÚmodified_valuer   r   r   rw   „  s   

€rw   )#r   Ú
__future__r   Ú
__author__rT   ÚloggingÚplatformr@   r0   Úgoogleapiclientr   Úgoogleapiclient_versionÚgoogleapiclient.errorsr   Úgoogle.api_core.version_headerr   r/   ÚImportErrorÚ__version__r-   Úpython_versionr.   Ú	getLoggerr   r!   r    r	   Úobjectr   r   rR   re   rm   ro   rw   r   r   r   r   Ú<module>   s:   ÿ
+ +/"