• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1httplib2 for Python 3
2
3This directory contains a port of httplib2 to Python 3. As you may
4know, Python 3 is not backward-compatible with Python 2. The biggest
5change in Python 3 (that affects httplib2) is the distinction between
6bytes and strings.
7
8To successfully use http2lib for Python 3, you absolutely must
9understand the following sentence:
10
11** THE RESPONSE HEADERS ARE STRINGS, BUT THE CONTENT BODY IS BYTES **
12
13
14Example:
15
16>>> import httplib2, pprint
17>>> h = httplib2.Http(".cache")
18>>> (resp_headers, content) = h.request("http://example.org/", "GET")
19>>> pprint.pprint(resp_headers)
20{'accept-ranges': 'bytes',
21 'connection': 'close',
22 'content-length': '438',
23 'content-location': 'http://example.org/',
24 'content-type': 'text/html; charset=UTF-8',
25 'date': 'Fri, 29 May 2009 03:57:29 GMT',
26 'etag': '"b80f4-1b6-80bfd280"',
27 'last-modified': 'Tue, 15 Nov 2005 13:24:10 GMT',
28 'server': 'Apache/2.2.3 (CentOS)',
29 'status': '200'}
30>>> type(content)
31<class 'bytes'>
32>>> content[:49]
33b'<HTML>\r\n<HEAD>\r\n  <TITLE>Example Web Page</TITLE>'
34
35
36Further reading:
37
38  * http://diveintopython3.org/strings.html
39  * http://docs.python.org/3.0/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit
40  * http://docs.python.org/3.0/howto/unicode.html
41
42
43--------------------------------------------------------------------
44Httplib2 Software License
45
46Copyright (c) 2006 by Joe Gregorio
47Copyright (c) 2009 by Mark Pilgrim
48
49Permission is hereby granted, free of charge, to any person
50obtaining a copy of this software and associated documentation
51files (the "Software"), to deal in the Software without restriction,
52including without limitation the rights to use, copy, modify, merge,
53publish, distribute, sublicense, and/or sell copies of the Software,
54and to permit persons to whom the Software is furnished to do so,
55subject to the following conditions:
56
57The above copyright notice and this permission notice shall be
58included in all copies or substantial portions of the Software.
59
60THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
61EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
62OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
63NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
64BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
65ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
66CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
67SOFTWARE.
68
69