Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 1 | |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 3 | <html><head><title>Python: module apiclient.http</title> |
| 4 | </head><body bgcolor="#f0f0f8"> |
| 5 | |
| 6 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
| 7 | <tr bgcolor="#7799ee"> |
| 8 | <td valign=bottom> <br> |
| 9 | <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 |
| 10 | ><td align=right valign=bottom |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 11 | ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jcgregorio/projects/clean/apiclient/http.py">/home/jcgregorio/projects/clean/apiclient/http.py</a></font></td></tr></table> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 12 | <p><tt>Classes to encapsulate a single HTTP request.<br> |
| 13 | <br> |
| 14 | The classes implement a command pattern, with every<br> |
| 15 | <a href="__builtin__.html#object">object</a> supporting an execute() method that does the<br> |
| 16 | actuall HTTP request.</tt></p> |
| 17 | <p> |
| 18 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
Joe Gregorio | 6e53703 | 2011-02-09 23:04:26 -0500 | [diff] [blame] | 19 | <tr bgcolor="#aa55cc"> |
| 20 | <td colspan=3 valign=bottom> <br> |
| 21 | <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> |
| 22 | |
| 23 | <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 24 | <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="StringIO.html">StringIO</a><br> |
Joe Gregorio | 3d55ac5 | 2012-02-21 10:11:19 -0500 | [diff] [blame] | 25 | <a href="base64.html">base64</a><br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 26 | <a href="copy.html">copy</a><br> |
Joe Gregorio | 3d55ac5 | 2012-02-21 10:11:19 -0500 | [diff] [blame] | 27 | </td><td width="25%" valign=top><a href="gzip.html">gzip</a><br> |
| 28 | <a href="httplib2.html">httplib2</a><br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 29 | <a href="apiclient.mimeparse.html">apiclient.mimeparse</a><br> |
Joe Gregorio | 3d55ac5 | 2012-02-21 10:11:19 -0500 | [diff] [blame] | 30 | </td><td width="25%" valign=top><a href="mimetypes.html">mimetypes</a><br> |
| 31 | <a href="os.html">os</a><br> |
| 32 | <a href="json.html">json</a><br> |
| 33 | </td><td width="25%" valign=top><a href="urllib.html">urllib</a><br> |
| 34 | <a href="urlparse.html">urlparse</a><br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 35 | <a href="uuid.html">uuid</a><br> |
| 36 | </td></tr></table></td></tr></table><p> |
Joe Gregorio | 6e53703 | 2011-02-09 23:04:26 -0500 | [diff] [blame] | 37 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 38 | <tr bgcolor="#ee77aa"> |
| 39 | <td colspan=3 valign=bottom> <br> |
| 40 | <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> |
| 41 | |
| 42 | <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> |
| 43 | <td width="100%"><dl> |
| 44 | <dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a> |
| 45 | </font></dt><dd> |
| 46 | <dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 47 | <dt><font face="helvetica, arial"><a href="apiclient.http.html#BatchHttpRequest">BatchHttpRequest</a> |
| 48 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpMock">HttpMock</a> |
| 49 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpMockSequence">HttpMockSequence</a> |
| 50 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequest">HttpRequest</a> |
| 51 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequestMock">HttpRequestMock</a> |
| 52 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaUpload">MediaUpload</a> |
| 53 | </font></dt><dd> |
| 54 | <dl> |
| 55 | <dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaFileUpload">MediaFileUpload</a> |
| 56 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaInMemoryUpload">MediaInMemoryUpload</a> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 57 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaIoBaseUpload">MediaIoBaseUpload</a> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 58 | </font></dt></dl> |
| 59 | </dd> |
| 60 | <dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaUploadProgress">MediaUploadProgress</a> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 61 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#RequestMockBuilder">RequestMockBuilder</a> |
| 62 | </font></dt></dl> |
| 63 | </dd> |
| 64 | </dl> |
| 65 | <p> |
| 66 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 67 | <tr bgcolor="#ffc8d8"> |
| 68 | <td colspan=3 valign=bottom> <br> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 69 | <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> |
| 70 | |
| 71 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 72 | <td colspan=2><tt>Batches multiple <a href="#HttpRequest">HttpRequest</a> objects into a single HTTP request.<br> </tt></td></tr> |
| 73 | <tr><td> </td> |
| 74 | <td width="100%">Methods defined here:<br> |
| 75 | <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> |
| 76 | <br> |
| 77 | Args:<br> |
| 78 | callback: callable, A callback to be called for each response, of the<br> |
| 79 | form callback(id, response). The first parameter is the request id, and<br> |
| 80 | the second is the deserialized response <a href="__builtin__.html#object">object</a>.<br> |
| 81 | batch_uri: string, URI to send batch requests to.</tt></dd></dl> |
| 82 | |
| 83 | <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> |
| 84 | <br> |
| 85 | Every callback added will be paired with a unique id, the request_id. That<br> |
| 86 | unique id will be passed back to the callback when the response comes back<br> |
| 87 | from the server. The default behavior is to have the library generate it's<br> |
| 88 | own unique id. If the caller passes in a request_id then they must ensure<br> |
| 89 | uniqueness for each request_id, and if they are not an exception is<br> |
| 90 | raised. Callers should either supply all request_ids or nevery supply a<br> |
| 91 | request id, to avoid such an error.<br> |
| 92 | <br> |
| 93 | Args:<br> |
| 94 | request: <a href="#HttpRequest">HttpRequest</a>, Request to add to the batch.<br> |
| 95 | callback: callable, A callback to be called for this response, of the<br> |
| 96 | form callback(id, response). The first parameter is the request id, and<br> |
| 97 | the second is the deserialized response <a href="__builtin__.html#object">object</a>.<br> |
| 98 | request_id: string, A unique id for the request. The id will be passed to<br> |
| 99 | the callback with the response.<br> |
| 100 | <br> |
| 101 | Returns:<br> |
| 102 | None<br> |
| 103 | <br> |
| 104 | Raises:<br> |
| 105 | BatchError if a resumable request is added to a batch.<br> |
| 106 | KeyError is the request_id is not unique.</tt></dd></dl> |
| 107 | |
| 108 | <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> |
| 109 | <br> |
| 110 | Args:<br> |
| 111 | http: httplib2.Http, an http <a href="__builtin__.html#object">object</a> to be used in place of the one the<br> |
| 112 | <a href="#HttpRequest">HttpRequest</a> request <a href="__builtin__.html#object">object</a> was constructed with. If one isn't supplied<br> |
| 113 | then use a http <a href="__builtin__.html#object">object</a> from the requests in this batch.<br> |
| 114 | <br> |
| 115 | Returns:<br> |
| 116 | None<br> |
| 117 | <br> |
| 118 | Raises:<br> |
| 119 | httplib2.Error if a transport error has occured.<br> |
| 120 | apiclient.errors.BatchError if the response is the wrong format.</tt></dd></dl> |
| 121 | |
| 122 | <hr> |
| 123 | Data descriptors defined here:<br> |
| 124 | <dl><dt><strong>__dict__</strong></dt> |
| 125 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 126 | </dl> |
| 127 | <dl><dt><strong>__weakref__</strong></dt> |
| 128 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 129 | </dl> |
| 130 | </td></tr></table> <p> |
| 131 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 132 | <tr bgcolor="#ffc8d8"> |
| 133 | <td colspan=3 valign=bottom> <br> |
| 134 | <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> |
| 135 | |
| 136 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 137 | <td colspan=2><tt>Mock of httplib2.Http<br> </tt></td></tr> |
| 138 | <tr><td> </td> |
| 139 | <td width="100%">Methods defined here:<br> |
| 140 | <dl><dt><a name="HttpMock-__init__"><strong>__init__</strong></a>(self, filename, headers<font color="#909090">=None</font>)</dt><dd><tt>Args:<br> |
| 141 | filename: string, absolute filename to read response from<br> |
| 142 | headers: dict, header to return with response</tt></dd></dl> |
| 143 | |
| 144 | <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> |
| 145 | |
| 146 | <hr> |
| 147 | Data descriptors defined here:<br> |
| 148 | <dl><dt><strong>__dict__</strong></dt> |
| 149 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 150 | </dl> |
| 151 | <dl><dt><strong>__weakref__</strong></dt> |
| 152 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 153 | </dl> |
| 154 | </td></tr></table> <p> |
| 155 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 156 | <tr bgcolor="#ffc8d8"> |
| 157 | <td colspan=3 valign=bottom> <br> |
| 158 | <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> |
| 159 | |
| 160 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 161 | <td colspan=2><tt>Mock of httplib2.Http<br> |
| 162 | <br> |
| 163 | Mocks a sequence of calls to request returning different responses for each<br> |
| 164 | call. Create an instance initialized with the desired response headers<br> |
| 165 | and content and then use as if an httplib2.Http instance.<br> |
| 166 | <br> |
| 167 | http = <a href="#HttpMockSequence">HttpMockSequence</a>([<br> |
| 168 | ({'status': '401'}, ''),<br> |
| 169 | ({'status': '200'}, '{"access_token":"1/3w","expires_in":3600}'),<br> |
| 170 | ({'status': '200'}, 'echo_request_headers'),<br> |
| 171 | ])<br> |
| 172 | resp, content = http.<a href="#HttpMockSequence-request">request</a>("<a href="http://examples.com">http://examples.com</a>")<br> |
| 173 | <br> |
| 174 | There are special values you can pass in for content to trigger<br> |
| 175 | behavours that are helpful in testing.<br> |
| 176 | <br> |
| 177 | 'echo_request_headers' means return the request headers in the response body<br> |
| 178 | 'echo_request_headers_as_json' means return the request headers in<br> |
| 179 | the response body<br> |
| 180 | 'echo_request_body' means return the request body in the response body<br> |
| 181 | 'echo_request_uri' means return the request uri in the response body<br> </tt></td></tr> |
| 182 | <tr><td> </td> |
| 183 | <td width="100%">Methods defined here:<br> |
| 184 | <dl><dt><a name="HttpMockSequence-__init__"><strong>__init__</strong></a>(self, iterable)</dt><dd><tt>Args:<br> |
| 185 | iterable: iterable, a sequence of pairs of (headers, body)</tt></dd></dl> |
| 186 | |
| 187 | <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> |
| 188 | |
| 189 | <hr> |
| 190 | Data descriptors defined here:<br> |
| 191 | <dl><dt><strong>__dict__</strong></dt> |
| 192 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 193 | </dl> |
| 194 | <dl><dt><strong>__weakref__</strong></dt> |
| 195 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 196 | </dl> |
| 197 | </td></tr></table> <p> |
| 198 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 199 | <tr bgcolor="#ffc8d8"> |
| 200 | <td colspan=3 valign=bottom> <br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 201 | <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> |
| 202 | |
| 203 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 204 | <td colspan=2><tt>Encapsulates a single HTTP request.<br> </tt></td></tr> |
| 205 | <tr><td> </td> |
| 206 | <td width="100%">Methods defined here:<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 207 | <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> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 208 | <br> |
| 209 | Args:<br> |
| 210 | http: httplib2.Http, the transport <a href="__builtin__.html#object">object</a> to use to make a request<br> |
Joe Gregorio | abda96f | 2011-02-11 20:19:33 -0500 | [diff] [blame] | 211 | postproc: callable, called on the HTTP response and content to transform<br> |
| 212 | it into a data <a href="__builtin__.html#object">object</a> before returning, or raising an exception<br> |
| 213 | on an error.<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 214 | uri: string, the absolute URI to send the request to<br> |
| 215 | method: string, the HTTP method to use<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 216 | body: string, the request body of the HTTP request,<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 217 | headers: dict, the HTTP request headers<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 218 | methodId: string, a unique identifier for the API method being called.<br> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 219 | resumable: <a href="#MediaUpload">MediaUpload</a>, None if this is not a resumbale request.</tt></dd></dl> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 220 | |
| 221 | <dl><dt><a name="HttpRequest-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute the request.<br> |
| 222 | <br> |
| 223 | Args:<br> |
| 224 | http: httplib2.Http, an http <a href="__builtin__.html#object">object</a> to be used in place of the<br> |
| 225 | one the <a href="#HttpRequest">HttpRequest</a> request <a href="__builtin__.html#object">object</a> was constructed with.<br> |
| 226 | <br> |
| 227 | Returns:<br> |
| 228 | A deserialized <a href="__builtin__.html#object">object</a> model of the response body as determined<br> |
| 229 | by the postproc.<br> |
| 230 | <br> |
| 231 | Raises:<br> |
| 232 | apiclient.errors.HttpError if the response was not a 2xx.<br> |
| 233 | httplib2.Error if a transport error has occured.</tt></dd></dl> |
| 234 | |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 235 | <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> |
| 236 | <br> |
| 237 | Can only be used if the method being executed supports media uploads and<br> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 238 | the <a href="#MediaUpload">MediaUpload</a> <a href="__builtin__.html#object">object</a> passed in was flagged as using resumable upload.<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 239 | <br> |
| 240 | Example:<br> |
| 241 | <br> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 242 | media = <a href="#MediaFileUpload">MediaFileUpload</a>('smiley.png', mimetype='image/png',<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 243 | chunksize=1000, resumable=True)<br> |
| 244 | request = service.objects().insert(<br> |
| 245 | bucket=buckets['items'][0]['id'],<br> |
| 246 | name='smiley.png',<br> |
| 247 | media_body=media)<br> |
| 248 | <br> |
| 249 | response = None<br> |
| 250 | while response is None:<br> |
| 251 | status, response = request.<a href="#HttpRequest-next_chunk">next_chunk</a>()<br> |
| 252 | if status:<br> |
| 253 | print "Upload %d%% complete." % int(status.progress() * 100)<br> |
| 254 | <br> |
| 255 | <br> |
| 256 | Returns:<br> |
| 257 | (status, body): (ResumableMediaStatus, <a href="__builtin__.html#object">object</a>)<br> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 258 | The body will be None until the resumable media is fully uploaded.<br> |
| 259 | <br> |
| 260 | Raises:<br> |
| 261 | apiclient.errors.HttpError if the response was not a 2xx.<br> |
| 262 | httplib2.Error if a transport error has occured.</tt></dd></dl> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 263 | |
| 264 | <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> |
| 265 | |
| 266 | <hr> |
| 267 | Static methods defined here:<br> |
| 268 | <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> |
| 269 | |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 270 | <hr> |
| 271 | Data descriptors defined here:<br> |
| 272 | <dl><dt><strong>__dict__</strong></dt> |
| 273 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 274 | </dl> |
| 275 | <dl><dt><strong>__weakref__</strong></dt> |
| 276 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 277 | </dl> |
| 278 | </td></tr></table> <p> |
| 279 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 280 | <tr bgcolor="#ffc8d8"> |
| 281 | <td colspan=3 valign=bottom> <br> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 282 | <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> |
| 283 | |
| 284 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 285 | <td colspan=2><tt>Mock of <a href="#HttpRequest">HttpRequest</a>.<br> |
| 286 | <br> |
| 287 | Do not construct directly, instead use <a href="#RequestMockBuilder">RequestMockBuilder</a>.<br> </tt></td></tr> |
| 288 | <tr><td> </td> |
| 289 | <td width="100%">Methods defined here:<br> |
| 290 | <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> |
| 291 | <br> |
| 292 | Args:<br> |
| 293 | resp: httplib2.Response, the response to emulate coming from the request<br> |
| 294 | content: string, the response body<br> |
| 295 | postproc: callable, the post processing function usually supplied by<br> |
| 296 | the model class. See model.JsonModel.response() as an example.</tt></dd></dl> |
| 297 | |
| 298 | <dl><dt><a name="HttpRequestMock-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute the request.<br> |
| 299 | <br> |
| 300 | Same behavior as <a href="#HttpRequest">HttpRequest</a>.<a href="#HttpRequestMock-execute">execute</a>(), but the response is<br> |
| 301 | mocked and not really from an HTTP request/response.</tt></dd></dl> |
| 302 | |
| 303 | <hr> |
| 304 | Data descriptors defined here:<br> |
| 305 | <dl><dt><strong>__dict__</strong></dt> |
| 306 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 307 | </dl> |
| 308 | <dl><dt><strong>__weakref__</strong></dt> |
| 309 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 310 | </dl> |
| 311 | </td></tr></table> <p> |
| 312 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 313 | <tr bgcolor="#ffc8d8"> |
| 314 | <td colspan=3 valign=bottom> <br> |
| 315 | <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> |
| 316 | |
| 317 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 318 | <td colspan=2><tt>A <a href="#MediaUpload">MediaUpload</a> for a file.<br> |
| 319 | <br> |
| 320 | Construct a <a href="#MediaFileUpload">MediaFileUpload</a> and pass as the media_body parameter of the<br> |
| 321 | method. For example, if we had a service that allowed uploading images:<br> |
| 322 | <br> |
| 323 | <br> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 324 | media = <a href="#MediaFileUpload">MediaFileUpload</a>('smiley.png', mimetype='image/png',<br> |
| 325 | chunksize=1024*1024, resumable=True)<br> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 326 | service.objects().insert(<br> |
| 327 | bucket=buckets['items'][0]['id'],<br> |
| 328 | name='smiley.png',<br> |
| 329 | media_body=media).execute()<br> </tt></td></tr> |
| 330 | <tr><td> </td> |
| 331 | <td width="100%"><dl><dt>Method resolution order:</dt> |
| 332 | <dd><a href="apiclient.http.html#MediaFileUpload">MediaFileUpload</a></dd> |
| 333 | <dd><a href="apiclient.http.html#MediaUpload">MediaUpload</a></dd> |
| 334 | <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> |
| 335 | </dl> |
| 336 | <hr> |
| 337 | Methods defined here:<br> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 338 | <dl><dt><a name="MediaFileUpload-__init__"><strong>__init__</strong></a>(self, filename, mimetype<font color="#909090">=None</font>, chunksize<font color="#909090">=524288</font>, resumable<font color="#909090">=False</font>)</dt><dd><tt>Constructor.<br> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 339 | <br> |
| 340 | Args:<br> |
| 341 | filename: string, Name of the file.<br> |
| 342 | mimetype: string, Mime-type of the file. If None then a mime-type will be<br> |
| 343 | guessed from the file extension.<br> |
| 344 | chunksize: int, File will be uploaded in chunks of this many bytes. Only<br> |
| 345 | used if resumable=True.<br> |
| 346 | resumable: bool, True if this is a resumable upload. False means upload<br> |
| 347 | in a single request.</tt></dd></dl> |
| 348 | |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 349 | <dl><dt><a name="MediaFileUpload-chunksize"><strong>chunksize</strong></a>(self)</dt><dd><tt>Chunk size for resumable uploads.<br> |
| 350 | <br> |
| 351 | Returns:<br> |
| 352 | Chunk size in bytes.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 353 | |
| 354 | <dl><dt><a name="MediaFileUpload-getbytes"><strong>getbytes</strong></a>(self, begin, length)</dt><dd><tt>Get bytes from the media.<br> |
| 355 | <br> |
| 356 | Args:<br> |
| 357 | begin: int, offset from beginning of file.<br> |
| 358 | length: int, number of bytes to read, starting at begin.<br> |
| 359 | <br> |
| 360 | Returns:<br> |
| 361 | A string of bytes read. May be shorted than length if EOF was reached<br> |
| 362 | first.</tt></dd></dl> |
| 363 | |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 364 | <dl><dt><a name="MediaFileUpload-mimetype"><strong>mimetype</strong></a>(self)</dt><dd><tt>Mime type of the body.<br> |
| 365 | <br> |
| 366 | Returns:<br> |
| 367 | Mime type.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 368 | |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 369 | <dl><dt><a name="MediaFileUpload-resumable"><strong>resumable</strong></a>(self)</dt><dd><tt>Whether this upload is resumable.<br> |
| 370 | <br> |
| 371 | Returns:<br> |
| 372 | True if resumable upload or False.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 373 | |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 374 | <dl><dt><a name="MediaFileUpload-size"><strong>size</strong></a>(self)</dt><dd><tt>Size of upload.<br> |
| 375 | <br> |
| 376 | Returns:<br> |
| 377 | Size of the body, or None of the size is unknown.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 378 | |
| 379 | <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> |
| 380 | <br> |
| 381 | Returns:<br> |
| 382 | string, a JSON representation of this instance, suitable to pass to<br> |
| 383 | <a href="#MediaFileUpload-from_json">from_json</a>().</tt></dd></dl> |
| 384 | |
| 385 | <hr> |
| 386 | Static methods defined here:<br> |
| 387 | <dl><dt><a name="MediaFileUpload-from_json"><strong>from_json</strong></a>(s)</dt></dl> |
| 388 | |
| 389 | <hr> |
| 390 | Class methods inherited from <a href="apiclient.http.html#MediaUpload">MediaUpload</a>:<br> |
| 391 | <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> |
| 392 | representation produced by <a href="#MediaFileUpload-to_json">to_json</a>().<br> |
| 393 | <br> |
| 394 | Args:<br> |
| 395 | s: string, JSON from <a href="#MediaFileUpload-to_json">to_json</a>().<br> |
| 396 | <br> |
| 397 | Returns:<br> |
| 398 | An instance of the subclass of <a href="#MediaUpload">MediaUpload</a> that was serialized with<br> |
| 399 | <a href="#MediaFileUpload-to_json">to_json</a>().</tt></dd></dl> |
| 400 | |
| 401 | <hr> |
| 402 | Data descriptors inherited from <a href="apiclient.http.html#MediaUpload">MediaUpload</a>:<br> |
| 403 | <dl><dt><strong>__dict__</strong></dt> |
| 404 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 405 | </dl> |
| 406 | <dl><dt><strong>__weakref__</strong></dt> |
| 407 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 408 | </dl> |
| 409 | </td></tr></table> <p> |
| 410 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 411 | <tr bgcolor="#ffc8d8"> |
| 412 | <td colspan=3 valign=bottom> <br> |
| 413 | <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> |
| 414 | |
| 415 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 416 | <td colspan=2><tt><a href="#MediaUpload">MediaUpload</a> for a chunk of bytes.<br> |
| 417 | <br> |
| 418 | Construct a <a href="#MediaFileUpload">MediaFileUpload</a> and pass as the media_body parameter of the<br> |
| 419 | method. For example, if we had a service that allowed plain text:<br> </tt></td></tr> |
| 420 | <tr><td> </td> |
| 421 | <td width="100%"><dl><dt>Method resolution order:</dt> |
| 422 | <dd><a href="apiclient.http.html#MediaInMemoryUpload">MediaInMemoryUpload</a></dd> |
| 423 | <dd><a href="apiclient.http.html#MediaUpload">MediaUpload</a></dd> |
| 424 | <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> |
| 425 | </dl> |
| 426 | <hr> |
| 427 | Methods defined here:<br> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 428 | <dl><dt><a name="MediaInMemoryUpload-__init__"><strong>__init__</strong></a>(self, body, mimetype<font color="#909090">='application/octet-stream'</font>, chunksize<font color="#909090">=524288</font>, resumable<font color="#909090">=False</font>)</dt><dd><tt>Create a new MediaBytesUpload.<br> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 429 | <br> |
| 430 | Args:<br> |
| 431 | body: string, Bytes of body content.<br> |
| 432 | mimetype: string, Mime-type of the file or default of<br> |
| 433 | 'application/octet-stream'.<br> |
| 434 | chunksize: int, File will be uploaded in chunks of this many bytes. Only<br> |
| 435 | used if resumable=True.<br> |
| 436 | resumable: bool, True if this is a resumable upload. False means upload<br> |
| 437 | in a single request.</tt></dd></dl> |
| 438 | |
| 439 | <dl><dt><a name="MediaInMemoryUpload-chunksize"><strong>chunksize</strong></a>(self)</dt><dd><tt>Chunk size for resumable uploads.<br> |
| 440 | <br> |
| 441 | Returns:<br> |
| 442 | Chunk size in bytes.</tt></dd></dl> |
| 443 | |
| 444 | <dl><dt><a name="MediaInMemoryUpload-getbytes"><strong>getbytes</strong></a>(self, begin, length)</dt><dd><tt>Get bytes from the media.<br> |
| 445 | <br> |
| 446 | Args:<br> |
| 447 | begin: int, offset from beginning of file.<br> |
| 448 | length: int, number of bytes to read, starting at begin.<br> |
| 449 | <br> |
| 450 | Returns:<br> |
| 451 | A string of bytes read. May be shorter than length if EOF was reached<br> |
| 452 | first.</tt></dd></dl> |
| 453 | |
| 454 | <dl><dt><a name="MediaInMemoryUpload-mimetype"><strong>mimetype</strong></a>(self)</dt><dd><tt>Mime type of the body.<br> |
| 455 | <br> |
| 456 | Returns:<br> |
| 457 | Mime type.</tt></dd></dl> |
| 458 | |
| 459 | <dl><dt><a name="MediaInMemoryUpload-resumable"><strong>resumable</strong></a>(self)</dt><dd><tt>Whether this upload is resumable.<br> |
| 460 | <br> |
| 461 | Returns:<br> |
| 462 | True if resumable upload or False.</tt></dd></dl> |
| 463 | |
| 464 | <dl><dt><a name="MediaInMemoryUpload-size"><strong>size</strong></a>(self)</dt><dd><tt>Size of upload.<br> |
| 465 | <br> |
| 466 | Returns:<br> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 467 | Size of the body, or None of the size is unknown.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 468 | |
| 469 | <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> |
| 470 | <br> |
| 471 | Returns:<br> |
| 472 | string, a JSON representation of this instance, suitable to pass to<br> |
| 473 | <a href="#MediaInMemoryUpload-from_json">from_json</a>().</tt></dd></dl> |
| 474 | |
| 475 | <hr> |
| 476 | Static methods defined here:<br> |
| 477 | <dl><dt><a name="MediaInMemoryUpload-from_json"><strong>from_json</strong></a>(s)</dt></dl> |
| 478 | |
| 479 | <hr> |
| 480 | Class methods inherited from <a href="apiclient.http.html#MediaUpload">MediaUpload</a>:<br> |
| 481 | <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> |
| 482 | representation produced by <a href="#MediaInMemoryUpload-to_json">to_json</a>().<br> |
| 483 | <br> |
| 484 | Args:<br> |
| 485 | s: string, JSON from <a href="#MediaInMemoryUpload-to_json">to_json</a>().<br> |
| 486 | <br> |
| 487 | Returns:<br> |
| 488 | An instance of the subclass of <a href="#MediaUpload">MediaUpload</a> that was serialized with<br> |
| 489 | <a href="#MediaInMemoryUpload-to_json">to_json</a>().</tt></dd></dl> |
| 490 | |
| 491 | <hr> |
| 492 | Data descriptors inherited from <a href="apiclient.http.html#MediaUpload">MediaUpload</a>:<br> |
| 493 | <dl><dt><strong>__dict__</strong></dt> |
| 494 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 495 | </dl> |
| 496 | <dl><dt><strong>__weakref__</strong></dt> |
| 497 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 498 | </dl> |
| 499 | </td></tr></table> <p> |
| 500 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 501 | <tr bgcolor="#ffc8d8"> |
| 502 | <td colspan=3 valign=bottom> <br> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 503 | <font color="#000000" face="helvetica, arial"><a name="MediaIoBaseUpload">class <strong>MediaIoBaseUpload</strong></a>(<a href="apiclient.http.html#MediaUpload">MediaUpload</a>)</font></td></tr> |
| 504 | |
| 505 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 506 | <td colspan=2><tt>A <a href="#MediaUpload">MediaUpload</a> for a io.Base objects.<br> |
| 507 | <br> |
| 508 | Note that the Python file <a href="__builtin__.html#object">object</a> is compatible with io.Base and can be used<br> |
| 509 | with this class also.<br> |
| 510 | <br> |
| 511 | <br> |
| 512 | fh = io.BytesIO('...Some data to upload...')<br> |
| 513 | media = <a href="#MediaIoBaseUpload">MediaIoBaseUpload</a>(fh, mimetype='image/png',<br> |
| 514 | chunksize=1024*1024, resumable=True)<br> |
| 515 | service.objects().insert(<br> |
| 516 | bucket='a_bucket_id',<br> |
| 517 | name='smiley.png',<br> |
| 518 | media_body=media).execute()<br> </tt></td></tr> |
| 519 | <tr><td> </td> |
| 520 | <td width="100%"><dl><dt>Method resolution order:</dt> |
| 521 | <dd><a href="apiclient.http.html#MediaIoBaseUpload">MediaIoBaseUpload</a></dd> |
| 522 | <dd><a href="apiclient.http.html#MediaUpload">MediaUpload</a></dd> |
| 523 | <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> |
| 524 | </dl> |
| 525 | <hr> |
| 526 | Methods defined here:<br> |
| 527 | <dl><dt><a name="MediaIoBaseUpload-__init__"><strong>__init__</strong></a>(self, fh, mimetype, chunksize<font color="#909090">=524288</font>, resumable<font color="#909090">=False</font>)</dt><dd><tt>Constructor.<br> |
| 528 | <br> |
| 529 | Args:<br> |
| 530 | fh: io.Base or file <a href="__builtin__.html#object">object</a>, The source of the bytes to upload.<br> |
| 531 | mimetype: string, Mime-type of the file. If None then a mime-type will be<br> |
| 532 | guessed from the file extension.<br> |
| 533 | chunksize: int, File will be uploaded in chunks of this many bytes. Only<br> |
| 534 | used if resumable=True.<br> |
| 535 | resumable: bool, True if this is a resumable upload. False means upload<br> |
| 536 | in a single request.</tt></dd></dl> |
| 537 | |
| 538 | <dl><dt><a name="MediaIoBaseUpload-chunksize"><strong>chunksize</strong></a>(self)</dt><dd><tt>Chunk size for resumable uploads.<br> |
| 539 | <br> |
| 540 | Returns:<br> |
| 541 | Chunk size in bytes.</tt></dd></dl> |
| 542 | |
| 543 | <dl><dt><a name="MediaIoBaseUpload-getbytes"><strong>getbytes</strong></a>(self, begin, length)</dt><dd><tt>Get bytes from the media.<br> |
| 544 | <br> |
| 545 | Args:<br> |
| 546 | begin: int, offset from beginning of file.<br> |
| 547 | length: int, number of bytes to read, starting at begin.<br> |
| 548 | <br> |
| 549 | Returns:<br> |
| 550 | A string of bytes read. May be shorted than length if EOF was reached<br> |
| 551 | first.</tt></dd></dl> |
| 552 | |
| 553 | <dl><dt><a name="MediaIoBaseUpload-mimetype"><strong>mimetype</strong></a>(self)</dt><dd><tt>Mime type of the body.<br> |
| 554 | <br> |
| 555 | Returns:<br> |
| 556 | Mime type.</tt></dd></dl> |
| 557 | |
| 558 | <dl><dt><a name="MediaIoBaseUpload-resumable"><strong>resumable</strong></a>(self)</dt><dd><tt>Whether this upload is resumable.<br> |
| 559 | <br> |
| 560 | Returns:<br> |
| 561 | True if resumable upload or False.</tt></dd></dl> |
| 562 | |
| 563 | <dl><dt><a name="MediaIoBaseUpload-size"><strong>size</strong></a>(self)</dt><dd><tt>Size of upload.<br> |
| 564 | <br> |
| 565 | Returns:<br> |
| 566 | Size of the body, or None of the size is unknown.</tt></dd></dl> |
| 567 | |
| 568 | <dl><dt><a name="MediaIoBaseUpload-to_json"><strong>to_json</strong></a>(self)</dt><dd><tt>This upload type is not serializable.</tt></dd></dl> |
| 569 | |
| 570 | <hr> |
| 571 | Class methods inherited from <a href="apiclient.http.html#MediaUpload">MediaUpload</a>:<br> |
| 572 | <dl><dt><a name="MediaIoBaseUpload-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> |
| 573 | representation produced by <a href="#MediaIoBaseUpload-to_json">to_json</a>().<br> |
| 574 | <br> |
| 575 | Args:<br> |
| 576 | s: string, JSON from <a href="#MediaIoBaseUpload-to_json">to_json</a>().<br> |
| 577 | <br> |
| 578 | Returns:<br> |
| 579 | An instance of the subclass of <a href="#MediaUpload">MediaUpload</a> that was serialized with<br> |
| 580 | <a href="#MediaIoBaseUpload-to_json">to_json</a>().</tt></dd></dl> |
| 581 | |
| 582 | <hr> |
| 583 | Data descriptors inherited from <a href="apiclient.http.html#MediaUpload">MediaUpload</a>:<br> |
| 584 | <dl><dt><strong>__dict__</strong></dt> |
| 585 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 586 | </dl> |
| 587 | <dl><dt><strong>__weakref__</strong></dt> |
| 588 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 589 | </dl> |
| 590 | </td></tr></table> <p> |
| 591 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 592 | <tr bgcolor="#ffc8d8"> |
| 593 | <td colspan=3 valign=bottom> <br> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 594 | <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> |
| 595 | |
| 596 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 597 | <td colspan=2><tt>Describes a media <a href="__builtin__.html#object">object</a> to upload.<br> |
| 598 | <br> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 599 | Base class that defines the interface of <a href="#MediaUpload">MediaUpload</a> subclasses.<br> |
| 600 | <br> |
| 601 | Note that subclasses of <a href="#MediaUpload">MediaUpload</a> may allow you to control the chunksize<br> |
| 602 | when upload a media <a href="__builtin__.html#object">object</a>. It is important to keep the size of the chunk as<br> |
| 603 | large as possible to keep the upload efficient. Other factors may influence<br> |
| 604 | the size of the chunk you use, particularly if you are working in an<br> |
| 605 | environment where individual HTTP requests may have a hardcoded time limit,<br> |
| 606 | such as under certain classes of requests under Google App Engine.<br> </tt></td></tr> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 607 | <tr><td> </td> |
| 608 | <td width="100%">Methods defined here:<br> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 609 | <dl><dt><a name="MediaUpload-chunksize"><strong>chunksize</strong></a>(self)</dt><dd><tt>Chunk size for resumable uploads.<br> |
| 610 | <br> |
| 611 | Returns:<br> |
| 612 | Chunk size in bytes.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 613 | |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 614 | <dl><dt><a name="MediaUpload-getbytes"><strong>getbytes</strong></a>(self, begin, end)</dt><dd><tt>Get bytes from the media.<br> |
| 615 | <br> |
| 616 | Args:<br> |
| 617 | begin: int, offset from beginning of file.<br> |
| 618 | length: int, number of bytes to read, starting at begin.<br> |
| 619 | <br> |
| 620 | Returns:<br> |
| 621 | A string of bytes read. May be shorter than length if EOF was reached<br> |
| 622 | first.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 623 | |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 624 | <dl><dt><a name="MediaUpload-mimetype"><strong>mimetype</strong></a>(self)</dt><dd><tt>Mime type of the body.<br> |
| 625 | <br> |
| 626 | Returns:<br> |
| 627 | Mime type.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 628 | |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 629 | <dl><dt><a name="MediaUpload-resumable"><strong>resumable</strong></a>(self)</dt><dd><tt>Whether this upload is resumable.<br> |
| 630 | <br> |
| 631 | Returns:<br> |
| 632 | True if resumable upload or False.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 633 | |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 634 | <dl><dt><a name="MediaUpload-size"><strong>size</strong></a>(self)</dt><dd><tt>Size of upload.<br> |
| 635 | <br> |
| 636 | Returns:<br> |
| 637 | Size of the body, or None of the size is unknown.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 638 | |
| 639 | <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> |
| 640 | <br> |
| 641 | Returns:<br> |
| 642 | string, a JSON representation of this instance, suitable to pass to<br> |
| 643 | from_json().</tt></dd></dl> |
| 644 | |
| 645 | <hr> |
| 646 | Class methods defined here:<br> |
| 647 | <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> |
| 648 | representation produced by <a href="#MediaUpload-to_json">to_json</a>().<br> |
| 649 | <br> |
| 650 | Args:<br> |
| 651 | s: string, JSON from <a href="#MediaUpload-to_json">to_json</a>().<br> |
| 652 | <br> |
| 653 | Returns:<br> |
| 654 | An instance of the subclass of <a href="#MediaUpload">MediaUpload</a> that was serialized with<br> |
| 655 | <a href="#MediaUpload-to_json">to_json</a>().</tt></dd></dl> |
| 656 | |
| 657 | <hr> |
| 658 | Data descriptors defined here:<br> |
| 659 | <dl><dt><strong>__dict__</strong></dt> |
| 660 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 661 | </dl> |
| 662 | <dl><dt><strong>__weakref__</strong></dt> |
| 663 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 664 | </dl> |
| 665 | </td></tr></table> <p> |
| 666 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 667 | <tr bgcolor="#ffc8d8"> |
| 668 | <td colspan=3 valign=bottom> <br> |
| 669 | <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> |
| 670 | |
| 671 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 672 | <td colspan=2><tt>Status of a resumable upload.<br> </tt></td></tr> |
| 673 | <tr><td> </td> |
| 674 | <td width="100%">Methods defined here:<br> |
| 675 | <dl><dt><a name="MediaUploadProgress-__init__"><strong>__init__</strong></a>(self, resumable_progress, total_size)</dt><dd><tt>Constructor.<br> |
| 676 | <br> |
| 677 | Args:<br> |
| 678 | resumable_progress: int, bytes sent so far.<br> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 679 | total_size: int, total bytes in complete upload, or None if the total<br> |
| 680 | upload size isn't known ahead of time.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 681 | |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 682 | <dl><dt><a name="MediaUploadProgress-progress"><strong>progress</strong></a>(self)</dt><dd><tt>Percent of upload completed, as a float.<br> |
| 683 | <br> |
| 684 | Returns:<br> |
| 685 | the percentage complete as a float, returning 0.0 if the total size of<br> |
| 686 | the upload is unknown.</tt></dd></dl> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 687 | |
| 688 | <hr> |
| 689 | Data descriptors defined here:<br> |
| 690 | <dl><dt><strong>__dict__</strong></dt> |
| 691 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 692 | </dl> |
| 693 | <dl><dt><strong>__weakref__</strong></dt> |
| 694 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 695 | </dl> |
| 696 | </td></tr></table> <p> |
| 697 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 698 | <tr bgcolor="#ffc8d8"> |
| 699 | <td colspan=3 valign=bottom> <br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 700 | <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> |
| 701 | |
| 702 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 703 | <td colspan=2><tt>A simple mock of <a href="#HttpRequest">HttpRequest</a><br> |
| 704 | <br> |
| 705 | Pass in a dictionary to the constructor that maps request methodIds to<br> |
Joe Gregorio | a845167 | 2011-09-15 09:53:21 -0400 | [diff] [blame] | 706 | tuples of (httplib2.Response, content, opt_expected_body) that should be<br> |
| 707 | returned when that method is called. None may also be passed in for the<br> |
| 708 | httplib2.Response, in which case a 200 OK response will be generated.<br> |
| 709 | If an opt_expected_body (str or dict) is provided, it will be compared to<br> |
| 710 | the body and UnexpectedBodyError will be raised on inequality.<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 711 | <br> |
| 712 | Example:<br> |
| 713 | response = '{"data": {"id": "tag:google.c...'<br> |
| 714 | requestBuilder = <a href="#RequestMockBuilder">RequestMockBuilder</a>(<br> |
| 715 | {<br> |
Joe Gregorio | c4fc095 | 2011-11-09 12:21:11 -0500 | [diff] [blame] | 716 | 'plus.activities.get': (None, response),<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 717 | }<br> |
| 718 | )<br> |
Joe Gregorio | c4fc095 | 2011-11-09 12:21:11 -0500 | [diff] [blame] | 719 | apiclient.discovery.build("plus", "v1", requestBuilder=requestBuilder)<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 720 | <br> |
| 721 | Methods that you do not supply a response for will return a<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 722 | 200 OK with an empty string as the response content or raise an excpetion<br> |
| 723 | if check_unexpected is set to True. The methodId is taken from the rpcName<br> |
Joe Gregorio | a845167 | 2011-09-15 09:53:21 -0400 | [diff] [blame] | 724 | in the discovery document.<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 725 | <br> |
| 726 | For more details see the project wiki.<br> </tt></td></tr> |
| 727 | <tr><td> </td> |
| 728 | <td width="100%">Methods defined here:<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 729 | <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> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 730 | of requestBuilder, which is to build an <a href="__builtin__.html#object">object</a> compatible with<br> |
| 731 | <a href="#HttpRequest">HttpRequest</a>.execute(). See that method for the description of the<br> |
| 732 | parameters and the expected response.</tt></dd></dl> |
| 733 | |
Joe Gregorio | a845167 | 2011-09-15 09:53:21 -0400 | [diff] [blame] | 734 | <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> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 735 | <br> |
| 736 | The constructed <a href="__builtin__.html#object">object</a> should be a callable <a href="__builtin__.html#object">object</a><br> |
| 737 | that can replace the class HttpResponse.<br> |
| 738 | <br> |
| 739 | responses - A dictionary that maps methodIds into tuples<br> |
| 740 | of (httplib2.Response, content). The methodId<br> |
| 741 | comes from the 'rpcName' field in the discovery<br> |
Joe Gregorio | a845167 | 2011-09-15 09:53:21 -0400 | [diff] [blame] | 742 | document.<br> |
| 743 | check_unexpected - A boolean setting whether or not UnexpectedMethodError<br> |
| 744 | should be raised on unsupplied method.</tt></dd></dl> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 745 | |
| 746 | <hr> |
| 747 | Data descriptors defined here:<br> |
| 748 | <dl><dt><strong>__dict__</strong></dt> |
| 749 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 750 | </dl> |
| 751 | <dl><dt><strong>__weakref__</strong></dt> |
| 752 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 753 | </dl> |
| 754 | </td></tr></table></td></tr></table><p> |
| 755 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 756 | <tr bgcolor="#eeaa77"> |
| 757 | <td colspan=3 valign=bottom> <br> |
| 758 | <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> |
| 759 | |
| 760 | <tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> |
Joe Gregorio | d9d0090 | 2012-04-13 07:58:30 -0400 | [diff] [blame] | 761 | <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> |
| 762 | <br> |
| 763 | Args:<br> |
| 764 | http - An instance of httplib2.Http<br> |
| 765 | or something that acts like it.<br> |
| 766 | user_agent: string, the value for the user-agent header.<br> |
| 767 | <br> |
| 768 | Returns:<br> |
| 769 | A modified instance of http that was passed in.<br> |
| 770 | <br> |
| 771 | Example:<br> |
| 772 | <br> |
| 773 | h = httplib2.Http()<br> |
| 774 | h = <a href="#-set_user_agent">set_user_agent</a>(h, "my-app-name/6.0")<br> |
| 775 | <br> |
| 776 | Most of the time the user-agent will be set doing auth, this is for the rare<br> |
| 777 | cases where you are accessing an unauthenticated endpoint.</tt></dd></dl> |
| 778 | <dl><dt><a name="-tunnel_patch"><strong>tunnel_patch</strong></a>(http)</dt><dd><tt>Tunnel PATCH requests over POST.<br> |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 779 | Args:<br> |
| 780 | http - An instance of httplib2.Http<br> |
| 781 | or something that acts like it.<br> |
| 782 | <br> |
| 783 | Returns:<br> |
| 784 | A modified instance of http that was passed in.<br> |
| 785 | <br> |
| 786 | Example:<br> |
| 787 | <br> |
| 788 | h = httplib2.Http()<br> |
| 789 | h = <a href="#-tunnel_patch">tunnel_patch</a>(h, "my-app-name/6.0")<br> |
| 790 | <br> |
| 791 | Useful if you are running on a platform that doesn't support PATCH.<br> |
| 792 | Apply this last if you are using OAuth 1.0, as changing the method<br> |
| 793 | will result in a different signature.</tt></dd></dl> |
| 794 | </td></tr></table><p> |
| 795 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 796 | <tr bgcolor="#55aa55"> |
| 797 | <td colspan=3 valign=bottom> <br> |
| 798 | <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
| 799 | |
| 800 | <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
Joe Gregorio | 6621203 | 2012-06-14 09:10:14 -0400 | [diff] [blame^] | 801 | <td width="100%"><strong>DEFAULT_CHUNK_SIZE</strong> = 524288<br> |
| 802 | <strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 803 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 804 | <tr bgcolor="#7799ee"> |
| 805 | <td colspan=3 valign=bottom> <br> |
| 806 | <font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr> |
| 807 | |
| 808 | <tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td> |
| 809 | <td width="100%">jcgregorio@google.com (Joe Gregorio)</td></tr></table> |
| 810 | </body></html> |