README 2.5 KB

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