
                             d dl mZ d dl mZ d dl mZ d dlZd dlZd dlZd dlZ G d de      Z	d Z
d Zd	 Zd
 Zd Zd Zd ZddZd Zd Zd Z G d de      Zd ZddZy)    )absolute_import)division)print_functionNc                        e Zd ZdZd Zd ZeZy)
JSONObjecta#  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                      y N )selfattrs     'lib/third_party/gae_ext_runtime/comm.py__getattr__zJSONObject.__getattr__%   s        c                     i }t        j                  | j                        D ]%  \  }}|j                  d      rt	        |      ||<   ' |S )N_)six	iteritems__dict__
startswith_make_serializable)r   resultr   vals       r   to_dictzJSONObject.to_dict(   sC    t}}5ID#??3'1#6t 6 r   N)__name__
__module____qualname____doc__r   r   ToDictr
   r   r   r   r      s     Fr   r   c                 F    t        | t              r| j                         S | S )z&Converts objects to serializable form.)
isinstancer   r   )objs    r   r   r   3   s    #z"{{}
r   c                      t        j                  | t        j                  t               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.
    )default
N)jsondumpsysstdoutr   writeflush)messages    r   
_write_msgr,   ;   s;     	IIgszz+=>JJTJJr   c                 $    t        d| |z         y )Nerrortyper+   r,   r+   argss     r   r.   r.   G       GWt^4r   c                 $    t        d| |z         y )Nwarnr/   r1   r2   s     r   r6   r6   K       FGdN3r   c                 $    t        d| |z         y )Ninfor/   r1   r2   s     r   r9   r9   O   r7   r   c                 $    t        d| |z         y )Ndebugr/   r1   r2   s     r   r;   r;   S   r4   r   c                 $    t        d| |z         y )Nprint_statusr/   r1   r2   s     r   r=   r=   W   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, ...} 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)r0   runtime_dataappinfo)r0   r@   r1   )paramsrA   s     r   send_runtime_paramsrC   [   s'     ,6"	$ 	,6Br   c                     t        d|        y)zzSend updated Docker context to the controller.

    Args:
        path: (str) new directory to use as docker context.
    set_docker_context)r0   pathNr1   )rF   s    r   rE   rE   m   s     (t4r   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)r0   )r,   dict_to_objectr%   loadsr'   stdinreadliner
   r   r   rH   rH   u   s-     L!$**SYY%7%7%9:;;r   c                     t               }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:
      (JSONObject)
    )r   r   r   r    dictrI   setattr)	json_dictr!   namer   s       r   rI   rI      sI     ,C]]9-	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 r	   )root)r   rF   s     r   __init__zRuntimeDefinitionRoot.__init__   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osrF   joinrU   read)r   rQ   srcs      r   	read_filezRuntimeDefinitionRoot.read_file   s7    "'',,tyy0401S88: 211s   AAN)r   r   r   r   rV   r]   r
   r   r   rS   rS      s    Nr   rS   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)r0   filenamecontentsNr1   )rQ   ra   s     r   r_   r_      s     JAr   c                     i }| |d<   |||d<   t        dddi| t        j                  t        j                  j                               d   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#   r0   
query_userr   r
   )r,   r%   rJ   r'   rK   rL   )rc   r#   kwargss      r   rd   rd      sT     FF8#y+L+F+::cii((*+H55r   r	   )
__future__r   r   r   r%   rY   r'   r   objectr   r   r,   r.   r6   r9   r;   r=   rC   rE   rH   rI   rS   r_   rd   r
   r   r   <module>rh      sw   $ '  %  	 
 
 0	5445<C$5<&F 	B6r   