
    (ph(                     \    S r SSKJr  SrSSKJr  SSKJr   " S S\	5      r
 " S S	\	5      rg
)a  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.
    )absolute_importz$jcgregorio@google.com (Joe Gregorio))OrderedDict)_helpersc                       \ rS rSrSrS r\R                  " S5      SS j5       rS r	\R                  " S5      SS j5       r
S	 rSS
 jrSrg)SchemasG   zSchemas for an API.c                 @    UR                  S0 5      U l        0 U l        g)zvConstructor.

Args:
  discovery: object, Deserialized discovery document from which we pull
    out the named schema.
schemasN)getr
   pretty)self	discoverys     I/var/www/html/venv/lib/python3.13/site-packages/googleapiclient/schema.py__init__Schemas.__init__J   s     !}}Y3        Nc                    Uc  / nX;   a  SU-  $ UR                  U5        XR                  ;  a=  [        U R                  U   X#S9R	                  U R
                  5      U R                  U'   UR                  5         U R                  U   $ )aN  Get pretty printed object prototype from the schema name.

Args:
  name: string, Name of schema in the discovery document.
  seen: list of string, Names of schema already seen. Used to handle
    recursive definitions.

Returns:
  string, A string that contains a prototype object with
    comments that conforms to the given schema.
z# Object with schema name: %sdent)appendr   _SchemaToStructr
   to_str_prettyPrintByNamepop)r   nameseenr   s       r   r   Schemas._prettyPrintByNameV   s     <D<2T99D{{" /T"D!fT,,- KK 	
{{4  r   c                 *    U R                  U/ SS9SS $ )zGet 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.
r   )r   r   N)r   )r   r   s     r   prettyPrintByNameSchemas.prettyPrintByNamet   s#     &&t"1&=crBBr   c                 R    Uc  / n[        XUS9R                  U R                  5      $ )a/  Get pretty printed object prototype of schema.

Args:
  schema: object, Parsed JSON schema.
  seen: list of string, Names of schema already seen. Used to handle
    recursive definitions.

Returns:
  string, A string that contains a prototype object with
    comments that conforms to the given schema.
r   )r   r   r   r   schemar   r   s       r   _prettyPrintSchemaSchemas._prettyPrintSchema   s,     <Dv$7>>t?V?VWWr   c                 (    U R                  USS9SS $ )zGet 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.
r   r   Nr    )r&   )r   r%   s     r   prettyPrintSchemaSchemas.prettyPrintSchema   s!     &&vA&6s;;r   c                 8    U R                   R                  X5      $ )zGet deserialized JSON schema from the schema name.

Args:
  name: string, Schema name.
  default: object, return value if name not found.
)r
   r   )r   r   defaults      r   r   Schemas.get   s     ||..r   )r   r
   )Nr   )N)__name__
__module____qualname____firstlineno____doc__r   util
positionalr   r!   r&   r)   r   __static_attributes__ r   r   r   r   G   sV    
 
__Q! !:C 
__QX X"</r   r   c                   v    \ rS rSrSr\R                  " S5      SS j5       rS rS r	S r
S rS	 rS
 rS rSrg)r      z%Convert schema to a prototype object.   c                 R    / U l         SU l        Xl        X0l        SU l        X l        g)zConstructor.

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.
N)valuestringr%   r   
from_cacher   r$   s       r   r   _SchemaToStruct.__init__   s2     
   	  	r   c                 Z    U R                   R                  SU R                  -  US/5        g)zIAdd text as a line to the output.

Args:
  text: string, Text to output.
  
Nr;   extendr   r   texts     r   emit_SchemaToStruct.emit   s&     	

4$))+T489r   c                 X    U R                   R                  SU R                  -  U/5        g)z\Add text to the output, but with no line terminator.

Args:
  text: string, Text to output.
r@   NrB   rD   s     r   	emitBegin_SchemaToStruct.emitBegin   s$     	

4$))+T23r   c                 F   U(       ax  SSU R                   S-   -  -   S-   nUR                  5       nU Vs/ s H  oUR                  5       PM     nnUR                  U5      nU R                  R                  USUS/5        gU R                  R                  US/5        gs  snf )zAdd text and comment to the output with line terminator.

