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 | 3d55ac5 | 2012-02-21 10:11:19 -0500 | [diff] [blame^] | 11 | ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/jcgregorio/projects/apiclient-release/apiclient/http.py">/usr/local/google/home/jcgregorio/projects/apiclient-release/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 | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 47 | <dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequest">HttpRequest</a> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 48 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#RequestMockBuilder">RequestMockBuilder</a> |
| 49 | </font></dt></dl> |
| 50 | </dd> |
| 51 | </dl> |
| 52 | <p> |
| 53 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 54 | <tr bgcolor="#ffc8d8"> |
| 55 | <td colspan=3 valign=bottom> <br> |
| 56 | <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> |
| 57 | |
| 58 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 59 | <td colspan=2><tt>Encapsulates a single HTTP request.<br> </tt></td></tr> |
| 60 | <tr><td> </td> |
| 61 | <td width="100%">Methods defined here:<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 62 | <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] | 63 | <br> |
| 64 | Args:<br> |
| 65 | 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] | 66 | postproc: callable, called on the HTTP response and content to transform<br> |
| 67 | it into a data <a href="__builtin__.html#object">object</a> before returning, or raising an exception<br> |
| 68 | on an error.<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 69 | uri: string, the absolute URI to send the request to<br> |
| 70 | method: string, the HTTP method to use<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 71 | body: string, the request body of the HTTP request,<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 72 | headers: dict, the HTTP request headers<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 73 | methodId: string, a unique identifier for the API method being called.<br> |
| 74 | resumable: MediaUpload, None if this is not a resumbale request.</tt></dd></dl> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 75 | |
| 76 | <dl><dt><a name="HttpRequest-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute the request.<br> |
| 77 | <br> |
| 78 | Args:<br> |
| 79 | http: httplib2.Http, an http <a href="__builtin__.html#object">object</a> to be used in place of the<br> |
| 80 | one the <a href="#HttpRequest">HttpRequest</a> request <a href="__builtin__.html#object">object</a> was constructed with.<br> |
| 81 | <br> |
| 82 | Returns:<br> |
| 83 | A deserialized <a href="__builtin__.html#object">object</a> model of the response body as determined<br> |
| 84 | by the postproc.<br> |
| 85 | <br> |
| 86 | Raises:<br> |
| 87 | apiclient.errors.HttpError if the response was not a 2xx.<br> |
| 88 | httplib2.Error if a transport error has occured.</tt></dd></dl> |
| 89 | |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 90 | <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> |
| 91 | <br> |
| 92 | Can only be used if the method being executed supports media uploads and<br> |
| 93 | the MediaUpload <a href="__builtin__.html#object">object</a> passed in was flagged as using resumable upload.<br> |
| 94 | <br> |
| 95 | Example:<br> |
| 96 | <br> |
| 97 | media = MediaFileUpload('smiley.png', mimetype='image/png',<br> |
| 98 | chunksize=1000, resumable=True)<br> |
| 99 | request = service.objects().insert(<br> |
| 100 | bucket=buckets['items'][0]['id'],<br> |
| 101 | name='smiley.png',<br> |
| 102 | media_body=media)<br> |
| 103 | <br> |
| 104 | response = None<br> |
| 105 | while response is None:<br> |
| 106 | status, response = request.<a href="#HttpRequest-next_chunk">next_chunk</a>()<br> |
| 107 | if status:<br> |
| 108 | print "Upload %d%% complete." % int(status.progress() * 100)<br> |
| 109 | <br> |
| 110 | <br> |
| 111 | Returns:<br> |
| 112 | (status, body): (ResumableMediaStatus, <a href="__builtin__.html#object">object</a>)<br> |
| 113 | The body will be None until the resumable media is fully uploaded.</tt></dd></dl> |
| 114 | |
| 115 | <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> |
| 116 | |
| 117 | <hr> |
| 118 | Static methods defined here:<br> |
| 119 | <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> |
| 120 | |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 121 | <hr> |
| 122 | Data descriptors defined here:<br> |
| 123 | <dl><dt><strong>__dict__</strong></dt> |
| 124 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 125 | </dl> |
| 126 | <dl><dt><strong>__weakref__</strong></dt> |
| 127 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 128 | </dl> |
| 129 | </td></tr></table> <p> |
| 130 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 131 | <tr bgcolor="#ffc8d8"> |
| 132 | <td colspan=3 valign=bottom> <br> |
| 133 | <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> |
| 134 | |
| 135 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 136 | <td colspan=2><tt>A simple mock of <a href="#HttpRequest">HttpRequest</a><br> |
| 137 | <br> |
| 138 | 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] | 139 | tuples of (httplib2.Response, content, opt_expected_body) that should be<br> |
| 140 | returned when that method is called. None may also be passed in for the<br> |
| 141 | httplib2.Response, in which case a 200 OK response will be generated.<br> |
| 142 | If an opt_expected_body (str or dict) is provided, it will be compared to<br> |
| 143 | the body and UnexpectedBodyError will be raised on inequality.<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 144 | <br> |
| 145 | Example:<br> |
| 146 | response = '{"data": {"id": "tag:google.c...'<br> |
| 147 | requestBuilder = <a href="#RequestMockBuilder">RequestMockBuilder</a>(<br> |
| 148 | {<br> |
Joe Gregorio | c4fc095 | 2011-11-09 12:21:11 -0500 | [diff] [blame] | 149 | 'plus.activities.get': (None, response),<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 150 | }<br> |
| 151 | )<br> |
Joe Gregorio | c4fc095 | 2011-11-09 12:21:11 -0500 | [diff] [blame] | 152 | apiclient.discovery.build("plus", "v1", requestBuilder=requestBuilder)<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 153 | <br> |
| 154 | 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] | 155 | 200 OK with an empty string as the response content or raise an excpetion<br> |
| 156 | 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] | 157 | in the discovery document.<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 158 | <br> |
| 159 | For more details see the project wiki.<br> </tt></td></tr> |
| 160 | <tr><td> </td> |
| 161 | <td width="100%">Methods defined here:<br> |
Joe Gregorio | b417caf | 2011-12-08 12:04:24 -0500 | [diff] [blame] | 162 | <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] | 163 | of requestBuilder, which is to build an <a href="__builtin__.html#object">object</a> compatible with<br> |
| 164 | <a href="#HttpRequest">HttpRequest</a>.execute(). See that method for the description of the<br> |
| 165 | parameters and the expected response.</tt></dd></dl> |
| 166 | |
Joe Gregorio | a845167 | 2011-09-15 09:53:21 -0400 | [diff] [blame] | 167 | <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] | 168 | <br> |
| 169 | The constructed <a href="__builtin__.html#object">object</a> should be a callable <a href="__builtin__.html#object">object</a><br> |
| 170 | that can replace the class HttpResponse.<br> |
| 171 | <br> |
| 172 | responses - A dictionary that maps methodIds into tuples<br> |
| 173 | of (httplib2.Response, content). The methodId<br> |
| 174 | comes from the 'rpcName' field in the discovery<br> |
Joe Gregorio | a845167 | 2011-09-15 09:53:21 -0400 | [diff] [blame] | 175 | document.<br> |
| 176 | check_unexpected - A boolean setting whether or not UnexpectedMethodError<br> |
| 177 | should be raised on unsupplied method.</tt></dd></dl> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 178 | |
| 179 | <hr> |
| 180 | Data descriptors defined here:<br> |
| 181 | <dl><dt><strong>__dict__</strong></dt> |
| 182 | <dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 183 | </dl> |
| 184 | <dl><dt><strong>__weakref__</strong></dt> |
| 185 | <dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 186 | </dl> |
| 187 | </td></tr></table></td></tr></table><p> |
| 188 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 189 | <tr bgcolor="#eeaa77"> |
| 190 | <td colspan=3 valign=bottom> <br> |
| 191 | <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> |
| 192 | |
| 193 | <tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> |
| 194 | <td width="100%"><dl><dt><a name="-tunnel_patch"><strong>tunnel_patch</strong></a>(http)</dt><dd><tt>Tunnel PATCH requests over POST.<br> |
| 195 | Args:<br> |
| 196 | http - An instance of httplib2.Http<br> |
| 197 | or something that acts like it.<br> |
| 198 | <br> |
| 199 | Returns:<br> |
| 200 | A modified instance of http that was passed in.<br> |
| 201 | <br> |
| 202 | Example:<br> |
| 203 | <br> |
| 204 | h = httplib2.Http()<br> |
| 205 | h = <a href="#-tunnel_patch">tunnel_patch</a>(h, "my-app-name/6.0")<br> |
| 206 | <br> |
| 207 | Useful if you are running on a platform that doesn't support PATCH.<br> |
| 208 | Apply this last if you are using OAuth 1.0, as changing the method<br> |
| 209 | will result in a different signature.</tt></dd></dl> |
| 210 | </td></tr></table><p> |
| 211 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 212 | <tr bgcolor="#55aa55"> |
| 213 | <td colspan=3 valign=bottom> <br> |
| 214 | <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> |
| 215 | |
| 216 | <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> |
Joe Gregorio | 20a5aa9 | 2011-04-01 17:44:25 -0400 | [diff] [blame] | 217 | <td width="100%"><strong>__all__</strong> = ['HttpRequest', 'RequestMockBuilder', 'HttpMockset_user_agent', 'tunnel_patch']<br> |
Joe Gregorio | 30dfdc3 | 2010-12-09 16:34:22 -0500 | [diff] [blame] | 218 | <strong>__author__</strong> = 'jcgregorio@google.com (Joe Gregorio)'</td></tr></table><p> |
| 219 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 220 | <tr bgcolor="#7799ee"> |
| 221 | <td colspan=3 valign=bottom> <br> |
| 222 | <font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr> |
| 223 | |
| 224 | <tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td> |
| 225 | <td width="100%">jcgregorio@google.com (Joe Gregorio)</td></tr></table> |
| 226 | </body></html> |