
^Yc        
   @@  s  d  Z  d d l m Z d d l Z d d l m Z d Z d d d d	 g Z d d
 l m Z d d l m	 Z	 d d l
 m Z m Z m Z m Z m Z d d l Z y d d l m Z Wn! e k
 r d d l m Z n Xd 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 d d l Z d d l Z d d l Z d d l  Z  d d l! m" Z" d d l! m# Z# d d l$ m% Z% d d l$ m& Z& d d l$ m' Z' d d l$ m( Z( d d l$ m) Z) d d l$ m* Z* d d l+ m, Z, d d l+ m- Z- d d l+ m. Z. d d l+ m/ Z/ d d l+ m0 Z0 d d l+ m1 Z1 d d l+ m2 Z2 d d  l3 m4 Z4 d d! l3 m5 Z5 d d" l3 m6 Z6 d d# l7 m8 Z8 d d$ l9 m: Z: y$ d d% l; m< Z< d d& l; m= Z= Wn1 e k
 rd d% l> m< Z< d d& l> m= Z= n Xd' e _? e j@ eA  ZB e jC d(  ZD e jC d)  ZE d* ZF eF ZG d+ ZH d, ZI eJ d- d. d/ g  ZK i d0 d1 6d2 d3 6d4 d5 6d6 d7 6ZL i d8 d9 6d: d; 6eM d< 6ZN i d= d9 6d> d; 6eO d< 6ZP i d? d9 6d> d; 6eO d< 6ZQ eJ d@ dA dB dC g  ZR i d> d; 6dD dE 6ZS eJ dF g  ZT dG e f dH     YZU dI   ZV dJ   ZW e= dK  d eF d d e0 d eM d dL   ZY d dM  ZZ e= d'  d d d d d e0 d dN   Z[ dO   Z\ dP   Z] dQ   Z^ dR   Z_ dS   Z` dT   Za dU   Zb dV ec f dW     YZd dX   Ze dY   Zf dZ ec f d[     YZg d S(\   sV   Client for discovery based APIs.

A client library for Google's discovery based APIs.
i    (   t   absolute_importN(   t   zips$   jcgregorio@google.com (Joe Gregorio)t   buildt   build_from_documentt   fix_method_namet	   key2param(   t   BytesIO(   t   http_client(   t	   urlencodet   urlparset   urljoint
   urlunparset	   parse_qsl(   t   BytesGenerator(   t	   Generator(   t   MIMEMultipart(   t   MIMENonMultipart(   t   _auth(   t	   mimeparse(   t	   HttpError(   t   InvalidJsonError(   t   MediaUploadSizeError(   t   UnacceptableMimeTypeError(   t   UnknownApiNameOrVersion(   t   UnknownFileType(   t
   build_http(   t   BatchHttpRequest(   t   HttpMock(   t   HttpMockSequence(   t   HttpRequest(   t   MediaFileUpload(   t   MediaUpload(   t	   JsonModel(   t
   MediaModel(   t   RawModel(   t   Schemas(   t   GoogleCredentials(   t   _add_query_parameter(   t
   positionali   s   {[^}]*}s   [a-zA-Z0-9_-]+sD   https://www.googleapis.com/discovery/v1/apis/{api}/{apiVersion}/restsA   https://{api}.googleapis.com/$discovery/rest?version={apiVersion}s)   A description of how to use this functiont   PUTt   POSTt   PATCHi
   t   KBi   t   MBi   t   GBi(   t   TBs   The request body.t   descriptiont   objectt   typet   requiredsO   The filename of the media request body, or an instance of a MediaUpload object.t   stringsP   The MIME type of the media request body, or an instance of a MediaUpload object.t   tracet   ppt   useript   strictt   queryt   locationt   bodyt   _BytesGeneratorc           B@  s   e  Z e j Z RS(    (   t   __name__t
   __module__R   t   writet   _write_lines(    (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR:      s   c         C@  s+   t  j |   s |  t k r# |  d S|  Sd S(   s   Fix method names to avoid reserved word conflicts.

  Args:
    name: string, method name.

  Returns:
    The name with a '_' prefixed if the name is a reserved word.
  t   _N(   t   keywordt	   iskeywordt   RESERVED_WORDS(   t   name(    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR      s    	c         C@  sy   g  } t  |   }  |  d j   s2 | j d  n  x7 |  D]/ } | j   r[ | j |  q9 | j d  q9 Wd j |  S(   s   Converts key names into parameter names.

  For example, converting "max-results" -> "max_results"

  Args:
    key: string, the method key name.

  Returns:
    A safe method name based on the key name.
  i    t   xR?   t    (   t   listt   isalphat   appendt   isalnumt   join(   t   keyt   resultt   c(    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR      s    i   c
         C@  s   i |  d 6| d 6}
 | d
 k r, t   } n | } x | t f D] } t j | |
  } yG t | | | |	  } t | d | d | d | d | d | d | SWq? t k
 r } | j j	 t
 j k r q? q |  q? Xq? Wt d	 |  | f   d
 S(   sA  Construct a Resource for interacting with an API.

  Construct a Resource object for interacting with an API. The serviceName and
  version are the names from the Discovery service.

  Args:
    serviceName: string, name of the service.
    version: string, the version of the service.
    http: httplib2.Http, An instance of httplib2.Http or something that acts
      like it that HTTP requests will be made through.
    discoveryServiceUrl: string, a URI Template that points to the location of
      the discovery service. It should have two parameters {api} and
      {apiVersion} that when filled in produce an absolute URI to the discovery
      document for that service.
    developerKey: string, key obtained from
      https://code.google.com/apis/console.
    model: googleapiclient.Model, converts to and from the wire format.
    requestBuilder: googleapiclient.http.HttpRequest, encapsulator for an HTTP
      request.
    credentials: oauth2client.Credentials or
      google.auth.credentials.Credentials, credentials to be used for
      authentication.
    cache_discovery: Boolean, whether or not to cache the discovery doc.
    cache: googleapiclient.discovery_cache.base.CacheBase, an optional
      cache object for the discovery documents.

  Returns:
    A Resource object with methods for interacting with the service.
  t   apit
   apiVersiont   baset   httpt   developerKeyt   modelt   requestBuildert   credentialss   name: %s  version: %sN(   t   NoneR   t   V2_DISCOVERY_URIt   uritemplatet   expandt   _retrieve_discovery_docR   R   t   respt   statusR   t	   NOT_FOUNDR   (   t   serviceNamet   versionRQ   t   discoveryServiceUrlRR   RS   RT   RU   t   cache_discoveryt   cachet   paramst   discovery_httpt   discovery_urlt   requested_urlt   contentt   e(    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR      s(    (
c         C@  sp  | rf d d l  m } d d l m } | d k rA | j   } n  | rf | j |   } | rc | Sqf n  |  } d t j k r t |  d t j d  } n  t	 j
 d |  | j |  \ } } | j d k r t | | d |  n  y | j d	  } Wn t k
 r	n Xy t j |  }	 Wn- t k
 rL}
 t	 j d
 |  t    n X| rl| rl| j |  |  n  | S(   s  Retrieves the discovery_doc from cache or the internet.

  Args:
    url: string, the URL of the discovery document.
    http: httplib2.Http, An instance of httplib2.Http or something that acts
      like it through which HTTP requests will be made.
    cache_discovery: Boolean, whether or not to cache the discovery doc.
    cache: googleapiclient.discovery_cache.base.Cache, an optional cache
      object for the discovery documents.

  Returns:
    A unicode string representation of the discovery document.
  i   (   t   discovery_cache(   RP   t   REMOTE_ADDRt   userIps   URL being requested: GET %si  t   uris   utf-8s   Failed to parse as JSON: N(   RE   Ri   RP   RV   t
   autodetectt   gett   ost   environR%   t   loggert   infot   requestR\   R   t   decodet   AttributeErrort   jsont   loadst
   ValueErrort   errorR   t   set(   t   urlRQ   Ra   Rb   Ri   RP   Rg   t
   actual_urlR[   t   serviceRh   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyRZ      s8    
c         C@  s  | d k	 r' | d k	 r' t d   n  t |  t j  rK t j |   }  n  d |  k r t | t t f  r t	 j
 d d d d  t    n  t |  d |  d  } t |   } | d k rNt |  j d i   j d	 i   j d
 i   j    }	 |	 rB| rB| d k rt j   } n  t j | |	  } t j |  } qNt   } n  | d k r|  j d g   }
 t d |
 k  } n  t d | d | d | d | d | d |  d |  d |  S(   s  Create a Resource for interacting with an API.

  Same as `build()`, but constructs the Resource object from a discovery
  document that is it given, as opposed to retrieving one over HTTP.

  Args:
    service: string or object, the JSON discovery document describing the API.
      The value passed in may either be the JSON string or the deserialized
      JSON.
    base: string, base URI for all HTTP requests, usually the discovery URI.
      This parameter is no longer used as rootUrl and servicePath are included
      within the discovery document. (deprecated)
    future: string, discovery document with future capabilities (deprecated).
    http: httplib2.Http, An instance of httplib2.Http or something that acts
      like it that HTTP requests will be made through.
    developerKey: string, Key for controlling API usage, generated
      from the API Console.
    model: Model class instance that serializes and de-serializes requests and
      responses.
    requestBuilder: Takes an http request and packages it up to be executed.
    credentials: oauth2client.Credentials or
      google.auth.credentials.Credentials, credentials to be used for
      authentication.

  Returns:
    A Resource object with methods for interacting with the service.
  s6   Arguments http and credentials are mutually exclusive.t   rootUrls2   You are using HttpMock or HttpMockSequence withouts7   having the service discovery doc in cache. Try calling s3   build() without mocking once first to populate the s   cache.t   servicePatht   autht   oauth2t   scopest   featurest   dataWrapperRQ   t   baseUrlRS   RR   RT   t   resourceDesct   rootDesct   schemaN(   RV   Rx   t
   isinstancet   sixt   string_typesRv   Rw   R   R   Rq   Ry   R   R
   R#   RF   Rn   t   keysR   t   default_credentialst   with_scopest   authorized_httpR   R    t   Resource(   R}   RP   t   futureRQ   RR   RS   RT   RU   R   R   R   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR   '  s6    &3c         C@  s   | d k rM t  |   t  d  k s< t  |   t  d  k r@ |  St |   Sn | d k ri t t |    S| d k r t t |    S| d k r t t |    j   St  |   t  d  k s t  |   t  d  k r |  St |   Sd S(   sV  Convert value to a string based on JSON Schema type.

  See http://tools.ietf.org/html/draft-zyp-json-schema-03 for more details on
  JSON Schema.

  Args:
    value: any, the value to convert
    schema_type: string, the type that value should be interpreted as

  Returns:
    A string representation of 'value' based on the schema_type.
  R2   RE   u    t   integert   numbert   booleanN(   R0   t   strt   intt   floatt   boolt   lower(   t   valuet   schema_type(    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   _cast  s    00c         C@  sa   t  |   d k  r d S|  d j   } t j |  } | d k	 rS t |  d   | >St |   Sd S(   s   Convert a string media size, such as 10GB or 3TB into an integer.

  Args:
    maxSize: string, size as a string, such as 2MB or 7GB.

  Returns:
    The size as an integer value.
  i   i    iN(   t   lent   uppert   _MEDIA_SIZE_BIT_SHIFTSRn   RV   R   (   t   maxSizet   unitst	   bit_shift(    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   _media_size_to_long  s    	c         C@  s%   d i |  d d 6|  d d 6| d 6S(   s  Creates an absolute media path URL.

  Constructed using the API root URI and service path from the discovery
  document and the relative path for the API method.

  Args:
    root_desc: Dictionary; the entire original deserialized discovery document.
    path_url: String; the relative URL for the API method. Relative to the API
        root, which is specified in the discovery document.

  Returns:
    String; the absolute URI for media upload for the API method.
  s'   %(root)supload/%(service_path)s%(path)sR~   t   rootR   t   service_patht   path(    (   t	   root_desct   path_url(    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   _media_path_url_from_info  s    c         C@  s   |  j  d i   } x3 t j | j d i    D] \ } } | | | <q. Wx t D] } t j   | | <qO W| t k r d |  k r t j   } | j	 |  d  | | d <n  | S(   s  Updates parameters of an API method with values specific to this library.

  Specifically, adds whatever global parameters are specified by the API to the
  parameters for the individual method. Also adds parameters which don't
  appear in the discovery document, but are available to all discovery based
  APIs (these are listed in STACK_QUERY_PARAMETERS).

  SIDE EFFECTS: This updates the parameters dictionary object in the method
  description.

  Args:
    method_desc: Dictionary with metadata describing an API method. Value comes
        from the dictionary of methods stored in the 'methods' key in the
        deserialized discovery document.
    root_desc: Dictionary; the entire original deserialized discovery document.
    http_method: String; the HTTP method used to call the API method described
        in method_desc.

  Returns:
    The updated Dictionary stored in the 'parameters' key of the method
        description dictionary.
  t
   parametersRs   R9   (
   t
   setdefaultR   t	   iteritemsRn   t   STACK_QUERY_PARAMETERSt#   STACK_QUERY_PARAMETER_DEFAULT_VALUEt   copyt   HTTP_PAYLOAD_METHODSt   BODY_PARAMETER_DEFAULT_VALUEt   update(   t   method_descR   t   http_methodR   RC   R.   R9   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   _fix_up_parameters  s    (c         C@  s   |  j  d i   } | j  d g   } t | j  d d   } d	 } | r t | |  } t j   | d <t j   | d <d | k r t | d d <q n  | | | f S(
   s  Adds 'media_body' and 'media_mime_type' parameters if supported by method.

  SIDE EFFECTS: If the method supports media upload and has a required body,
  sets body to be optional (required=False) instead. Also, if there is a
  'mediaUpload' in the method description, adds 'media_upload' key to
  parameters.

  Args:
    method_desc: Dictionary with metadata describing an API method. Value comes
        from the dictionary of methods stored in the 'methods' key in the
        deserialized discovery document.
    root_desc: Dictionary; the entire original deserialized discovery document.
    path_url: String; the relative URL for the API method. Relative to the API
        root, which is specified in the discovery document.
    parameters: A dictionary describing method parameters for method described
        in method_desc.

  Returns:
    Triple (accept, max_size, media_path_url) where:
      - accept is a list of strings representing what content types are
        accepted for media upload. Defaults to empty list if not in the
        discovery document.
      - max_size is a long representing the max size in bytes allowed for a
        media upload. Defaults to 0L if not in the discovery document.
      - media_path_url is a String; the absolute URI for media upload for the
        API method. Constructed using the API root URI and service path from
        the discovery document and the relative path for the API method. If
        media upload is not supported, this is None.
  t   mediaUploadt   acceptR   RE   t
   media_bodyt   media_mime_typeR9   R1   N(   Rn   R   RV   R   t"   MEDIA_BODY_PARAMETER_DEFAULT_VALUER   t'   MEDIA_MIME_TYPE_PARAMETER_DEFAULT_VALUEt   False(   R   R   R   R   t   media_uploadR   t   max_sizet   media_path_url(    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   _fix_up_media_upload  s    c   	      C@  sd   |  d } |  d } |  d } t  |  | |  } t |  | | |  \ } } } | | | | | | f S(   s3  Updates a method description in a discovery document.

  SIDE EFFECTS: Changes the parameters dictionary in the method description with
  extra parameters which are used locally.

  Args:
    method_desc: Dictionary with metadata describing an API method. Value comes
        from the dictionary of methods stored in the 'methods' key in the
        deserialized discovery document.
    root_desc: Dictionary; the entire original deserialized discovery document.

  Returns:
    Tuple (path_url, http_method, method_id, accept, max_size, media_path_url)
    where:
      - path_url is a String; the relative URL for the API method. Relative to
        the API root, which is specified in the discovery document.
      - http_method is a String; the HTTP method used to call the API method
        described in the method description.
      - method_id is a String; the name of the RPC method associated with the
        API method, and is in the method description in the 'id' key.
      - accept is a list of strings representing what content types are
        accepted for media upload. Defaults to empty list if not in the
        discovery document.
      - max_size is a long representing the max size in bytes allowed for a
        media upload. Defaults to 0L if not in the discovery document.
      - media_path_url is a String; the absolute URI for media upload for the
        API method. Constructed using the API root URI and service path from
        the discovery document and the relative path for the API method. If
        media upload is not supported, this is None.
  R   t
   httpMethodt   id(   R   R   (	   R   R   R   R   t	   method_idR   R   R   R   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   _fix_up_method_description!  s    


c         C@  sq   | j  d  s | j  d  r+ t |  |  S|  j d  r@ |  n |  d } | j  d  rc | d n | } | | S(   s8   Custom urljoin replacement supporting : before / in url.s   http://s   https://t   /i   (   t
   startswithR
   t   endswith(   RP   R{   t   new_baset   new_url(    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   _urljoinN  s
    
t   ResourceMethodParametersc           B@  s    e  Z d  Z d   Z d   Z RS(   s  Represents the parameters associated with a method.

  Attributes:
    argmap: Map from method parameter name (string) to query parameter name
        (string).
    required_params: List of required parameters (represented by parameter
        name as string).
    repeated_params: List of repeated parameters (represented by parameter
        name as string).
    pattern_params: Map from method parameter name (string) to regular
        expression (as a string). If the pattern is set for a parameter, the
        value for that parameter must match the regular expression.
    query_params: List of parameters (represented by parameter name as string)
        that will be used in the query string.
    path_params: Set of parameters (represented by parameter name as string)
        that will be used in the base URL path.
    param_types: Map from method parameter name (string) to parameter type. Type
        can be any valid JSON schema type; valid values are 'any', 'array',
        'boolean', 'integer', 'number', 'object', or 'string'. Reference:
        http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1
    enum_params: Map from method parameter name (string) to list of strings,
       where each list of strings is the list of acceptable enum values.
  c         C@  s\   i  |  _  g  |  _ g  |  _ i  |  _ g  |  _ t   |  _ i  |  _ i  |  _ |  j	 |  d S(   sE  Constructor for ResourceMethodParameters.

    Sets default values and defers to set_parameters to populate.

    Args:
      method_desc: Dictionary with metadata describing an API method. Value
          comes from the dictionary of methods stored in the 'methods' key in
          the deserialized discovery document.
    N(
   t   argmapt   required_paramst   repeated_paramst   pattern_paramst   query_paramsRz   t   path_paramst   param_typest   enum_paramst   set_parameters(   t   selfR   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   __init__y  s    
							c         C@  s  x5t  j | j d i    D]\ } } t |  } | |  j | <| j d  rd | d |  j | <n  | j d  r | d |  j | <n  | j d  r |  j j |  n  | j d  r |  j	 j |  n  | j d  d k r |  j
 j |  n  | j d  d k r|  j j |  n  | j d	 d
  |  j | <q Wx t j | d  D]p } xg t j | j d   D]M } t | j d   } |  j j |  | |  j
 k rk|  j
 j |  qkqkWqLWd S(   s{  Populates maps and lists based on method description.

    Iterates through each parameter for the method and parses the values from
    the parameter dictionary.

    Args:
      method_desc: Dictionary with metadata describing an API method. Value
          comes from the dictionary of methods stored in the 'methods' key in
          the deserialized discovery document.
    R   t   patternt   enumR1   t   repeatedR8   R7   R   R0   R2   i    N(   R   R   Rn   R   R   R   R   R   RH   R   R   R   t   addR   t   URITEMPLATEt   finditert   VARNAMEt   groupt   remove(   R   R   t   argt   desct   paramt   matcht	   namematchRC   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR     s,    ((   R;   R<   t   __doc__R   R   (    (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR   `  s   	c      
   @  s4  t     t  |  \        t              f	 d   }  j d t  d g } t  j  d k r | j d  n  t | j d i   j	    } | j
 t  t  j j	    } g   j d g   D] } t |  ^ q }	 d | k r$|	 j d  n  x* | D]" }
 |
 |	 k r+|	 j |
  q+q+Wxh|	 D]`} | | k rpqXn  d	 } |  j k rd
 } n  d	 } |  j k rd } n   d  j | } | j d d  } d | k r| j d | | | | | j | d  f  n2 | j d d  } | j d | | | | | f  | j d g   } | j d g   } | rX| rX| j d  x7 t | |  D]# \ }
 } | j d |
 | f  qWqXqXWd  k r j d  r| j d  q| j d  | j | j  d   n  t | d d	 j |    | f S(   sW  Creates a method for attaching to a Resource.

  Args:
    methodName: string, name of the method to use.
    methodDesc: object, fragment of deserialized discovery document that
      describes the method.
    rootDesc: object, the entire deserialized discovery document.
    schema: object, mapping of schema names to schema descriptions.
  c   #      @  s  x9 t  j |  D]( } |  j k r t d |   q q Wt | j    } x( | D]  } | | d  k rU | | =qU qU Wx0  j D]% } | | k r t d |   q q Wx t  j  j	  D] \ } } | | k r t
 | | t  j  r | | g } n
 | | } xE | D]: } t j | |  d  k rt d | | | f   qqWq q Wx t  j  j  D] \ } } | | k rf|  j k rt
 | | t  j  r| | } n | | g } x? | D]4 }	 |	 | k rt d | |	 t |  f   qqWqfqfWi  }
 i  } x t  j |  D] \ } }	  j j | d  } |  j k rt |	  t g   k rg  |	 D] } t | |  ^ qo} n t |	 |  } |  j k r| |
  j | <n  |  j k r | |  j | <q q W| j d d   } | j d d   } | j d d   } |  j r5|  j |
 d	 <n  |  j }  j d
  rYt   } n d  k rqt   } n  i  } | j | | |
 |  \ } } } } t j  |  } t |  j  | |  } d  } d } | rt
 | t  j  rx| d  k rt! j" d |  t# j$ |  \ } } n  | d  k r6t% |   n  t& j' | g d j(     sct) |   n  t* | d | } n$ t
 | t+  r| } n t d   | j,   d  k	 r| j,    k od k n rt- d    n  t j  |  } t |  j  | |  } | j.   r,t/ | d d  } n  | j.   rA| } q| d  k r| j0   | d <| j1 d | j,    } t/ | d d  } qt2 d  } t3 | d d    t4 | d j5 d    } | j6 |  | j7 |  t4 | j0   j5 d    } d | d <| j1 d | j,    }  | j6 |   | j7 |  t8   }! t9 |! d t: }" |" j; | d t: |! j<   } | j=   } d | | d <t/ | d d   } n  t! j> d!  | f  |  j? |  j@ | jA | d"  d | d# | d$  d | S(%   Ns'   Got an unexpected keyword argument "%s"s   Missing required parameter "%s"s9   Parameter "%s" value "%s" does not match the pattern "%s"s9   Parameter "%s" value "%s" is not an allowed value in "%s"R2   R9   R   R   RK   t   _mediat   responseRE   sD   media_mime_type argument not specified: trying to auto-detect for %st   ,t   mimetypes*   media_filename must be str or MediaUpload.i    s   Media larger than: %st
   uploadTypet	   resumables   content-typet   mediat   relatedt   _write_headersc         S@  s   d  S(   N(   RV   (   R   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   <lambda>E  s    R   t   binarys   Content-Transfer-Encodingt   mangle_from_t   unixfroms    multipart/related; boundary="%s"t	   multiparts   URL being requested: %s %st   methodt   headerst   methodId(B   R   t   iterkeysR   t	   TypeErrorRF   R   RV   R   R   R   R   R   t   reR   R   R   R   R   Rn   R0   R   R   R   t   _developerKeyt   _modelR   R!   R"   Rs   RX   RY   R   t   _baseUrlRq   t   warningt	   mimetypest
   guess_typeR   R   t
   best_matchRJ   R   R   R   t   sizeR   R   R%   R   t   getbytesR   t   setattrR   t   splitt   set_payloadt   attachR   R:   R   t   flattent   getvaluet   get_boundaryRr   t   _requestBuildert   _httpR   (#   R   t   kwargsRC   R   t   regext   pvaluest   pvaluet   enumst   valuesR   t   actual_query_paramst   actual_path_paramsRK   t   to_typeRD   t
   cast_valuet
   body_valuet   media_filenameR   RS   R   Rc   R7   R9   t   expanded_urlR{   R   t   multipart_boundaryR?   R   t   msgRoott   msgt   payloadt   fpt   g(	   R   R   R   t   mediaPathUrlt
   methodDescR   t
   methodNameR   t   pathUrl(    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR     s    
!''%					4	
	R.   s   

i    s   Args:
R   t   parameterOrderR9   RE   s    (repeated)s    (required)s   A parameters   $refs<     %s: object, %s%s%s
    The object takes the form of:

%s

R0   R2   s     %s: %s, %s%s%s
R   t   enumDescriptionss       Allowed values
s         %s - %s
R   R   s/   
Returns:
  The media object as a string.

    s(   
Returns:
  An object of the form:

    R   (   R   R   R   Rn   t   DEFAULT_METHOD_DOCR   R   RH   RF   R   t   extendR   R   R   R   t   prettyPrintByNameR   R   t   prettyPrintSchemaR  RJ   (   R!  R   R   R   R   t   docst   skip_parameterst   all_argst   st   args_orderedRC   R   R   R1   t	   paramdesct   paramdoct	   paramtypeR   t   enumDescR   (    (	   R   R   R   R  R   R   R!  R   R"  sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   createMethod  s`    
