(self, http)
return http
Authorize an httplib2.Http instance with these credentials.

    The modified http.request method will add authentication headers to each
    request and will refresh access_tokens when a 401 is received on a
    request. In addition the http.request method has a credentials property,
    http.request.credentials, which is the Credentials object that authorized
    it.

    Args:
       http: An instance of httplib2.Http
         or something that acts like it.

    Returns:
       A modified instance of http that was passed in.

    Example:

      h = httplib2.Http()
      h = credentials.authorize(h)

    You can't create a new OAuth subclass of httplib2.Authenication
    because it never gets passed the absolute URI, which is needed for
    signing. So instead we have to overload 'request' with a closure
    that adds in the Authorization header and then calls the original
    version of 'request()'.
Authorize an httplib2.Http instance with these credentials.
Authorize an httplib2 . Http instance with these credentials .
def authorize(self, http):
    """Authorize an httplib2.Http instance with these credentials.

    The modified http.request method will add authentication headers to each
    request and will refresh access_tokens when a 401 is received on a
    request. In addition the http.request method has a credentials property,
    http.request.credentials, which is the Credentials object that authorized
    it.

    Args:
       http: An instance of httplib2.Http
         or something that acts like it.

    Returns:
       A modified instance of http that was passed in.

    Example:

      h = httplib2.Http()
      h = credentials.authorize(h)

    You can't create a new OAuth subclass of httplib2.Authenication
    because it never gets passed the absolute URI, which is needed for
    signing. So instead we have to overload 'request' with a closure
    that adds in the Authorization header and then calls the original
    version of 'request()'.
    """
    request_orig = http.request

    # The closure that will replace 'httplib2.Http.request'.
    @util.positional(1)
    def new_request(uri, method='GET', body=None, headers=None,
                    redirections=httplib2.DEFAULT_MAX_REDIRECTS,
                    connection_type=None):
      if not self.access_token:
        logger.info('Attempting refresh to obtain initial access_token')
        self._refresh(request_orig)

      # Modify the request headers to add the appropriate
      # Authorization header.
      if headers is None:
        headers = {}
      self.apply(headers)

      if self.user_agent is not None:
        if 'user-agent' in headers:
          headers['user-agent'] = self.user_agent + ' ' + headers['user-agent']
        else:
          headers['user-agent'] = self.user_agent

      resp, content = request_orig(uri, method, body, clean_headers(headers),
                                   redirections, connection_type)

      if resp.status in REFRESH_STATUS_CODES:
        logger.info('Refreshing due to a %s' % str(resp.status))
        self._refresh(request_orig)
        self.apply(headers)
        return request_orig(uri, method, body, clean_headers(headers),
                            redirections, connection_type)
      else:
        return (resp, content)

    # Replace the request method with our own closure.
    http.request = new_request

    # Set credentials as a property of the request method.
    setattr(http.request, 'credentials', self)

    return http
def authorize ( self , http ) : request_orig = http . request # The closure that will replace 'httplib2.Http.request'. @ util . positional ( 1 ) def new_request ( uri , method = 'GET' , body = None , headers = None , redirections = httplib2 . DEFAULT_MAX_REDIRECTS , connection_type = None ) : if not self . access_token : logger . info ( 'Attempting refresh to obtain initial access_token' ) self . _refresh ( request_orig ) # Modify the request headers to add the appropriate # Authorization header. if headers is None : headers = { } self . apply ( headers ) if self . user_agent is not None : if 'user-agent' in headers : headers [ 'user-agent' ] = self . user_agent + ' ' + headers [ 'user-agent' ] else : headers [ 'user-agent' ] = self . user_agent resp , content = request_orig ( uri , method , body , clean_headers ( headers ) , redirections , connection_type ) if resp . status in REFRESH_STATUS_CODES : logger . info ( 'Refreshing due to a %s' % str ( resp . status ) ) self . _refresh ( request_orig ) self . apply ( headers ) return request_orig ( uri , method , body , clean_headers ( headers ) , redirections , connection_type ) else : return ( resp , content ) # Replace the request method with our own closure. http . request = new_request # Set credentials as a property of the request method. setattr ( http . request , 'credentials' , self ) return http