
    0                     p    d dl Z d dlZd dlZd Zd Zd Zd Zd Zd ZddZ	d	 Z
d
 Z G d de      Zd Zy)    Nc                      t        j                  | t        j                         t        j                  j	                  d       t        j                  j                          y)zWrite a message to standard output.

    Args:
        **message: ({str: object, ...}) A JSON message encoded in keyword
            arguments.
    
N)jsondumpsysstdoutwriteflush)messages    'platform/ext-runtime/nodejs/lib/comm.py
_write_msgr      s8     	IIgszz"JJTJJ    c                 $    t        d| |z         y )Nerrortyper   r   r   argss     r   r   r          GWt^4r   c                 $    t        d| |z         y )Nwarnr   r   r   s     r   r   r   #       FGdN3r   c                 $    t        d| |z         y )Ninfor   r   r   s     r   r   r   '   r   r   c                 $    t        d| |z         y )Ndebugr   r   r   s     r   r   r   +   r   r   c                 $    t        d| |z         y )Nprint_statusr   r   r   s     r   r   r   /   s    NGdN;r   c                 @    |t        d| |       yt        d|        y)a  Send runtime parameters back to the controller.

    Args:
        params: ({str: object, ...}) Set of runtime parameters.  Must be
            json-encodable.
        appinfo: ({str: object, ...}) 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)r   runtime_dataappinfo)r   r"   r   )paramsr#   s     r   send_runtime_paramsr%   3   s'     ,6"	$ 	,6Br   c                      t        d       t        t        j                  t        j
                  j                                     S )zRequest runtime parameters from the controller.

    Returns:
      (object) The runtime parameters represented as an object.
    
get_config)r   )r   dict_to_objectr   loadsr   stdinreadline r   r   r'   r'   F   s-     L!$**SYY%7%7%9:;;r   c                      G d dt               } |       }| j                         D ]-  \  }}t        |t              rt	        |      }t        |||       / |S )zConverts a dictionary to a python object.

    Converts key-values to attribute-values.

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

    Returns:
      (object)
    c                       e Zd Zy)dict_to_object.<locals>.ObjectN)__name__
__module____qualname__r,   r   r   Objectr/   [   s    r   r3   )object	iteritems
isinstancedictr(   setattr)	json_dictr3   objnamevals        r   r(   r(   P   sS     
(C((*	cc4 s##T3 + Jr   c                       e Zd ZdZd Zd Zy)RuntimeDefinitionRootzDAbstraction that allows us to access files in the runtime definiton.c                     || _         y N)root)selfpaths     r   __init__zRuntimeDefinitionRoot.__init__h   s	    	r   c                     t        t        j                  j                  | j                  g|       5 }|j                         cd d d        S # 1 sw Y   y xY wr@   )openosrC   joinrA   read)rB   r;   srcs      r   	read_filezRuntimeDefinitionRoot.read_filek   s7    "'',,tyy0401S88: 211s   AAN)r0   r1   r2   __doc__rD   rK   r,   r   r   r>   r>   e   s    Nr   r>   c                      t        d| |       y)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)r   filenamecontentsNr   )r;   rP   s     r   rN   rN   p   s     JAr   r@   )r   rG   r   r   r   r   r   r   r   r%   r'   r(   r4   r>   rN   r,   r   r   <module>rQ      sP     	 
	5445<C&<*F 	Br   