σ
Ύ^Yc           @@  s  d  Z  d d l m Z d d l Z d Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 d d l m Z e j e  Z e Z d   Z d	 e f d
     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d   Z d S(   sδ   Model objects for requests and responses.

Each API may support one or more serializations, such
as JSON, Atom, etc. The model classes are responsible
for converting between the wire format and the Python
object representation.
i    (   t   absolute_importNs$   jcgregorio@google.com (Joe Gregorio)(   t	   urlencode(   t   __version__(   t	   HttpErrorc           C@  s   t  d   d  S(   Ns"   You need to override this function(   t   NotImplementedError(    (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyt	   _abstract)   s    t   Modelc           B@  s    e  Z d  Z d   Z d   Z RS(   sΌ   Model base class.

  All Model classes should implement this interface.
  The Model serializes and de-serializes between a wire
  format such as JSON and a Python object representation.
  c         C@  s   t    d S(   sx  Updates outgoing requests with a serialized body.

    Args:
      headers: dict, request headers
      path_params: dict, parameters that appear in the request path
      query_params: dict, parameters that appear in the query
      body_value: object, the request body as a Python object, which must be
                  serializable.
    Returns:
      A tuple of (headers, path_params, query, body)

      headers: dict, request headers
      path_params: dict, parameters that appear in the request path
      query: string, query part of the request URI
      body: string, the body serialized in the desired wire format.
    N(   R   (   t   selft   headerst   path_paramst   query_paramst
   body_value(    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyt   request5   s    c         C@  s   t    d S(   sU  Convert the response wire format into a Python object.

    Args:
      resp: httplib2.Response, the HTTP response headers and status
      content: string, the body of the HTTP response

    Returns:
      The body de-serialized as a Python object.

    Raises:
      googleapiclient.errors.HttpError if a non 2xx response is received.
    N(   R   (   R   t   respt   content(    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyt   responseH   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR   -   s   	t	   BaseModelc           B@  se   e  Z d  Z d Z d Z d Z d Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z RS(	   sθ  Base model class.

  Subclasses should provide implementations for the "serialize" and
  "deserialize" methods, as well as values for the following class attributes.

  Attributes:
    accept: The value to use for the HTTP Accept header.
    content_type: The value to use for the HTTP Content-type header.
    no_content_response: The value to return when deserializing a 204 "No
        Content" response.
    alt_param: The value to supply as the "alt" query parameter for requests.
  c         C@  sα   t  rέ t j d  t j d  x0 t j |  D] \ } } t j d | |  q0 Wt j d  t j d  x0 t j |  D] \ } } t j d | |  q} Wt j d  t j d |  t j d |  t j d	  n  d
 S(   s:   Logs debugging information about the request if requested.s   --request-start--s   -headers-start-s   %s: %ss   -headers-end-s   -path-parameters-start-s   -path-parameters-end-s   body: %ss	   query: %ss   --request-end--N(   t   dump_request_responset   LOGGERt   infot   sixt	   iteritems(   R   R   R	   t   queryt   bodyt   ht   v(    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyt   _log_requestk   s    c         C@  s΄   |  j  |  } |  j | d <d | d <d | k rE | d c d 7<n
 d | d <| d c d t 7<| d	 k	 r |  j | d <|  j |  } n  |  j | | | |  | | | | f S(
   sl  Updates outgoing requests with a serialized body.

    Args:
      headers: dict, request headers
      path_params: dict, parameters that appear in the request path
      query_params: dict, parameters that appear in the query
      body_value: object, the request body as a Python object, which must be
                  serializable by json.
    Returns:
      A tuple of (headers, path_params, query, body)

      headers: dict, request headers
      path_params: dict, parameters that appear in the request path
      query: string, query part of the request URI
      body: string, the body serialized as JSON
    t   accepts   gzip, deflates   accept-encodings
   user-agentt    t    s"   google-api-python-client/%s (gzip)s   content-typeN(   t   _build_queryR   R   t   Nonet   content_typet	   serializeR   (   R   R   R	   R
   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR   {   s    

c         C@  sρ   |  j  d k	 r) | j i |  j  d 6 n  g  } x± t j |  D]  \ } } t |  t g   k r xy | D]( } | j d  } | j | | f  qj Wq? t | t j	  rΜ t
 | j  rΜ | j d  } n  | j | | f  q? Wd t |  S(   s¨   Builds a query string.

    Args:
      params: dict, the query parameters

    Returns:
      The query parameters properly encoded into an HTTP URI query string.
    t   alts   utf-8t   ?N(   t	   alt_paramR"   t   updateR   R   t   typet   encodet   appendt
   isinstancet	   text_typet   callableR   (   R   t   paramst   astuplest   keyt   valuet   x(    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR!      s    	!c         C@  sp   t  rl t j d  x0 t j |  D] \ } } t j d | |  q# W| r\ t j |  n  t j d  n  d S(   s;   Logs debugging information about the response if requested.s   --response-start--s   %s: %ss   --response-end--N(   R   R   R   R   R   (   R   R   R   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyt   _log_response²   s    c         C@  sf   |  j  | |  | j d k  rB | j d k r5 |  j S|  j |  St j d |  t | |   d S(   sU  Convert the response wire format into a Python object.

    Args:
      resp: httplib2.Response, the HTTP response headers and status
      content: string, the body of the HTTP response

    Returns:
      The body de-serialized as a Python object.

    Raises:
      googleapiclient.errors.HttpError if a non 2xx response is received.
    i,  iΜ   s    Content from bad request was: %sN(   R4   t   statust   no_content_responset   deserializeR   t   debugR   (   R   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR   Ό   s    c         C@  s   t    d S(   s·   Perform the actual Python object serialization.

    Args:
      body_value: object, the request body as a Python object.

    Returns:
      string, the body in serialized form.
    N(   R   (   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR$   Φ   s    	c         C@  s   t    d S(   sΡ   Perform the actual deserialization from response string to Python
    object.

    Args:
      content: string, the body of the HTTP response

    Returns:
      The body de-serialized as a Python object.
    N(   R   (   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR7   α   s    
N(   R   R   R   R"   R   R#   R6   R'   R   R   R!   R4   R   R$   R7   (    (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR   X   s   		 		
		t	   JsonModelc           B@  sM   e  Z d  Z d Z d Z d Z e d  Z d   Z d   Z	 e
 d    Z RS(   s   Model class for JSON.

  Serializes and de-serializes between JSON and the Python
  object representation of HTTP request and response bodies.
  s   application/jsont   jsonc         C@  s   | |  _  d S(   sq   Construct a JsonModel.

    Args:
      data_wrapper: boolean, wrap requests and responses in a data wrapper
    N(   t   _data_wrapper(   R   t   data_wrapper(    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyt   __init__ψ   s    c         C@  sA   t  | t  r4 d | k r4 |  j r4 i | d 6} n  t j |  S(   Nt   data(   R,   t   dictR;   R:   t   dumps(   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR$      s    	c         C@  sk   y | j  d  } Wn t k
 r& n Xt j |  } |  j rg t | t  rg d | k rg | d } n  | S(   Ns   utf-8R>   (   t   decodet   AttributeErrorR:   t   loadsR;   R,   R?   (   R   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR7     s    $c         C@  s   i  S(   N(    (   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR6     s    (   R   R   R   R   R#   R'   t   FalseR=   R$   R7   t   propertyR6   (    (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR9   ξ   s   		
t   RawModelc           B@  s8   e  Z d  Z d Z d Z d Z d   Z e d    Z	 RS(   sΚ   Model class for requests that don't return JSON.

  Serializes and de-serializes between JSON and the Python
  object representation of HTTP request, and returns the raw bytes
  of the response body.
  s   */*s   application/jsonc         C@  s   | S(   N(    (   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR7      s    c         C@  s   d S(   NR    (    (   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR6   #  s    N(
   R   R   R   R   R#   R"   R'   R7   RE   R6   (    (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyRF     s   	t
   MediaModelc           B@  s8   e  Z d  Z d Z d Z d Z d   Z e d    Z RS(   sΕ   Model class for requests that return Media.

  Serializes and de-serializes between JSON and the Python
  object representation of HTTP request, and returns the raw bytes
  of the response body.
  s   */*s   application/jsont   mediac         C@  s   | S(   N(    (   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR7   3  s    c         C@  s   d S(   NR    (    (   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR6   6  s    (	   R   R   R   R   R#   R'   R7   RE   R6   (    (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyRG   (  s   	t   ProtocolBufferModelc           B@  sJ   e  Z d  Z d Z d Z d Z d   Z d   Z d   Z e	 d    Z
 RS(   s   Model class for protocol buffers.

  Serializes and de-serializes the binary protocol buffer sent in the HTTP
  request and response bodies.
  s   application/x-protobuft   protoc         C@  s   | |  _  d S(   s  Constructs a ProtocolBufferModel.

    The serialzed protocol buffer returned in an HTTP response will be
    de-serialized using the given protocol buffer class.

    Args:
      protocol_buffer: The protocol buffer class used to de-serialize a
      response from the API.
    N(   t   _protocol_buffer(   R   t   protocol_buffer(    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR=   E  s    
c         C@  s
   | j    S(   N(   t   SerializeToString(   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR$   Q  s    c         C@  s   |  j  j |  S(   N(   RK   t
   FromString(   R   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR7   T  s    c         C@  s
   |  j    S(   N(   RK   (   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyR6   W  s    (   R   R   R   R   R#   R'   R=   R$   R7   RE   R6   (    (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyRI   ;  s   			c         C@  sΚ   i  } x t  j |   D]~ \ } } | j | d  } | d k rM d | | <q | | k r t |  t i   k r t | |  | | <q | | | <q q Wx+ | D]# } | |  k r | | | | <q q W| S(   s  Create a patch object.

  Some methods support PATCH, an efficient way to send updates to a resource.
  This method allows the easy construction of patch bodies by looking at the
  differences between a resource before and after it was modified.

  Args:
    original: object, the original deserialized resource
    modified: object, the modified deserialized resource
  Returns:
    An object that contains only the changes from original to modified, in a
    form suitable to pass to a PATCH method.

  Example usage:
    item = service.activities().get(postid=postid, userid=userid).execute()
    original = copy.deepcopy(item)
    item['object']['content'] = 'This is updated.'
    service.activities.patch(postid=postid, userid=userid,
      body=makepatch(original, item)).execute()
  N(   R   R   t   getR"   R)   t	   makepatch(   t   originalt   modifiedt   patchR1   t   original_valuet   modified_value(    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyRP   \  s    (   R   t
   __future__R    R   t
   __author__R:   t   loggingt   six.moves.urllib.parseR   t   googleapiclientR   t   googleapiclient.errorsR   t	   getLoggerR   R   RD   R   R   t   objectR   R   R9   RF   RG   RI   RP   (    (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/model.pyt   <module>   s$   	+'!