669 lines
45 KiB
HTML
669 lines
45 KiB
HTML
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html><head><title>Python: module apiclient.http</title>
|
|
</head><body bgcolor="#f0f0f8">
|
|
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
|
|
<tr bgcolor="#7799ee">
|
|
<td valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="apiclient.html"><font color="#ffffff">apiclient</font></a>.http</strong></big></big></font></td
|
|
><td align=right valign=bottom
|
|
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/apiclient-release/apiclient/http.py">/home/jcgregorio/projects/apiclient-release/apiclient/http.py</a></font></td></tr></table>
|
|
<p><tt>Classes to encapsulate a single HTTP request.<br>
|
|
<br>
|
|
The classes implement a command pattern, with every<br>
|
|
<a href="__builtin__.html#object">object</a> supporting an execute() method that does the<br>
|
|
actuall HTTP request.</tt></p>
|
|
<p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#aa55cc">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
|
|
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="StringIO.html">StringIO</a><br>
|
|
<a href="base64.html">base64</a><br>
|
|
<a href="copy.html">copy</a><br>
|
|
</td><td width="25%" valign=top><a href="gzip.html">gzip</a><br>
|
|
<a href="httplib2.html">httplib2</a><br>
|
|
<a href="apiclient.mimeparse.html">apiclient.mimeparse</a><br>
|
|
</td><td width="25%" valign=top><a href="mimetypes.html">mimetypes</a><br>
|
|
<a href="os.html">os</a><br>
|
|
<a href="json.html">json</a><br>
|
|
</td><td width="25%" valign=top><a href="urllib.html">urllib</a><br>
|
|
<a href="urlparse.html">urlparse</a><br>
|
|
<a href="uuid.html">uuid</a><br>
|
|
</td></tr></table></td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ee77aa">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
|
|
<td width="100%"><dl>
|
|
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
|
|
</font></dt><dd>
|
|
<dl>
|
|
<dt><font face="helvetica, arial"><a href="apiclient.http.html#BatchHttpRequest">BatchHttpRequest</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpMock">HttpMock</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpMockSequence">HttpMockSequence</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequest">HttpRequest</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequestMock">HttpRequestMock</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaUpload">MediaUpload</a>
|
|
</font></dt><dd>
|
|
<dl>
|
|
<dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaFileUpload">MediaFileUpload</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaInMemoryUpload">MediaInMemoryUpload</a>
|
|
</font></dt></dl>
|
|
</dd>
|
|
<dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaUploadProgress">MediaUploadProgress</a>
|
|
</font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#RequestMockBuilder">RequestMockBuilder</a>
|
|
</font></dt></dl>
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="BatchHttpRequest">class <strong>BatchHttpRequest</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Batches multiple <a href="#HttpRequest">HttpRequest</a> objects into a single HTTP request.<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="BatchHttpRequest-__init__"><strong>__init__</strong></a>(self, callback<font color="#909090">=None</font>, batch_uri<font color="#909090">=None</font>)</dt><dd><tt>Constructor for a <a href="#BatchHttpRequest">BatchHttpRequest</a>.<br>
|
|
<br>
|
|
Args:<br>
|
|
callback: callable, A callback to be called for each response, of the<br>
|
|
form callback(id, response). The first parameter is the request id, and<br>
|
|
the second is the deserialized response <a href="__builtin__.html#object">object</a>.<br>
|
|
batch_uri: string, URI to send batch requests to.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="BatchHttpRequest-add"><strong>add</strong></a>(self, request, callback<font color="#909090">=None</font>, request_id<font color="#909090">=None</font>)</dt><dd><tt>Add a new request.<br>
|
|
<br>
|
|
Every callback added will be paired with a unique id, the request_id. That<br>
|
|
unique id will be passed back to the callback when the response comes back<br>
|
|
from the server. The default behavior is to have the library generate it's<br>
|
|
own unique id. If the caller passes in a request_id then they must ensure<br>
|
|
uniqueness for each request_id, and if they are not an exception is<br>
|
|
raised. Callers should either supply all request_ids or nevery supply a<br>
|
|
request id, to avoid such an error.<br>
|
|
<br>
|
|
Args:<br>
|
|
request: <a href="#HttpRequest">HttpRequest</a>, Request to add to the batch.<br>
|
|
callback: callable, A callback to be called for this response, of the<br>
|
|
form callback(id, response). The first parameter is the request id, and<br>
|
|
the second is the deserialized response <a href="__builtin__.html#object">object</a>.<br>
|
|
request_id: string, A unique id for the request. The id will be passed to<br>
|
|
the callback with the response.<br>
|
|
<br>
|
|
Returns:<br>
|
|
None<br>
|
|
<br>
|
|
Raises:<br>
|
|
BatchError if a resumable request is added to a batch.<br>
|
|
KeyError is the request_id is not unique.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="BatchHttpRequest-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute all the requests as a single batched HTTP request.<br>
|
|
<br>
|
|
Args:<br>
|
|
http: httplib2.Http, an http <a href="__builtin__.html#object">object</a> to be used in place of the one the<br>
|
|
<a href="#HttpRequest">HttpRequest</a> request <a href="__builtin__.html#object">object</a> was constructed with. If one isn't supplied<br>
|
|
then use a http <a href="__builtin__.html#object">object</a> from the requests in this batch.<br>
|
|
<br>
|
|
Returns:<br>
|
|
None<br>
|
|
<br>
|
|
Raises:<br>
|
|
httplib2.Error if a transport error has occured.<br>
|
|
apiclient.errors.BatchError if the response is the wrong format.</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data descriptors defined here:<br>
|
|
<dl><dt><strong>__dict__</strong></dt>
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
|
</dl>
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
|
</dl>
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="HttpMock">class <strong>HttpMock</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Mock of httplib2.Http<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="HttpMock-__init__"><strong>__init__</strong></a>(self, filename, headers<font color="#909090">=None</font>)</dt><dd><tt>Args:<br>
|
|
filename: string, absolute filename to read response from<br>
|
|
headers: dict, header to return with response</tt></dd></dl>
|
|
|
|
<dl><dt><a name="HttpMock-request"><strong>request</strong></a>(self, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, redirections<font color="#909090">=1</font>, connection_type<font color="#909090">=None</font>)</dt></dl>
|
|
|
|
<hr>
|
|
Data descriptors defined here:<br>
|
|
<dl><dt><strong>__dict__</strong></dt>
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
|
</dl>
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
|
</dl>
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="HttpMockSequence">class <strong>HttpMockSequence</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Mock of httplib2.Http<br>
|
|
<br>
|
|
Mocks a sequence of calls to request returning different responses for each<br>
|
|
call. Create an instance initialized with the desired response headers<br>
|
|
and content and then use as if an httplib2.Http instance.<br>
|
|
<br>
|
|
http = <a href="#HttpMockSequence">HttpMockSequence</a>([<br>
|
|
({'status': '401'}, ''),<br>
|
|
({'status': '200'}, '{"access_token":"1/3w","expires_in":3600}'),<br>
|
|
({'status': '200'}, 'echo_request_headers'),<br>
|
|
])<br>
|
|
resp, content = http.<a href="#HttpMockSequence-request">request</a>("<a href="http://examples.com">http://examples.com</a>")<br>
|
|
<br>
|
|
There are special values you can pass in for content to trigger<br>
|
|
behavours that are helpful in testing.<br>
|
|
<br>
|
|
'echo_request_headers' means return the request headers in the response body<br>
|
|
'echo_request_headers_as_json' means return the request headers in<br>
|
|
the response body<br>
|
|
'echo_request_body' means return the request body in the response body<br>
|
|
'echo_request_uri' means return the request uri in the response body<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="HttpMockSequence-__init__"><strong>__init__</strong></a>(self, iterable)</dt><dd><tt>Args:<br>
|
|
iterable: iterable, a sequence of pairs of (headers, body)</tt></dd></dl>
|
|
|
|
<dl><dt><a name="HttpMockSequence-request"><strong>request</strong></a>(self, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, redirections<font color="#909090">=1</font>, connection_type<font color="#909090">=None</font>)</dt></dl>
|
|
|
|
<hr>
|
|
Data descriptors defined here:<br>
|
|
<dl><dt><strong>__dict__</strong></dt>
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
|
</dl>
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
|
</dl>
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="HttpRequest">class <strong>HttpRequest</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Encapsulates a single HTTP request.<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="HttpRequest-__init__"><strong>__init__</strong></a>(self, http, postproc, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, methodId<font color="#909090">=None</font>, resumable<font color="#909090">=None</font>)</dt><dd><tt>Constructor for an <a href="#HttpRequest">HttpRequest</a>.<br>
|
|
<br>
|
|
Args:<br>
|
|
http: httplib2.Http, the transport <a href="__builtin__.html#object">object</a> to use to make a request<br>
|
|
postproc: callable, called on the HTTP response and content to transform<br>
|
|
it into a data <a href="__builtin__.html#object">object</a> before returning, or raising an exception<br>
|
|
on an error.<br>
|
|
uri: string, the absolute URI to send the request to<br>
|
|
method: string, the HTTP method to use<br>
|
|
body: string, the request body of the HTTP request,<br>
|
|
headers: dict, the HTTP request headers<br>
|
|
methodId: string, a unique identifier for the API method being called.<br>
|
|
resumable: <a href="#MediaUpload">MediaUpload</a>, None if this is not a resumbale request.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="HttpRequest-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute the request.<br>
|
|
<br>
|
|
Args:<br>
|
|
http: httplib2.Http, an http <a href="__builtin__.html#object">object</a> to be used in place of the<br>
|
|
one the <a href="#HttpRequest">HttpRequest</a> request <a href="__builtin__.html#object">object</a> was constructed with.<br>
|
|
<br>
|
|
Returns:<br>
|
|
A deserialized <a href="__builtin__.html#object">object</a> model of the response body as determined<br>
|
|
by the postproc.<br>
|
|
<br>
|
|
Raises:<br>
|
|
apiclient.errors.HttpError if the response was not a 2xx.<br>
|
|
httplib2.Error if a transport error has occured.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="HttpRequest-next_chunk"><strong>next_chunk</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute the next step of a resumable upload.<br>
|
|
<br>
|
|
Can only be used if the method being executed supports media uploads and<br>
|
|
the <a href="#MediaUpload">MediaUpload</a> <a href="__builtin__.html#object">object</a> passed in was flagged as using resumable upload.<br>
|
|
<br>
|
|
Example:<br>
|
|
<br>
|
|
media = <a href="#MediaFileUpload">MediaFileUpload</a>('smiley.png', mimetype='image/png',<br>
|
|
chunksize=1000, resumable=True)<br>
|
|
request = service.objects().insert(<br>
|
|
bucket=buckets['items'][0]['id'],<br>
|
|
name='smiley.png',<br>
|
|
media_body=media)<br>
|
|
<br>
|
|
response = None<br>
|
|
while response is None:<br>
|
|
status, response = request.<a href="#HttpRequest-next_chunk">next_chunk</a>()<br>
|
|
if status:<br>
|
|
print "Upload %d%% complete." % int(status.progress() * 100)<br>
|
|
<br>
|
|
<br>
|
|
Returns:<br>
|
|
(status, body): (ResumableMediaStatus, <a href="__builtin__.html#object">object</a>)<br>
|
|
The body will be None until the resumable media is fully uploaded.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="HttpRequest-to_json"><strong>to_json</strong></a>(self)</dt><dd><tt>Returns a JSON representation of the <a href="#HttpRequest">HttpRequest</a>.</tt></dd></dl>
|
|
|
|
<hr>
|
|
Static methods defined here:<br>
|
|
<dl><dt><a name="HttpRequest-from_json"><strong>from_json</strong></a>(s, http, postproc)</dt><dd><tt>Returns an <a href="#HttpRequest">HttpRequest</a> populated with info from a JSON <a href="__builtin__.html#object">object</a>.</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data descriptors defined here:<br>
|
|
<dl><dt><strong>__dict__</strong></dt>
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
|
</dl>
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
|
</dl>
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="HttpRequestMock">class <strong>HttpRequestMock</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Mock of <a href="#HttpRequest">HttpRequest</a>.<br>
|
|
<br>
|
|
Do not construct directly, instead use <a href="#RequestMockBuilder">RequestMockBuilder</a>.<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="HttpRequestMock-__init__"><strong>__init__</strong></a>(self, resp, content, postproc)</dt><dd><tt>Constructor for <a href="#HttpRequestMock">HttpRequestMock</a><br>
|
|
<br>
|
|
Args:<br>
|
|
resp: httplib2.Response, the response to emulate coming from the request<br>
|
|
content: string, the response body<br>
|
|
postproc: callable, the post processing function usually supplied by<br>
|
|
the model class. See model.JsonModel.response() as an example.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="HttpRequestMock-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute the request.<br>
|
|
<br>
|
|
Same behavior as <a href="#HttpRequest">HttpRequest</a>.<a href="#HttpRequestMock-execute">execute</a>(), but the response is<br>
|
|
mocked and not really from an HTTP request/response.</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data descriptors defined here:<br>
|
|
<dl><dt><strong>__dict__</strong></dt>
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
|
</dl>
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
|
</dl>
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="MediaFileUpload">class <strong>MediaFileUpload</strong></a>(<a href="apiclient.http.html#MediaUpload">MediaUpload</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>A <a href="#MediaUpload">MediaUpload</a> for a file.<br>
|
|
<br>
|
|
Construct a <a href="#MediaFileUpload">MediaFileUpload</a> and pass as the media_body parameter of the<br>
|
|
method. For example, if we had a service that allowed uploading images:<br>
|
|
<br>
|
|
<br>
|
|
media = <a href="#MediaFileUpload">MediaFileUpload</a>('smiley.png', mimetype='image/png', chunksize=1000,<br>
|
|
resumable=True)<br>
|
|
service.objects().insert(<br>
|
|
bucket=buckets['items'][0]['id'],<br>
|
|
name='smiley.png',<br>
|
|
media_body=media).execute()<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%"><dl><dt>Method resolution order:</dt>
|
|
<dd><a href="apiclient.http.html#MediaFileUpload">MediaFileUpload</a></dd>
|
|
<dd><a href="apiclient.http.html#MediaUpload">MediaUpload</a></dd>
|
|
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
|
|
</dl>
|
|
<hr>
|
|
Methods defined here:<br>
|
|
<dl><dt><a name="MediaFileUpload-__init__"><strong>__init__</strong></a>(self, filename, mimetype<font color="#909090">=None</font>, chunksize<font color="#909090">=262144</font>, resumable<font color="#909090">=False</font>)</dt><dd><tt>Constructor.<br>
|
|
<br>
|
|
Args:<br>
|
|
filename: string, Name of the file.<br>
|
|
mimetype: string, Mime-type of the file. If None then a mime-type will be<br>
|
|
guessed from the file extension.<br>
|
|
chunksize: int, File will be uploaded in chunks of this many bytes. Only<br>
|
|
used if resumable=True.<br>
|
|
resumable: bool, True if this is a resumable upload. False means upload<br>
|
|
in a single request.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="MediaFileUpload-chunksize"><strong>chunksize</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MediaFileUpload-getbytes"><strong>getbytes</strong></a>(self, begin, length)</dt><dd><tt>Get bytes from the media.<br>
|
|
<br>
|
|
Args:<br>
|
|
begin: int, offset from beginning of file.<br>
|
|
length: int, number of bytes to read, starting at begin.<br>
|
|
<br>
|
|
Returns:<br>
|
|
A string of bytes read. May be shorted than length if EOF was reached<br>
|
|
first.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="MediaFileUpload-mimetype"><strong>mimetype</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MediaFileUpload-resumable"><strong>resumable</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MediaFileUpload-size"><strong>size</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MediaFileUpload-to_json"><strong>to_json</strong></a>(self)</dt><dd><tt>Creating a JSON representation of an instance of Credentials.<br>
|
|
<br>
|
|
Returns:<br>
|
|
string, a JSON representation of this instance, suitable to pass to<br>
|
|
<a href="#MediaFileUpload-from_json">from_json</a>().</tt></dd></dl>
|
|
|
|
<hr>
|
|
Static methods defined here:<br>
|
|
<dl><dt><a name="MediaFileUpload-from_json"><strong>from_json</strong></a>(s)</dt></dl>
|
|
|
|
<hr>
|
|
Class methods inherited from <a href="apiclient.http.html#MediaUpload">MediaUpload</a>:<br>
|
|
<dl><dt><a name="MediaFileUpload-new_from_json"><strong>new_from_json</strong></a>(cls, s)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt><dd><tt>Utility class method to instantiate a <a href="#MediaUpload">MediaUpload</a> subclass from a JSON<br>
|
|
representation produced by <a href="#MediaFileUpload-to_json">to_json</a>().<br>
|
|
<br>
|
|
Args:<br>
|
|
s: string, JSON from <a href="#MediaFileUpload-to_json">to_json</a>().<br>
|
|
<br>
|
|
Returns:<br>
|
|
An instance of the subclass of <a href="#MediaUpload">MediaUpload</a> that was serialized with<br>
|
|
<a href="#MediaFileUpload-to_json">to_json</a>().</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data descriptors inherited from <a href="apiclient.http.html#MediaUpload">MediaUpload</a>:<br>
|
|
<dl><dt><strong>__dict__</strong></dt>
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
|
</dl>
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
|
</dl>
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="MediaInMemoryUpload">class <strong>MediaInMemoryUpload</strong></a>(<a href="apiclient.http.html#MediaUpload">MediaUpload</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt><a href="#MediaUpload">MediaUpload</a> for a chunk of bytes.<br>
|
|
<br>
|
|
Construct a <a href="#MediaFileUpload">MediaFileUpload</a> and pass as the media_body parameter of the<br>
|
|
method. For example, if we had a service that allowed plain text:<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%"><dl><dt>Method resolution order:</dt>
|
|
<dd><a href="apiclient.http.html#MediaInMemoryUpload">MediaInMemoryUpload</a></dd>
|
|
<dd><a href="apiclient.http.html#MediaUpload">MediaUpload</a></dd>
|
|
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
|
|
</dl>
|
|
<hr>
|
|
Methods defined here:<br>
|
|
<dl><dt><a name="MediaInMemoryUpload-__init__"><strong>__init__</strong></a>(self, body, mimetype<font color="#909090">='application/octet-stream'</font>, chunksize<font color="#909090">=262144</font>, resumable<font color="#909090">=False</font>)</dt><dd><tt>Create a new MediaBytesUpload.<br>
|
|
<br>
|
|
Args:<br>
|
|
body: string, Bytes of body content.<br>
|
|
mimetype: string, Mime-type of the file or default of<br>
|
|
'application/octet-stream'.<br>
|
|
chunksize: int, File will be uploaded in chunks of this many bytes. Only<br>
|
|
used if resumable=True.<br>
|
|
resumable: bool, True if this is a resumable upload. False means upload<br>
|
|
in a single request.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="MediaInMemoryUpload-chunksize"><strong>chunksize</strong></a>(self)</dt><dd><tt>Chunk size for resumable uploads.<br>
|
|
<br>
|
|
Returns:<br>
|
|
Chunk size in bytes.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="MediaInMemoryUpload-getbytes"><strong>getbytes</strong></a>(self, begin, length)</dt><dd><tt>Get bytes from the media.<br>
|
|
<br>
|
|
Args:<br>
|
|
begin: int, offset from beginning of file.<br>
|
|
length: int, number of bytes to read, starting at begin.<br>
|
|
<br>
|
|
Returns:<br>
|
|
A string of bytes read. May be shorter than length if EOF was reached<br>
|
|
first.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="MediaInMemoryUpload-mimetype"><strong>mimetype</strong></a>(self)</dt><dd><tt>Mime type of the body.<br>
|
|
<br>
|
|
Returns:<br>
|
|
Mime type.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="MediaInMemoryUpload-resumable"><strong>resumable</strong></a>(self)</dt><dd><tt>Whether this upload is resumable.<br>
|
|
<br>
|
|
Returns:<br>
|
|
True if resumable upload or False.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="MediaInMemoryUpload-size"><strong>size</strong></a>(self)</dt><dd><tt>Size of upload.<br>
|
|
<br>
|
|
Returns:<br>
|
|
Size of the body.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="MediaInMemoryUpload-to_json"><strong>to_json</strong></a>(self)</dt><dd><tt>Create a JSON representation of a <a href="#MediaInMemoryUpload">MediaInMemoryUpload</a>.<br>
|
|
<br>
|
|
Returns:<br>
|
|
string, a JSON representation of this instance, suitable to pass to<br>
|
|
<a href="#MediaInMemoryUpload-from_json">from_json</a>().</tt></dd></dl>
|
|
|
|
<hr>
|
|
Static methods defined here:<br>
|
|
<dl><dt><a name="MediaInMemoryUpload-from_json"><strong>from_json</strong></a>(s)</dt></dl>
|
|
|
|
<hr>
|
|
Class methods inherited from <a href="apiclient.http.html#MediaUpload">MediaUpload</a>:<br>
|
|
<dl><dt><a name="MediaInMemoryUpload-new_from_json"><strong>new_from_json</strong></a>(cls, s)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt><dd><tt>Utility class method to instantiate a <a href="#MediaUpload">MediaUpload</a> subclass from a JSON<br>
|
|
representation produced by <a href="#MediaInMemoryUpload-to_json">to_json</a>().<br>
|
|
<br>
|
|
Args:<br>
|
|
s: string, JSON from <a href="#MediaInMemoryUpload-to_json">to_json</a>().<br>
|
|
<br>
|
|
Returns:<br>
|
|
An instance of the subclass of <a href="#MediaUpload">MediaUpload</a> that was serialized with<br>
|
|
<a href="#MediaInMemoryUpload-to_json">to_json</a>().</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data descriptors inherited from <a href="apiclient.http.html#MediaUpload">MediaUpload</a>:<br>
|
|
<dl><dt><strong>__dict__</strong></dt>
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
|
</dl>
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
|
</dl>
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="MediaUpload">class <strong>MediaUpload</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Describes a media <a href="__builtin__.html#object">object</a> to upload.<br>
|
|
<br>
|
|
Base class that defines the interface of <a href="#MediaUpload">MediaUpload</a> subclasses.<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="MediaUpload-chunksize"><strong>chunksize</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MediaUpload-getbytes"><strong>getbytes</strong></a>(self, begin, end)</dt></dl>
|
|
|
|
<dl><dt><a name="MediaUpload-mimetype"><strong>mimetype</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MediaUpload-resumable"><strong>resumable</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MediaUpload-size"><strong>size</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="MediaUpload-to_json"><strong>to_json</strong></a>(self)</dt><dd><tt>Create a JSON representation of an instance of <a href="#MediaUpload">MediaUpload</a>.<br>
|
|
<br>
|
|
Returns:<br>
|
|
string, a JSON representation of this instance, suitable to pass to<br>
|
|
from_json().</tt></dd></dl>
|
|
|
|
<hr>
|
|
Class methods defined here:<br>
|
|
<dl><dt><a name="MediaUpload-new_from_json"><strong>new_from_json</strong></a>(cls, s)<font color="#909090"><font face="helvetica, arial"> from <a href="__builtin__.html#type">__builtin__.type</a></font></font></dt><dd><tt>Utility class method to instantiate a <a href="#MediaUpload">MediaUpload</a> subclass from a JSON<br>
|
|
representation produced by <a href="#MediaUpload-to_json">to_json</a>().<br>
|
|
<br>
|
|
Args:<br>
|
|
s: string, JSON from <a href="#MediaUpload-to_json">to_json</a>().<br>
|
|
<br>
|
|
Returns:<br>
|
|
An instance of the subclass of <a href="#MediaUpload">MediaUpload</a> that was serialized with<br>
|
|
<a href="#MediaUpload-to_json">to_json</a>().</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data descriptors defined here:<br>
|
|
<dl><dt><strong>__dict__</strong></dt>
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
|
</dl>
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
|
</dl>
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="MediaUploadProgress">class <strong>MediaUploadProgress</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Status of a resumable upload.<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="MediaUploadProgress-__init__"><strong>__init__</strong></a>(self, resumable_progress, total_size)</dt><dd><tt>Constructor.<br>
|
|
<br>
|
|
Args:<br>
|
|
resumable_progress: int, bytes sent so far.<br>
|
|
total_size: int, total bytes in complete upload.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="MediaUploadProgress-progress"><strong>progress</strong></a>(self)</dt><dd><tt>Percent of upload completed, as a float.</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data descriptors defined here:<br>
|
|
<dl><dt><strong>__dict__</strong></dt>
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
|
</dl>
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
|
</dl>
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="RequestMockBuilder">class <strong>RequestMockBuilder</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>A simple mock of <a href="#HttpRequest">HttpRequest</a><br>
|
|
<br>
|
|
Pass in a dictionary to the constructor that maps request methodIds to<br>
|
|
tuples of (httplib2.Response, content, opt_expected_body) that should be<br>
|
|
returned when that method is called. None may also be passed in for the<br>
|
|
httplib2.Response, in which case a 200 OK response will be generated.<br>
|
|
If an opt_expected_body (str or dict) is provided, it will be compared to<br>
|
|
the body and UnexpectedBodyError will be raised on inequality.<br>
|
|
<br>
|
|
Example:<br>
|
|
response = '{"data": {"id": "tag:google.c...'<br>
|
|
requestBuilder = <a href="#RequestMockBuilder">RequestMockBuilder</a>(<br>
|
|
{<br>
|
|
'plus.activities.get': (None, response),<br>
|
|
}<br>
|
|
)<br>
|
|
apiclient.discovery.build("plus", "v1", requestBuilder=requestBuilder)<br>
|
|
<br>
|
|
Methods that you do not supply a response for will return a<br>
|
|
200 OK with an empty string as the response content or raise an excpetion<br>
|
|
if check_unexpected is set to True. The methodId is taken from the rpcName<br>
|
|
in the discovery document.<br>
|
|
<br>
|
|
For more details see the project wiki.<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="RequestMockBuilder-__call__"><strong>__call__</strong></a>(self, http, postproc, uri, method<font color="#909090">='GET'</font>, body<font color="#909090">=None</font>, headers<font color="#909090">=None</font>, methodId<font color="#909090">=None</font>, resumable<font color="#909090">=None</font>)</dt><dd><tt>Implements the callable interface that discovery.build() expects<br>
|
|
of requestBuilder, which is to build an <a href="__builtin__.html#object">object</a> compatible with<br>
|
|
<a href="#HttpRequest">HttpRequest</a>.execute(). See that method for the description of the<br>
|
|
parameters and the expected response.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="RequestMockBuilder-__init__"><strong>__init__</strong></a>(self, responses, check_unexpected<font color="#909090">=False</font>)</dt><dd><tt>Constructor for <a href="#RequestMockBuilder">RequestMockBuilder</a><br>
|
|
<br>
|
|
The constructed <a href="__builtin__.html#object">object</a> should be a callable <a href="__builtin__.html#object">object</a><br>
|
|
that can replace the class HttpResponse.<br>
|
|
<br>
|
|
responses - A dictionary that maps methodIds into tuples<br>
|
|
of (httplib2.Response, content). The methodId<br>
|
|
comes from the 'rpcName' field in the discovery<br>
|
|
document.<br>
|
|
check_unexpected - A boolean setting whether or not UnexpectedMethodError<br>
|
|
should be raised on unsupplied method.</tt></dd></dl>
|
|
|
|
<hr>
|
|
Data descriptors defined here:<br>
|
|
<dl><dt><strong>__dict__</strong></dt>
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
|
</dl>
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
|
</dl>
|
|
</td></tr></table></td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#eeaa77">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
|
|
<td width="100%"><dl><dt><a name="-set_user_agent"><strong>set_user_agent</strong></a>(http, user_agent)</dt><dd><tt>Set the user-agent on every request.<br>
|
|
<br>
|
|
Args:<br>
|
|
http - An instance of httplib2.Http<br>
|
|
or something that acts like it.<br>
|
|
user_agent: string, the value for the user-agent header.<br>
|
|
<br>
|
|
Returns:<br>
|
|
A modified instance of http that was passed in.<br>
|
|
<br>
|
|
Example:<br>
|
|
<br>
|
|
h = httplib2.Http()<br>
|
|
h = <a href="#-set_user_agent">set_user_agent</a>(h, "my-app-name/6.0")<br>
|
|
<br>
|
|
Most of the time the user-agent will be set doing auth, this is for the rare<br>
|
|
cases where you are accessing an unauthenticated endpoint.</tt></dd></dl>
|
|
<dl><dt><a name="-tunnel_patch"><strong>tunnel_patch</strong></a>(http)</dt><dd><tt>Tunnel PATCH requests over POST.<br>
|
|
Args:<br>
|
|
http - An instance of httplib2.Http<br>
|
|
or something that acts like it.<br>
|
|
<br>
|
|
Returns:<br>
|
|
A modified instance of http that was passed in.<br>
|
|
<br>
|
|
Example:<br>
|
|
<br>
|
|
h = httplib2.Http()<br>
|
|
h = <a href="#-tunnel_patch">tunnel_patch</a>(h, "my-app-name/6.0")<br>
|
|
<br>
|
|
Useful if you are running on a platform that doesn't support PATCH.<br>
|
|
Apply this last if you are using OAuth 1.0, as changing the method<br>
|
|
will result in a different signature.</tt></dd></dl>
|
|
</td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#55aa55">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
|
|
<td width="100%"><strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#7799ee">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td>
|
|
<td width="100%">jcgregorio@google.com (Joe Gregorio)</td></tr></table>
|
|
</body></html> |