Args:
  text: string, Text to output.
  comment: string, Python comment.
rA   r@   r   z# z # N)r   
splitlinesrstripjoinr;   rC   )r   rE   commentdividerlinesxs         r   emitEnd_SchemaToStruct.emitEnd   s     TTYY]33d:G&&(E)./AXXZE/ll5)GJJtUGT:;JJtTl+	 0s   Bc                 .    U =R                   S-  sl         g)zIncrease indentation level.   Nr   r   s    r   indent_SchemaToStruct.indent       		Q	r   c                 .    U =R                   S-  sl         g)zDecrease indentation level.rV   Nr   rW   s    r   undent_SchemaToStruct.undent   rZ   r   c                    UR                  S5      nUS:X  a  U R                  SUR                  SS5      5        U R                  5         SU;   as  UR                  S0 5      n[        [	        UR                  5       5      5      nUR                  5        H*  u  pVU R                  SU-  5        U R                  U5        M,     O+SU;   a%  U R                  S	5        U R                  US   5        U R                  5         U R                  S
5        GOSU;   a  US   nUR                  SS5      nU R                  XpR                  S9n	U	R                  5       n
U R                  U
S   U5        U
SS  H"  nU R                  UR                  5       5        M$     GOUS:X  aB  UR                  SS5      nU R                  S[        U5      -  UR                  SS5      5        GOUS:X  aB  UR                  SS5      nU R                  S[        U5      -  UR                  SS5      5        GOUS:X  aB  UR                  SS5      nU R                  S[        U5      -  UR                  SS5      5        GO=US:X  aA  UR                  SS5      nU R                  S[        U5      -  UR                  SS5      5        OUS:X  a#  U R                  SUR                  SS5      5        OUS:X  a#  U R                  SUR                  SS5      5        OUS:X  ax  U R                  S UR                  S5      5        U R                  5         U R                  S5        U R                  US!   5        U R                  5         U R                  S"5        O&U R                  S#U-  5        U R                  SS5        SR                  U R                   5      U l        U R"                  $ )$zPrototype object based on the schema, in Python code with comments.

Args:
  schema: object, Parsed JSON schema file.

Returns:
  Prototype object based on the schema, in Python code with comments.
typeobject{description 
propertiesz"%s": additionalPropertiesz	"a_key": z},z$ref)r   r   rV   Nbooleanr,   zTrue or Falsez%s,r<   zA Stringz"%s",integer42numberz3.14nullzNone,anyz"",array[itemsz],zUnknown type! %s)r   rS   rX   r   sortedrn   rI   _to_str_implr\   rF   r=   r   rL   rM   strrN   r;   r<   )r   r%   styperd   sorted_propertiespnamepschema
schemaNamerb   spartsliner;   s                r   rp   _SchemaToStruct._to_str_impl   s    

6"HLLfjj;<KKMv%#ZZb9
$/z7G7G7I0J$K!&7&=&=&?NENN8e#34%%g. '@ (61{+!!&)?"@AKKMIIdOvJ **]B7K
;ALLNELLq;/ab			$++-( "iJJy/:ELLU+VZZr-JKhJJy*5ELL3u:-vzz-/LMiJJy$/ELLU+VZZr-JKhJJy&1ELLU+VZZr-JKf_LL&**]B"?@e^LL

=" =>gLLfjj78KKMNN2fWo.KKMIIdOII(501LLR ggdjj){{r   c                 D    Xl         U R                  U R                  5      $ )a  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.
)r=   rp   r%   )r   r=   s     r   r   _SchemaToStruct.to_str0  s     %  --r   )r   r=   r%   r   r<   r;   N)r   )r.   r/   r0   r1   r2   r3   r4   r   rF   rI   rS   rX   r\   rp   r   r5   r6   r   r   r   r      sD    /	__Q 8:4, <|.r   r   N)r2   
__future__r   
__author__collectionsr   googleapiclientr   r3   r`   r   r   r6   r   r   <module>r      s<   +X ' 4
 $ ,`/f `/FS.f S.r   