Package googleapiclient :: Module http
[hide private]
[frames] | no frames]

Module http

source code

Classes to encapsulate a single HTTP request.

The classes implement a command pattern, with every
object supporting an execute() method that does the
actuall HTTP request.


Author: jcgregorio@google.com (Joe Gregorio)

Classes [hide private]
  MediaUploadProgress
Status of a resumable upload.
  MediaDownloadProgress
Status of a resumable download.
  MediaUpload
Describes a media object to upload.
  MediaIoBaseUpload
A MediaUpload for a io.Base objects.
  MediaFileUpload
A MediaUpload for a file.
  MediaInMemoryUpload
MediaUpload for a chunk of bytes.
  MediaIoBaseDownload
"Download media resources.
  _StreamSlice
Truncated stream.
  HttpRequest
Encapsulates a single HTTP request.
  BatchHttpRequest
Batches multiple HttpRequest objects into a single HTTP request.
  HttpRequestMock
Mock of HttpRequest.
  RequestMockBuilder
A simple mock of HttpRequest
  HttpMock
Mock of httplib2.Http
  HttpMockSequence
Mock of httplib2.Http
Functions [hide private]
 
_should_retry_response(resp_status, content)
Determines whether a response should be retried.
source code
 
_retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args, **kwargs)
Retries an HTTP request multiple times while handling errors.
source code
 
set_user_agent(http, user_agent)
Set the user-agent on every request.
source code
 
tunnel_patch(http)
Tunnel PATCH requests over POST.
source code
 
build_http()
Builds httplib2.Http object
source code
Variables [hide private]
  _ssl_SSLError = ssl.SSLError
  LOGGER = logging.getLogger(__name__)
  DEFAULT_CHUNK_SIZE = 512* 1024
  MAX_URI_LENGTH = 2048
  _TOO_MANY_REQUESTS = 429
  DEFAULT_HTTP_TIMEOUT_SEC = 60
Function Details [hide private]

_should_retry_response(resp_status, content)

source code 
Determines whether a response should be retried.

Args:
  resp_status: The response status received.
  content: The response content body. 

Returns:
  True if the response should be retried, otherwise False.

_retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args, **kwargs)

source code 
Retries an HTTP request multiple times while handling errors.

If after all retries the request still fails, last error is either returned as
return value (for HTTP 5xx errors) or thrown (for ssl.SSLError).

Args:
  http: Http object to be used to execute request.
  num_retries: Maximum number of retries.
  req_type: Type of the request (used for logging retries).
  sleep, rand: Functions to sleep for random time between retries.
  uri: URI to be requested.
  method: HTTP method to be used.
  args, kwargs: Additional arguments passed to http.request.

Returns:
  resp, content - Response from the http request (may be HTTP 5xx).

set_user_agent(http, user_agent)

source code 
Set the user-agent on every request.

Args:
   http - An instance of httplib2.Http
       or something that acts like it.
   user_agent: string, the value for the user-agent header.

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

Example:

  h = httplib2.Http()
  h = set_user_agent(h, "my-app-name/6.0")

Most of the time the user-agent will be set doing auth, this is for the rare
cases where you are accessing an unauthenticated endpoint.

tunnel_patch(http)

source code 
Tunnel PATCH requests over POST.
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 = tunnel_patch(h, "my-app-name/6.0")

Useful if you are running on a platform that doesn't support PATCH.
Apply this last if you are using OAuth 1.0, as changing the method
will result in a different signature.

build_http()

source code 
Builds httplib2.Http object

Returns:
A httplib2.Http object, which is used to make http requests, and which has timeout set by default.
To override default timeout call

  socket.setdefaulttimeout(timeout_in_sec)

before interacting with this method.