!;i7dZddlmZdZddlZddlZddlZddlZddlZddl m Z ddl m Z  ddlmZdZn #e$rd ZYnwxYwe jZejZejeZd Zd ZGd d eZGd deZGddeZGddeZGddeZ GddeZ!dZ"dS)zModel 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 td)Nz"You need to override this function)NotImplementedErrorIC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\googleapiclient/model.py _abstractr 2s B C CCr ceZdZdZdZdZdS)ModelzModel 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"tdS)aUpdates 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. Nr )selfheaders path_params query_params body_values r requestz Model.request>s"  r c"tdS)uConvert 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. Nrrrespcontents r responsezModel.responseQs  r N)__name__ __module__ __qualname____doc__rrr r r rr6s<&     r rcNeZdZdZdZdZdZdZdZd dZ dZ dZ dZ dZ d ZdS) BaseModelaBase 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. Nctr@tdtd|D]!\}}td||"tdtd|D]!\}}td||"tdtd|td|td d Sd 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-zbody: %sz query: %sz--request-end--Ndump_request_responseLOGGERinfoitems)rrrquerybodyhvs r _log_requestzBaseModel._log_requestts + KK+ , , , KK) * * *  , ,1 Ha++++ KK ( ( ( KK1 2 2 2#))++ , ,1 Ha++++ KK/ 0 0 0 KK D ) ) ) KK U + + + KK) * * * * * + +r c||}|j|d<d|d<d|vr|dxxdz cc<nd|d<|dxxdz cc<d|vr|dxxdz cc<nd|d<|dxxd td tz cc<|rtr ||t <n|rt jd ||j|d <| |}| ||||||||fS)aXUpdates 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, deflatezaccept-encodingz user-agent z(gzip)zx-goog-api-clientzgdcl/z gl-python/zThe `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_queryr0_LIBRARY_VERSION _PY_VERSIONHAS_API_VERSIONrwarningswarn content_type serializer.)rrrrr api_versionr*s r rzBaseModel.requestsw(!!,// K%4!" 7 " " L ! ! !S ( ! ! ! !$&GL ! ) ' ) ) ' ( ( (C / ( ( ( (+-G' (#$$$$    K)  $$$  ? 0;G, - -   MG     !&*&7GN # 33J ';zBBBeZ88r c|j|d|jig}|D]\}}t|tgkr2|D].}|d}|||f/Wt |tr)t|jr|d}|||fdtj |zS)zBuilds a query string. Args: params: dict, the query parameters Returns: The query parameters properly encoded into an HTTP URI query string. Naltutf-8?) alt_paramupdater)typeencodeappend isinstancestrcallableurllibparse urlencode)rparamsastupleskeyvaluexs r r3zBaseModel._build_querys > % MM5$.1 2 2 2 ,,.. . .JCE{{d2hh&&..A))AOOS!H----.eS))2hu|.D.D2!LL11Ee ----V\++H5555r c$trtd|D]!\}}td||"|rt|tddSdS)z;Logs debugging information about the response if requested.z--response-start--r$z--response-end--Nr%)rrrr,r-s r _log_responsezBaseModel._log_responses  , KK, - - -  , ,1 Ha++++ % G$$$ KK* + + + + +  , ,r c||||jdkr'|jdkr|jS||Std|zt ||)ri,z Content from bad request was: %r)rQstatusno_content_response deserializer'debugrrs r rzBaseModel.responses} 4))) ;  {c!!//##G,, , LL;gE F F FD'** *r c"tdS)zPerform the actual Python object serialization. Args: body_value: object, the request body as a Python object. Returns: string, the body in serialized form. Nrrrs r r:zBaseModel.serializes  r c"tdS)zPerform 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. Nrrrs r rVzBaseModel.deserializes  r N)rrrr r0r9rUr@r.rr3rQrr:rVr r r r"r"as  FLI+++ 29292929h666.,,,+++4        r r"cHeZdZdZdZdZdZd dZdZdZ e dZ d S) JsonModelzModel class for JSON. Serializes and de-serializes between JSON and the Python object representation of HTTP request and response bodies. application/jsonjsonFc||_dS)z}Construct a JsonModel. Args: data_wrapper: boolean, wrap requests and responses in a data wrapper N) _data_wrapper)r data_wrappers r __init__zJsonModel.__init__s *r crt|trd|vr |jrd|i}tj|S)Ndata)rEdictrbr`dumpsrYs r r:zJsonModel.serializesF z4 ( ( .j((")!*-Jz*%%%r c |d}n#t$rYnwxYw tj|}|jr d|vr|d}n#tjj$r|}YnwxYw|S)Nr>rf)decodeAttributeErrorr`loadsrbdecoderJSONDecodeError)rrr+s r rVzJsonModel.deserialize's nnW--GG    D  $:g&&D! $fnnF| |+   DDD   s %%AA*)A*ciSr\r rs r rUzJsonModel.no_content_response5s r N)F rrrr r0r9r@rdr:rVpropertyrUr r r r^r^ s|  F%LI****&&&   Xr r^c:eZdZdZdZdZdZdZedZ dS)RawModelzModel 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. */*r_Nc|Sr\r r[s r rVzRawModel.deserializeFr cdSNr2r rps r rUzRawModel.no_content_responseIrr rrrr r0r9r@rVrrrUr r r rtrt:sYF%LIXr rtc:eZdZdZdZdZdZdZedZ dS) MediaModelzModel 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. rur_mediac|Sr\r r[s r rVzMediaModel.deserializeZrwr cdSryr rps r rUzMediaModel.no_content_response]rzr Nr{r r r r}r}NsYF%LIXr r}cFeZdZdZdZdZdZdZdZdZ e dZ dS) ProtocolBufferModelzModel class for protocol buffers. Serializes and de-serializes the binary protocol buffer sent in the HTTP request and response bodies. zapplication/x-protobufprotoc||_dS)a0Constructs 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)rprotocol_buffers r rdzProtocolBufferModel.__init__ms!0r c*|Sr\)SerializeToStringrYs r r:zProtocolBufferModel.serializeys++---r c6|j|Sr\)r FromStringr[s r rVzProtocolBufferModel.deserialize|s$//888r c*|Sr\rrps r rUz'ProtocolBufferModel.no_content_responses$$&&&r Nrqr r r rrbsw &F+LI 0 0 0...999''X'''r rc"i}|D]c\}}||d}|d||<#||kr:t|tikrt||||<]|||<cd|D]}||vr ||||<|S)a7Create 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)getrB makepatch)originalmodifiedpatchrMoriginal_valuemodified_values r rrs* E'~~//^!c400  !E#JJ ~ - -N##tBxx//&~~FFc ,c  '' h  !#E#J Lr )#r __future__r __author__r`loggingplatformrHr7googleapiclientrgoogleapiclient_versiongoogleapiclient.errorsrgoogle.api_core.version_headerrr6 ImportError __version__r4python_versionr5 getLoggerrr'r&r objectrr"r^rtr}rrr r r rs!'&&&&& 3  >>>>>>,,,,,,GGGGGGOOOOO+6%h%''  8 $ $DDD(((((F(((VggggggggT,,,,, ,,,^y((''''')'''D)))))s 5??