You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
263 lines
7.7 KiB
Python
263 lines
7.7 KiB
Python
"""
|
|
This type stub file was generated by pyright.
|
|
"""
|
|
|
|
"""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.
|
|
"""
|
|
__author__ = ...
|
|
HAS_API_VERSION = ...
|
|
_LIBRARY_VERSION = ...
|
|
_PY_VERSION = ...
|
|
LOGGER = ...
|
|
dump_request_response = ...
|
|
class Model:
|
|
"""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.
|
|
"""
|
|
def request(self, headers, path_params, query_params, body_value): # -> None:
|
|
"""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.
|
|
"""
|
|
...
|
|
|
|
def response(self, resp, content): # -> None:
|
|
"""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.
|
|
"""
|
|
...
|
|
|
|
|
|
|
|
class BaseModel(Model):
|
|
"""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.
|
|
"""
|
|
accept = ...
|
|
content_type = ...
|
|
no_content_response = ...
|
|
alt_param = ...
|
|
def request(self, headers, path_params, query_params, body_value, api_version=...): # -> tuple[Any, Any, Any, Any | None]:
|
|
"""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
|
|
"""
|
|
...
|
|
|
|
def response(self, resp, content): # -> None:
|
|
"""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.
|
|
"""
|
|
...
|
|
|
|
def serialize(self, body_value): # -> None:
|
|
"""Perform the actual Python object serialization.
|
|
|
|
Args:
|
|
body_value: object, the request body as a Python object.
|
|
|
|
Returns:
|
|
string, the body in serialized form.
|
|
"""
|
|
...
|
|
|
|
def deserialize(self, content): # -> None:
|
|
"""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.
|
|
"""
|
|
...
|
|
|
|
|
|
|
|
class JsonModel(BaseModel):
|
|
"""Model class for JSON.
|
|
|
|
Serializes and de-serializes between JSON and the Python
|
|
object representation of HTTP request and response bodies.
|
|
"""
|
|
accept = ...
|
|
content_type = ...
|
|
alt_param = ...
|
|
def __init__(self, data_wrapper=...) -> None:
|
|
"""Construct a JsonModel.
|
|
|
|
Args:
|
|
data_wrapper: boolean, wrap requests and responses in a data wrapper
|
|
"""
|
|
...
|
|
|
|
def serialize(self, body_value): # -> str:
|
|
...
|
|
|
|
def deserialize(self, content): # -> Any:
|
|
...
|
|
|
|
@property
|
|
def no_content_response(self): # -> dict[Any, Any]:
|
|
...
|
|
|
|
|
|
|
|
class RawModel(JsonModel):
|
|
"""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.
|
|
"""
|
|
accept = ...
|
|
content_type = ...
|
|
alt_param = ...
|
|
def deserialize(self, content):
|
|
...
|
|
|
|
@property
|
|
def no_content_response(self): # -> Literal['']:
|
|
...
|
|
|
|
|
|
|
|
class MediaModel(JsonModel):
|
|
"""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.
|
|
"""
|
|
accept = ...
|
|
content_type = ...
|
|
alt_param = ...
|
|
def deserialize(self, content):
|
|
...
|
|
|
|
@property
|
|
def no_content_response(self): # -> Literal['']:
|
|
...
|
|
|
|
|
|
|
|
class ProtocolBufferModel(BaseModel):
|
|
"""Model class for protocol buffers.
|
|
|
|
Serializes and de-serializes the binary protocol buffer sent in the HTTP
|
|
request and response bodies.
|
|
"""
|
|
accept = ...
|
|
content_type = ...
|
|
alt_param = ...
|
|
def __init__(self, protocol_buffer) -> None:
|
|
"""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.
|
|
"""
|
|
...
|
|
|
|
def serialize(self, body_value):
|
|
...
|
|
|
|
def deserialize(self, content):
|
|
...
|
|
|
|
@property
|
|
def no_content_response(self):
|
|
...
|
|
|
|
|
|
|
|
def makepatch(original, modified): # -> dict[Any, Any]:
|
|
"""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()
|
|
"""
|
|
...
|
|
|