ó
‚¾^Yc           @   s¹   d  Z  y. d d l Z d d l Z d d l Z e Z Wn e k
 rM e Z n Xy" d d l	 Z	 d d l
 Z	 e Z Wn e k
 r‰ e Z n Xd d l m Z d „  Z d „  Z d „  Z d S(   s=   Helpers for authentication using oauth2client or google-auth.iÿÿÿÿN(   t
   build_httpc          C   sE   t  r t j j ƒ  \ }  } |  St r5 t j j j ƒ  St	 d ƒ ‚ d S(   s(   Returns Application Default Credentials.sZ   No authentication library is available. Please install either google-auth or oauth2client.N(
   t   HAS_GOOGLE_AUTHt   googlet   autht   defaultt   HAS_OAUTH2CLIENTt   oauth2clientt   clientt   GoogleCredentialst   get_application_defaultt   EnvironmentError(   t   credentialst   _(    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/_auth.pyt   default_credentials#   s    c         C   sn   t  r4 t |  t j j j ƒ r4 t j j j |  | ƒ Sy! |  j ƒ  rP |  j | ƒ S|  SWn t	 k
 ri |  SXd S(   s…  Scopes the credentials if necessary.

    Args:
        credentials (Union[
            google.auth.credentials.Credentials,
            oauth2client.client.Credentials]): The credentials to scope.
        scopes (Sequence[str]): The list of scopes.

    Returns:
        Union[google.auth.credentials.Credentials,
            oauth2client.client.Credentials]: The scoped credentials.
    N(
   R   t
   isinstanceR   R   R   t   Credentialst   with_scopes_if_requiredt   create_scoped_requiredt   create_scopedt   AttributeError(   R   t   scopes(    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/_auth.pyt   with_scopes0   s    	
c         C   sH   t  r4 t |  t j j j ƒ r4 t j |  d t ƒ  ƒS|  j	 t ƒ  ƒ Sd S(   sa  Returns an http client that is authorized with the given credentials.

    Args:
        credentials (Union[
            google.auth.credentials.Credentials,
            oauth2client.client.Credentials]): The credentials to use.

    Returns:
        Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An
            authorized http client.
    t   httpN(
   R   R   R   R   R   R   t   google_auth_httplib2t   AuthorizedHttpR    t	   authorize(   R   (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/_auth.pyt   authorized_httpK   s
    	
(   t   __doc__t   google.authR   t   google.auth.credentialsR   t   TrueR   t   ImportErrort   FalseR   t   oauth2client.clientR   t   googleapiclient.httpR    R   R   R   (    (    (    sG   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/_auth.pyt   <module>   s"   



		