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.

161 lines
4.2 KiB
Python

"""
This type stub file was generated by pyright.
"""
from googleapiclient import _helpers as util
"""Schema processing for discovery based APIs
Schemas holds an APIs discovery schemas. It can return those schema as
deserialized JSON objects, or pretty print them as prototype objects that
conform to the schema.
For example, given the schema:
schema = \"\"\"{
"Foo": {
"type": "object",
"properties": {
"etag": {
"type": "string",
"description": "ETag of the collection."
},
"kind": {
"type": "string",
"description": "Type of the collection ('calendar#acl').",
"default": "calendar#acl"
},
"nextPageToken": {
"type": "string",
"description": "Token used to access the next
page of this result. Omitted if no further results are available."
}
}
}
}\"\"\"
s = Schemas(schema)
print s.prettyPrintByName('Foo')
Produces the following output:
{
"nextPageToken": "A String", # Token used to access the
# next page of this result. Omitted if no further results are available.
"kind": "A String", # Type of the collection ('calendar#acl').
"etag": "A String", # ETag of the collection.
},
The constructor takes a discovery document in which to look up named schema.
"""
__author__ = ...
class Schemas:
"""Schemas for an API."""
def __init__(self, discovery) -> None:
"""Constructor.
Args:
discovery: object, Deserialized discovery document from which we pull
out the named schema.
"""
...
def prettyPrintByName(self, name):
"""Get pretty printed object prototype from the schema name.
Args:
name: string, Name of schema in the discovery document.
Returns:
string, A string that contains a prototype object with
comments that conforms to the given schema.
"""
...
def prettyPrintSchema(self, schema): # -> LiteralString:
"""Get pretty printed object prototype of schema.
Args:
schema: object, Parsed JSON schema.
Returns:
string, A string that contains a prototype object with
comments that conforms to the given schema.
"""
...
def get(self, name, default=...):
"""Get deserialized JSON schema from the schema name.
Args:
name: string, Schema name.
default: object, return value if name not found.
"""
...
class _SchemaToStruct:
"""Convert schema to a prototype object."""
@util.positional(3)
def __init__(self, schema, seen, dent=...) -> None:
"""Constructor.
Args:
schema: object, Parsed JSON schema.
seen: list, List of names of schema already seen while parsing. Used to
handle recursive definitions.
dent: int, Initial indentation depth.
"""
...
def emit(self, text): # -> None:
"""Add text as a line to the output.
Args:
text: string, Text to output.
"""
...
def emitBegin(self, text): # -> None:
"""Add text to the output, but with no line terminator.
Args:
text: string, Text to output.
"""
...
def emitEnd(self, text, comment): # -> None:
"""Add text and comment to the output with line terminator.
Args:
text: string, Text to output.
comment: string, Python comment.
"""
...
def indent(self): # -> None:
"""Increase indentation level."""
...
def undent(self): # -> None:
"""Decrease indentation level."""
...
def to_str(self, from_cache): # -> LiteralString:
"""Prototype object based on the schema, in Python code with comments.
Args:
from_cache: callable(name, seen), Callable that retrieves an object
prototype for a schema with the given name. Seen is a list of schema
names already seen as we recursively descend the schema definition.
Returns:
Prototype object based on the schema, in Python code with comments.
The lines of the code will all be properly indented.
"""
...