
    ,                         S SK r S SKrS SKr " S S\5      rS rS rS rS rS r	S	 r
S
 rSS jrS rS r " S S\5      rS rSS jrg)    Nc                   (    \ rS rSrSrS rS r\rSrg)
JSONObject   a  Wrapper for a JSON object.

Presents a JSON object as a python object (where fields are attributes)
instead of a dictionary.  Undefined attributes produce a value of None
instead of an AttributeError.

Note that attribute names beginning with an underscore are excluded.
c                     g N )selfattrs     'platform/ext-runtime/python/lib/comm.py__getattr__JSONObject.__getattr__!   s        c                     0 nU R                   R                  5        H*  u  p#UR                  S5      (       a  M  [        U5      X'   M,     U$ )N_)__dict__	iteritems
startswith_make_serializable)r	   resultr
   vals       r   to_dictJSONObject.to_dict$   sB    002ID??3''1#6 3 r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r   ToDict__static_attributes__r   r   r   r   r      s     Fr   r   c                 P    [        U [        5      (       a  U R                  5       $ U $ )z&Converts objects to serializable form.)
isinstancer   r   )objs    r   r   r   /   s     #z""{{}
r   c                      [         R                  " U [        R                  [        S9  [        R                  R                  S5        [        R                  R                  5         g)zWrite a message to standard output.

Args:
    **message: ({str: object, ...}) A JSON message encoded in keyword
        arguments.
)default
N)jsondumpsysstdoutr   writeflush)messages    r   
_write_msgr-   7   s;     	IIgszz+=>JJTJJr   c                     [        SX-  S9  g )Nerrortyper,   r-   r,   argss     r   r/   r/   C       GW^4r   c                     [        SX-  S9  g )Nwarnr0   r2   r3   s     r   r7   r7   G       FGN3r   c                     [        SX-  S9  g )Ninfor0   r2   r3   s     r   r:   r:   K   r8   r   c                     [        SX-  S9  g )Ndebugr0   r2   r3   s     r   r<   r<   O   r5   r   c                     [        SX-  S9  g )Nprint_statusr0   r2   r3   s     r   r>   r>   S   s    NGN;r   c                 6    Ub  [        SU US9  g[        SU S9  g)a  Send runtime parameters back to the controller.

Args:
    params: ({str: object, ...}) Set of runtime parameters.  Must be
        json-encodable.
    appinfo: ({str: object, ...} or None) Contents of the app.yaml file to
        be produced by the runtime definition.  Required fields may be
        added to this by the framework, the only thing an application
        needs to provide is the "runtime" field and any additional data
        fields.
Nruntime_parameters)r1   runtime_dataappinfo)r1   rA   r2   )paramsrB   s     r   send_runtime_paramsrD   W   s'     ,6"	$ 	,6Br   c                      [        SS9  [        [        R                  " [        R
                  R                  5       5      5      $ )zvRequest runtime parameters from the controller.

Returns:
  (object) The runtime parameters represented as an object.

get_config)r1   )r-   dict_to_objectr&   loadsr(   stdinreadliner   r   r   rF   rF   j   s-     L!$**SYY%7%7%9:;;r   c                     [        5       nU R                  5        H1  u  p#[        U[        5      (       a  [	        U5      n[        XU5        M3     U$ )zConverts a dictionary to a python object.

Converts key-values to attribute-values.

Args:
  json_dict: ({str: object, ...})

Returns:
  (JSONObject)
)r   r   r!   dictrG   setattr)	json_dictr"   namer   s       r   rG   rG   t   sH     ,C((*	c4  s##3 + Jr   c                   $    \ rS rSrSrS rS rSrg)RuntimeDefinitionRoot   zDAbstraction that allows us to access files in the runtime definiton.c                     Xl         g r   root)r	   paths     r   __init__RuntimeDefinitionRoot.__init__   s    	r   c                     [        [        R                  R                  " U R                  /UQ76 5       nUR                  5       sS S S 5        $ ! , (       d  f       g = fr   )openosrV   joinrU   read)r	   rO   srcs      r   	read_fileRuntimeDefinitionRoot.read_file   s7    "'',,tyy0401S88: 211s   A
ArT   N)r   r   r   r   r   rW   r_   r   r   r   r   rQ   rQ      s    Nr   rQ   c                     [        SXS9  g)zGenerate the file.

This writes the file to be generated back to the controller.

Args:
    name: (str) The UNIX-style relative path of the file.
    contents: (str) The complete file contents.
gen_file)r1   filenamecontentsNr2   )rO   rd   s     r   rb   rb      s     JAr   c                     0 nXS'   Ub  XS'   [        SSS0UD6  [        R                  " [        R                  R                  5       5      S   $ )zQuery the user for data.

Args:
    prompt: (str) Prompt to display to the user.
    default: (str or None) Default value to use if the user doesn't input
        anything.

Returns:
    (str) Value returned by the user.
promptr$   r1   
query_userr   r   )r-   r&   rH   r(   rI   rJ   )rf   r$   kwargss      r   rg   rg      sP     F8#y+L+F+::cii((*+H55r   r   )r&   r[   r(   objectr   r   r-   r/   r7   r:   r<   r>   rD   rF   rG   rQ   rb   rg   r   r   r   <module>rj      sf   $  	 
 0	5445<C&<&F 	B6r   