!'+		"c         @  s%   t         f d   }   | f S(   s   Creates any _next methods for attaching to a Resource.

  The _next methods allow for easy iteration through list() responses.

  Args:
    methodName: string, name of the method to use.
  c         @  s   d | k s | d r d St j |  } | d } t t | j   } t | d  } g  | D]$ \ } } | d k r` | | f ^ q` }	 |	 j d | f  t |	  | d <t |  }
 |
 | _ t	 j
 d   |
 f  | S(   s[  Retrieves the next page of results.

Args:
  previous_request: The request for the previous page. (required)
  previous_response: The response from the request for the previous page. (required)

Returns:
  A request object that you can call 'execute()' on to request the next
  page. Returns None if there are no more items in the collection.
    t   nextPageTokeni   t	   pageTokens   URL being requested: %s %sN(   RV   R   RF   R	   Rl   R   RH   R   R   Rq   Rr   (   R   t   previous_requestt   previous_responseRs   R4  t   parsedt   qRK   R   t   newqRl   (   R!  (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt
   methodNext  s    
1	(   R   (   R!  R:  (    (   R!  sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   createNextMethod  s    #R   c           B@  sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s(   A class for interacting with a resource.c	   	      C@  s_   g  |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |  j	   d S(   s-  Build a Resource from the API description.

    Args:
      http: httplib2.Http, Object to make http requests with.
      baseUrl: string, base URL for the API. All requests are relative to this
          URI.
      model: googleapiclient.Model, converts to and from the wire format.
      requestBuilder: class or callable that instantiates an
          googleapiclient.HttpRequest object.
      developerKey: string, key obtained from
          https://code.google.com/apis/console
      resourceDesc: object, section of deserialized discovery document that
          describes a resource. Note that the top level discovery document
          is considered a resource.
      rootDesc: object, the entire deserialized discovery document.
      schema: object, mapping of schema names to schema descriptions.
    N(
   t   _dynamic_attrsR  R   R   R   R
  t   _resourceDesct	   _rootDesct   _schemat   _set_service_methods(	   R   RQ   R   RS   RT   RR   R   R   R   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR     s    									c         C@  s!   |  j  j |  | |  j | <d S(   s   Sets an instance attribute and tracks it in a list of dynamic attributes.

    Args:
      attr_name: string; The name of the attribute to be set
      value: The value being set on the object and tracked in the dynamic cache.
    N(   R<  RH   t   __dict__(   R   t	   attr_nameR   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   _set_dynamic_attr  s    c         C@  s8   t  j  |  j  } x |  j D] } | | =q W| d =| S(   s   Trim the state down to something that can be pickled.

    Uses the fact that the instance variable _dynamic_attrs holds attrs that
    will be wiped and restored on pickle serialization.
    R<  (   R   RA  R<  (   R   t
   state_dictt   dynamic_attr(    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   __getstate__  s
    c         C@  s'   |  j  j |  g  |  _ |  j   d S(   s   Reconstitute the state of the object from being pickled.

    Uses the fact that the instance variable _dynamic_attrs holds attrs that
    will be wiped and restored on pickle serialization.
    N(   RA  R   R<  R@  (   R   t   state(    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   __setstate__  s    	c         C@  sR   |  j  |  j |  j |  j  |  j |  j |  j |  j  |  j |  j |  j  d  S(   N(   t   _add_basic_methodsR=  R>  R?  t   _add_nested_resourcest   _add_next_methods(   R   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR@    s    c   	      @  s  | | k rQ d | d | j  d d  f   d    f d  } |  j d |  n  d | k rx t j | d  D] \ } } t | | | |  \ } } |  j | | j |  |  j   | j  d t  rq t | d	 | | |  \ } } |  j | | j |  |  j   qq qq Wn  d  S(
   Ns   %s%sR~   t	   batchPatht   batchc         @  s   t  d |  d    S(   sQ  Create a BatchHttpRequest object based on the discovery document.

        Args:
          callback: callable, A callback to be called for each response, of the
            form callback(id, response, exception). The first parameter is the
            request id, and the second is the deserialized response object. The
            third is an apiclient.errors.HttpError exception object if an HTTP
            error occurred while processing the request, or None if no error
            occurred.

        Returns:
          A BatchHttpRequest object based on the discovery document.
        t   callbackt	   batch_uri(   R   (   RN  (   RO  (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   new_batch_http_request  s    RP  t   methodst   supportsMediaDownloadR   (	   Rn   RV   RC  R   R   R2  t   __get__t	   __class__R   (	   R   R   R   R   RP  R!  R   t   fixedMethodNameR   (    (   RO  sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyRI    s      		c   	      @  s}   d | k ry    f d   } xX t  j | d  D]@ \ } } | | |  \ } } |  j | | j |  |  j   q2 Wn  d  S(   Nt	   resourcesc         @  sK   t  |   }      f d   } t | d d  t | d t  |  | f S(   s   Create a method on the Resource to access a nested Resource.

        Args:
          methodName: string, name of the method to use.
          methodDesc: object, fragment of deserialized discovery document that
            describes the method.
        c         @  sF   t  d |  j d |  j d |  j d |  j d |  j d   d  d   S(	   NRQ   R   RS   RR   RT   R   R   R   (   R   R  R   R   R   R
  (   R   (   R   R   R   (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   methodResourceM  s
    	R   s   A collection resource.t   __is_resource__(   R   R  t   True(   R!  R   RW  (   R   R   (   R   sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   createResourceMethodC  s
    (   R   R   RC  RS  RT  (	   R   R   R   R   RZ  R!  R   RU  R   (    (   R   R   sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyRJ  ?  s     	c   
      C@  s   d | k r x t  j | d  D] \ } } d | k r  | d } d | k rd | j | d  } n  d | j d i   k } d | j d i   k } | r | r t | d  \ } }	 |  j | |	 j |  |  j   q q  q  Wn  d  S(	   NRQ  R   s   $refR3  t
   propertiesR4  R   t   _next(   R   R   Rn   R;  RC  RS  RT  (
   R   R   R   R!  R   t   responseSchemat   hasNextPageTokent   hasPageTokenRU  R   (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyRK  ^  s     
	(   R;   R<   R   R   RC  RF  RH  R@  RI  RJ  RK  (    (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyR     s   	 	
		
		%	(h   R   t
   __future__R    R   t	   six.movesR   t
   __author__t   __all__R   R   t   six.moves.urllib.parseR   R	   R
   R   R   R   t   email.generatorR   t   ImportErrorR   t   email.mime.multipartR   t   email.mime.nonmultipartR   Rv   R@   t   loggingR   Ro   R   t   httplib2RX   t   googleapiclientR   R   t   googleapiclient.errorsR   R   R   R   R   R   t   googleapiclient.httpR   R   R   R   R   R   R   t   googleapiclient.modelR    R!   R"   t   googleapiclient.schemaR#   t   oauth2client.clientR$   t   oauth2client.utilR%   R&   t   oauth2client._helperst   RETRIESt	   getLoggerR;   Rq   t   compileR   R   t   DISCOVERY_URIt   V1_DISCOVERY_URIRW   R%  t	   frozensetR   R   RY  R   R   R   R   R   R   RB   R:   R   R   RV   R   RZ   R   R   R   R   R   R   R   R   R/   R   R2  R;  R   (    (    (    sK   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/discovery.pyt   <module>   s   	(	"


			;5	R				+	-	-	X		0