com.googler.python 1.0.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/package.json +1 -1
  2. package/python3.4.2/lib/python3.4/site-packages/pip/__init__.py +1 -277
  3. package/python3.4.2/lib/python3.4/site-packages/pip/__main__.py +19 -7
  4. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/__init__.py +246 -0
  5. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/basecommand.py +373 -0
  6. package/python3.4.2/lib/python3.4/site-packages/pip/{baseparser.py → _internal/baseparser.py} +240 -224
  7. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/build_env.py +92 -0
  8. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/cache.py +202 -0
  9. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/cmdoptions.py +609 -0
  10. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/__init__.py +79 -0
  11. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/check.py +42 -0
  12. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/completion.py +94 -0
  13. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/configuration.py +227 -0
  14. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/download.py +233 -0
  15. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/freeze.py +96 -0
  16. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/hash.py +57 -0
  17. package/python3.4.2/lib/python3.4/site-packages/pip/{commands → _internal/commands}/help.py +36 -33
  18. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/install.py +477 -0
  19. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/list.py +343 -0
  20. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/search.py +135 -0
  21. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/show.py +164 -0
  22. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/uninstall.py +71 -0
  23. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/commands/wheel.py +179 -0
  24. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/compat.py +235 -0
  25. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/configuration.py +378 -0
  26. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/download.py +922 -0
  27. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/exceptions.py +249 -0
  28. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/index.py +1117 -0
  29. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/locations.py +194 -0
  30. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/models/__init__.py +4 -0
  31. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/models/index.py +15 -0
  32. package/python3.4.2/lib/python3.4/site-packages/pip/{_vendor/requests/packages/urllib3/contrib → _internal/operations}/__init__.py +0 -0
  33. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/operations/check.py +106 -0
  34. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/operations/freeze.py +252 -0
  35. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/operations/prepare.py +378 -0
  36. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/pep425tags.py +317 -0
  37. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/req/__init__.py +69 -0
  38. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/req/req_file.py +338 -0
  39. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/req/req_install.py +1115 -0
  40. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/req/req_set.py +164 -0
  41. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/req/req_uninstall.py +455 -0
  42. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/resolve.py +354 -0
  43. package/python3.4.2/lib/python3.4/site-packages/pip/{status_codes.py → _internal/status_codes.py} +8 -6
  44. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/__init__.py +0 -0
  45. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/appdirs.py +258 -0
  46. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/deprecation.py +77 -0
  47. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/encoding.py +33 -0
  48. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/filesystem.py +28 -0
  49. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/glibc.py +84 -0
  50. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/hashes.py +94 -0
  51. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/logging.py +132 -0
  52. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/misc.py +851 -0
  53. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/outdated.py +163 -0
  54. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/packaging.py +70 -0
  55. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/setuptools_build.py +8 -0
  56. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/temp_dir.py +82 -0
  57. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/typing.py +29 -0
  58. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/utils/ui.py +421 -0
  59. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/vcs/__init__.py +471 -0
  60. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/vcs/bazaar.py +113 -0
  61. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/vcs/git.py +311 -0
  62. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/vcs/mercurial.py +105 -0
  63. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/vcs/subversion.py +271 -0
  64. package/python3.4.2/lib/python3.4/site-packages/pip/_internal/wheel.py +817 -0
  65. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/__init__.py +109 -8
  66. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/appdirs.py +604 -0
  67. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/__init__.py +11 -0
  68. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/_cmd.py +60 -0
  69. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/adapter.py +134 -0
  70. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/cache.py +39 -0
  71. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/caches/__init__.py +2 -0
  72. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/caches/file_cache.py +133 -0
  73. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/caches/redis_cache.py +43 -0
  74. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/compat.py +29 -0
  75. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/controller.py +373 -0
  76. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/filewrapper.py +78 -0
  77. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/heuristics.py +138 -0
  78. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/serialize.py +194 -0
  79. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/cachecontrol/wrapper.py +27 -0
  80. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/certifi/__init__.py +3 -0
  81. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/certifi/__main__.py +2 -0
  82. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests → certifi}/cacert.pem +1765 -2358
  83. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/certifi/core.py +37 -0
  84. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/__init__.py +39 -32
  85. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/big5freq.py +386 -0
  86. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/big5prober.py +47 -42
  87. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/chardistribution.py +233 -231
  88. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/charsetgroupprober.py +106 -0
  89. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/charsetprober.py +145 -0
  90. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/cli/__init__.py +1 -0
  91. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/cli/chardetect.py +85 -0
  92. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/codingstatemachine.py +88 -0
  93. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/compat.py +34 -34
  94. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/cp949prober.py +49 -44
  95. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/enums.py +76 -0
  96. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/escprober.py +101 -0
  97. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/escsm.py +246 -0
  98. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/eucjpprober.py +92 -0
  99. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/euckrfreq.py +195 -0
  100. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/euckrprober.py +47 -42
  101. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/euctwfreq.py +387 -428
  102. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/euctwprober.py +46 -41
  103. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/gb2312freq.py +283 -472
  104. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/gb2312prober.py +46 -41
  105. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/hebrewprober.py +292 -283
  106. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/jisfreq.py +325 -569
  107. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/jpcntx.py +233 -219
  108. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/langbulgarianmodel.py +228 -229
  109. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/langcyrillicmodel.py +333 -329
  110. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/langgreekmodel.py +225 -225
  111. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/langhebrewmodel.py +200 -201
  112. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/langhungarianmodel.py +225 -225
  113. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/langthaimodel.py +199 -200
  114. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/langturkishmodel.py +193 -0
  115. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/latin1prober.py +145 -139
  116. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/mbcharsetprober.py +91 -0
  117. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/mbcsgroupprober.py +54 -54
  118. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/mbcssm.py +572 -0
  119. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/sbcharsetprober.py +132 -0
  120. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/sbcsgroupprober.py +73 -69
  121. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/sjisprober.py +92 -0
  122. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/universaldetector.py +286 -0
  123. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/chardet → chardet}/utf8prober.py +82 -76
  124. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/chardet/version.py +9 -0
  125. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/colorama/__init__.py +7 -7
  126. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/colorama/ansi.py +102 -50
  127. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/colorama/ansitowin32.py +236 -190
  128. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/colorama/initialise.py +82 -56
  129. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/colorama/win32.py +156 -137
  130. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/colorama/winterm.py +162 -120
  131. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/__init__.py +23 -23
  132. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/_backport/__init__.py +6 -6
  133. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/_backport/misc.py +41 -41
  134. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/_backport/shutil.py +761 -761
  135. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/_backport/sysconfig.cfg +84 -84
  136. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/_backport/sysconfig.py +788 -788
  137. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/_backport/tarfile.py +2607 -2607
  138. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/compat.py +1117 -1064
  139. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/database.py +1318 -1301
  140. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/index.py +516 -488
  141. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/locators.py +1292 -1194
  142. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/manifest.py +393 -364
  143. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/markers.py +131 -190
  144. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/metadata.py +1068 -1026
  145. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/resources.py +355 -317
  146. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/scripts.py +415 -323
  147. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/t32.exe +0 -0
  148. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/t64.exe +0 -0
  149. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/util.py +1755 -1575
  150. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/version.py +736 -721
  151. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/w32.exe +0 -0
  152. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/w64.exe +0 -0
  153. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distlib/wheel.py +984 -958
  154. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/distro.py +1104 -0
  155. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/__init__.py +35 -23
  156. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/{ihatexml.py → _ihatexml.py} +288 -285
  157. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/{inputstream.py → _inputstream.py} +923 -881
  158. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/{tokenizer.py → _tokenizer.py} +1721 -1731
  159. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/{trie → _trie}/__init__.py +14 -12
  160. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/{trie → _trie}/_base.py +37 -37
  161. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/{trie → _trie}/datrie.py +44 -44
  162. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/{trie → _trie}/py.py +67 -67
  163. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/{utils.py → _utils.py} +124 -82
  164. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/constants.py +2947 -3104
  165. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/filters/alphabeticalattributes.py +29 -20
  166. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/filters/{_base.py → base.py} +12 -12
  167. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/filters/inject_meta_charset.py +73 -65
  168. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/filters/lint.py +93 -93
  169. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/filters/optionaltags.py +207 -205
  170. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/filters/sanitizer.py +896 -12
  171. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/filters/whitespace.py +38 -38
  172. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/html5parser.py +2791 -2713
  173. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/serializer.py +409 -0
  174. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treeadapters/__init__.py +30 -0
  175. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treeadapters/genshi.py +54 -0
  176. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treeadapters/sax.py +50 -44
  177. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treebuilders/__init__.py +88 -76
  178. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treebuilders/{_base.py → base.py} +417 -377
  179. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treebuilders/dom.py +236 -227
  180. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treebuilders/etree.py +340 -337
  181. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.py +366 -369
  182. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treewalkers/__init__.py +154 -57
  183. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treewalkers/{_base.py → base.py} +252 -200
  184. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treewalkers/dom.py +43 -46
  185. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treewalkers/etree.py +130 -138
  186. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treewalkers/{lxmletree.py → etree_lxml.py} +213 -208
  187. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treewalkers/{genshistream.py → genshi.py} +69 -69
  188. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/idna/__init__.py +2 -0
  189. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/idna/codec.py +118 -0
  190. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/idna/compat.py +12 -0
  191. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/idna/core.py +387 -0
  192. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/idna/idnadata.py +1585 -0
  193. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/idna/intranges.py +53 -0
  194. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/idna/package_data.py +2 -0
  195. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/idna/uts46data.py +7634 -0
  196. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/ipaddress.py +2419 -0
  197. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/lockfile/__init__.py +347 -0
  198. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/lockfile/linklockfile.py +73 -0
  199. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/lockfile/mkdirlockfile.py +84 -0
  200. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/lockfile/pidlockfile.py +190 -0
  201. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/lockfile/sqlitelockfile.py +156 -0
  202. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/lockfile/symlinklockfile.py +70 -0
  203. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/msgpack/__init__.py +66 -0
  204. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/msgpack/_version.py +1 -0
  205. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/msgpack/exceptions.py +41 -0
  206. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/msgpack/fallback.py +971 -0
  207. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/packaging/__about__.py +21 -0
  208. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/packaging/__init__.py +14 -0
  209. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/packaging/_compat.py +30 -0
  210. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/packaging/_structures.py +70 -0
  211. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/packaging/markers.py +301 -0
  212. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/packaging/requirements.py +130 -0
  213. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/packaging/specifiers.py +774 -0
  214. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/packaging/utils.py +63 -0
  215. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/packaging/version.py +441 -0
  216. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{pkg_resources.py → pkg_resources/__init__.py} +3125 -2762
  217. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/pkg_resources/py31compat.py +22 -0
  218. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/progress/__init__.py +127 -0
  219. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/progress/bar.py +88 -0
  220. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/progress/counter.py +48 -0
  221. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/progress/helpers.py +91 -0
  222. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/progress/spinner.py +44 -0
  223. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/pyparsing.py +5720 -0
  224. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/pytoml/__init__.py +3 -0
  225. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/pytoml/core.py +13 -0
  226. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/pytoml/parser.py +374 -0
  227. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/pytoml/writer.py +127 -0
  228. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/__init__.py +123 -77
  229. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/__version__.py +14 -0
  230. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/_internal_utils.py +42 -0
  231. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/adapters.py +525 -388
  232. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/api.py +152 -120
  233. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/auth.py +293 -193
  234. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/certs.py +18 -24
  235. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/compat.py +73 -115
  236. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/cookies.py +542 -454
  237. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/exceptions.py +122 -75
  238. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/help.py +120 -0
  239. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/hooks.py +34 -45
  240. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/models.py +948 -803
  241. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages.py +16 -0
  242. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/sessions.py +737 -637
  243. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/status_codes.py +91 -88
  244. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/structures.py +105 -127
  245. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/utils.py +904 -673
  246. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/retrying.py +267 -0
  247. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/six.py +891 -646
  248. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/__init__.py +97 -0
  249. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/_collections.py +319 -0
  250. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/connection.py +373 -0
  251. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/connectionpool.py +905 -710
  252. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/contrib/__init__.py +0 -0
  253. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/contrib/_securetransport/__init__.py +0 -0
  254. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/contrib/_securetransport/bindings.py +593 -0
  255. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.py +343 -0
  256. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/contrib/appengine.py +296 -0
  257. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/contrib/ntlmpool.py +112 -120
  258. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.py +455 -0
  259. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/contrib/securetransport.py +810 -0
  260. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/contrib/socks.py +188 -0
  261. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/exceptions.py +246 -0
  262. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/fields.py +178 -177
  263. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/filepost.py +94 -100
  264. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/packages/__init__.py +5 -4
  265. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/packages/backports/__init__.py +0 -0
  266. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/packages/backports/makefile.py +53 -0
  267. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/packages/ordered_dict.py +259 -260
  268. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/packages/six.py +868 -0
  269. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/packages/ssl_match_hostname/__init__.py +19 -13
  270. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/packages/ssl_match_hostname/_implementation.py +157 -105
  271. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/poolmanager.py +440 -0
  272. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/request.py +148 -141
  273. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/response.py +626 -0
  274. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/util/__init__.py +54 -0
  275. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/util/connection.py +130 -0
  276. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/util/request.py +118 -0
  277. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/util/response.py +81 -0
  278. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/util/retry.py +401 -0
  279. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/util/selectors.py +581 -0
  280. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/util/ssl_.py +341 -0
  281. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/util/timeout.py +242 -234
  282. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/{requests/packages/urllib3 → urllib3}/util/url.py +230 -162
  283. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/urllib3/util/wait.py +40 -0
  284. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/webencodings/__init__.py +342 -0
  285. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/webencodings/labels.py +231 -0
  286. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/webencodings/mklabels.py +59 -0
  287. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/webencodings/tests.py +153 -0
  288. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/webencodings/x_user_defined.py +325 -0
  289. package/python3.4.2/lib/python3.4/site-packages/pip-10.0.0.dist-info/LICENSE.txt +20 -0
  290. package/python3.4.2/lib/python3.4/site-packages/pip-10.0.0.dist-info/METADATA +78 -0
  291. package/python3.4.2/lib/python3.4/site-packages/pip-10.0.0.dist-info/RECORD +294 -0
  292. package/python3.4.2/lib/python3.4/site-packages/{pip-1.5.6.dist-info → pip-10.0.0.dist-info}/WHEEL +6 -6
  293. package/python3.4.2/lib/python3.4/site-packages/pip-10.0.0.dist-info/entry_points.txt +5 -0
  294. package/python3.4.2/lib/python3.4/site-packages/{pip-1.5.6.dist-info → pip-10.0.0.dist-info}/top_level.txt +0 -0
  295. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/_markerlib/__init__.py +0 -16
  296. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/_markerlib/markers.py +0 -119
  297. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/sanitizer.py +0 -271
  298. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/serializer/__init__.py +0 -16
  299. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/serializer/htmlserializer.py +0 -320
  300. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treewalkers/pulldom.py +0 -63
  301. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/re-vendor.py +0 -34
  302. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/__init__.py +0 -3
  303. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/big5freq.py +0 -925
  304. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/chardetect.py +0 -46
  305. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/charsetgroupprober.py +0 -106
  306. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/charsetprober.py +0 -62
  307. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/codingstatemachine.py +0 -61
  308. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/constants.py +0 -39
  309. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/escprober.py +0 -86
  310. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/escsm.py +0 -242
  311. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/eucjpprober.py +0 -90
  312. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/euckrfreq.py +0 -596
  313. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/mbcharsetprober.py +0 -86
  314. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/mbcssm.py +0 -575
  315. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/sbcharsetprober.py +0 -120
  316. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/sjisprober.py +0 -91
  317. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/universaldetector.py +0 -170
  318. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/__init__.py +0 -58
  319. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/_collections.py +0 -205
  320. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/connection.py +0 -204
  321. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py +0 -422
  322. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/exceptions.py +0 -126
  323. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/packages/six.py +0 -385
  324. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/poolmanager.py +0 -258
  325. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/response.py +0 -308
  326. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/util/__init__.py +0 -27
  327. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/util/connection.py +0 -45
  328. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/util/request.py +0 -68
  329. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/util/response.py +0 -13
  330. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py +0 -133
  331. package/python3.4.2/lib/python3.4/site-packages/pip/backwardcompat/__init__.py +0 -138
  332. package/python3.4.2/lib/python3.4/site-packages/pip/basecommand.py +0 -201
  333. package/python3.4.2/lib/python3.4/site-packages/pip/cmdoptions.py +0 -371
  334. package/python3.4.2/lib/python3.4/site-packages/pip/commands/__init__.py +0 -88
  335. package/python3.4.2/lib/python3.4/site-packages/pip/commands/bundle.py +0 -42
  336. package/python3.4.2/lib/python3.4/site-packages/pip/commands/completion.py +0 -59
  337. package/python3.4.2/lib/python3.4/site-packages/pip/commands/freeze.py +0 -114
  338. package/python3.4.2/lib/python3.4/site-packages/pip/commands/install.py +0 -314
  339. package/python3.4.2/lib/python3.4/site-packages/pip/commands/list.py +0 -162
  340. package/python3.4.2/lib/python3.4/site-packages/pip/commands/search.py +0 -132
  341. package/python3.4.2/lib/python3.4/site-packages/pip/commands/show.py +0 -80
  342. package/python3.4.2/lib/python3.4/site-packages/pip/commands/uninstall.py +0 -59
  343. package/python3.4.2/lib/python3.4/site-packages/pip/commands/unzip.py +0 -7
  344. package/python3.4.2/lib/python3.4/site-packages/pip/commands/wheel.py +0 -195
  345. package/python3.4.2/lib/python3.4/site-packages/pip/commands/zip.py +0 -351
  346. package/python3.4.2/lib/python3.4/site-packages/pip/download.py +0 -644
  347. package/python3.4.2/lib/python3.4/site-packages/pip/exceptions.py +0 -46
  348. package/python3.4.2/lib/python3.4/site-packages/pip/index.py +0 -990
  349. package/python3.4.2/lib/python3.4/site-packages/pip/locations.py +0 -171
  350. package/python3.4.2/lib/python3.4/site-packages/pip/log.py +0 -276
  351. package/python3.4.2/lib/python3.4/site-packages/pip/pep425tags.py +0 -102
  352. package/python3.4.2/lib/python3.4/site-packages/pip/req.py +0 -1931
  353. package/python3.4.2/lib/python3.4/site-packages/pip/runner.py +0 -18
  354. package/python3.4.2/lib/python3.4/site-packages/pip/util.py +0 -720
  355. package/python3.4.2/lib/python3.4/site-packages/pip/vcs/__init__.py +0 -251
  356. package/python3.4.2/lib/python3.4/site-packages/pip/vcs/bazaar.py +0 -131
  357. package/python3.4.2/lib/python3.4/site-packages/pip/vcs/git.py +0 -194
  358. package/python3.4.2/lib/python3.4/site-packages/pip/vcs/mercurial.py +0 -151
  359. package/python3.4.2/lib/python3.4/site-packages/pip/vcs/subversion.py +0 -273
  360. package/python3.4.2/lib/python3.4/site-packages/pip/wheel.py +0 -560
  361. package/python3.4.2/lib/python3.4/site-packages/pip-1.5.6.dist-info/DESCRIPTION.rst +0 -71
  362. package/python3.4.2/lib/python3.4/site-packages/pip-1.5.6.dist-info/METADATA +0 -98
  363. package/python3.4.2/lib/python3.4/site-packages/pip-1.5.6.dist-info/RECORD +0 -373
  364. package/python3.4.2/lib/python3.4/site-packages/pip-1.5.6.dist-info/entry_points.txt +0 -5
  365. package/python3.4.2/lib/python3.4/site-packages/pip-1.5.6.dist-info/metadata.json +0 -1
@@ -1,803 +1,948 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- """
4
- requests.models
5
- ~~~~~~~~~~~~~~~
6
-
7
- This module contains the primary objects that power Requests.
8
- """
9
-
10
- import collections
11
- import datetime
12
-
13
- from io import BytesIO, UnsupportedOperation
14
- from .hooks import default_hooks
15
- from .structures import CaseInsensitiveDict
16
-
17
- from .auth import HTTPBasicAuth
18
- from .cookies import cookiejar_from_dict, get_cookie_header
19
- from .packages.urllib3.fields import RequestField
20
- from .packages.urllib3.filepost import encode_multipart_formdata
21
- from .packages.urllib3.util import parse_url
22
- from .packages.urllib3.exceptions import DecodeError
23
- from .exceptions import (
24
- HTTPError, RequestException, MissingSchema, InvalidURL,
25
- ChunkedEncodingError, ContentDecodingError)
26
- from .utils import (
27
- guess_filename, get_auth_from_url, requote_uri,
28
- stream_decode_response_unicode, to_key_val_list, parse_header_links,
29
- iter_slices, guess_json_utf, super_len, to_native_string)
30
- from .compat import (
31
- cookielib, urlunparse, urlsplit, urlencode, str, bytes, StringIO,
32
- is_py2, chardet, json, builtin_str, basestring, IncompleteRead)
33
- from .status_codes import codes
34
-
35
- #: The set of HTTP status codes that indicate an automatically
36
- #: processable redirect.
37
- REDIRECT_STATI = (
38
- codes.moved, # 301
39
- codes.found, # 302
40
- codes.other, # 303
41
- codes.temporary_moved, # 307
42
- )
43
- DEFAULT_REDIRECT_LIMIT = 30
44
- CONTENT_CHUNK_SIZE = 10 * 1024
45
- ITER_CHUNK_SIZE = 512
46
-
47
-
48
- class RequestEncodingMixin(object):
49
- @property
50
- def path_url(self):
51
- """Build the path URL to use."""
52
-
53
- url = []
54
-
55
- p = urlsplit(self.url)
56
-
57
- path = p.path
58
- if not path:
59
- path = '/'
60
-
61
- url.append(path)
62
-
63
- query = p.query
64
- if query:
65
- url.append('?')
66
- url.append(query)
67
-
68
- return ''.join(url)
69
-
70
- @staticmethod
71
- def _encode_params(data):
72
- """Encode parameters in a piece of data.
73
-
74
- Will successfully encode parameters when passed as a dict or a list of
75
- 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary
76
- if parameters are supplied as a dict.
77
- """
78
-
79
- if isinstance(data, (str, bytes)):
80
- return data
81
- elif hasattr(data, 'read'):
82
- return data
83
- elif hasattr(data, '__iter__'):
84
- result = []
85
- for k, vs in to_key_val_list(data):
86
- if isinstance(vs, basestring) or not hasattr(vs, '__iter__'):
87
- vs = [vs]
88
- for v in vs:
89
- if v is not None:
90
- result.append(
91
- (k.encode('utf-8') if isinstance(k, str) else k,
92
- v.encode('utf-8') if isinstance(v, str) else v))
93
- return urlencode(result, doseq=True)
94
- else:
95
- return data
96
-
97
- @staticmethod
98
- def _encode_files(files, data):
99
- """Build the body for a multipart/form-data request.
100
-
101
- Will successfully encode files when passed as a dict or a list of
102
- 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary
103
- if parameters are supplied as a dict.
104
-
105
- """
106
- if (not files):
107
- raise ValueError("Files must be provided.")
108
- elif isinstance(data, basestring):
109
- raise ValueError("Data must not be a string.")
110
-
111
- new_fields = []
112
- fields = to_key_val_list(data or {})
113
- files = to_key_val_list(files or {})
114
-
115
- for field, val in fields:
116
- if isinstance(val, basestring) or not hasattr(val, '__iter__'):
117
- val = [val]
118
- for v in val:
119
- if v is not None:
120
- # Don't call str() on bytestrings: in Py3 it all goes wrong.
121
- if not isinstance(v, bytes):
122
- v = str(v)
123
-
124
- new_fields.append(
125
- (field.decode('utf-8') if isinstance(field, bytes) else field,
126
- v.encode('utf-8') if isinstance(v, str) else v))
127
-
128
- for (k, v) in files:
129
- # support for explicit filename
130
- ft = None
131
- fh = None
132
- if isinstance(v, (tuple, list)):
133
- if len(v) == 2:
134
- fn, fp = v
135
- elif len(v) == 3:
136
- fn, fp, ft = v
137
- else:
138
- fn, fp, ft, fh = v
139
- else:
140
- fn = guess_filename(v) or k
141
- fp = v
142
- if isinstance(fp, str):
143
- fp = StringIO(fp)
144
- if isinstance(fp, bytes):
145
- fp = BytesIO(fp)
146
-
147
- rf = RequestField(name=k, data=fp.read(),
148
- filename=fn, headers=fh)
149
- rf.make_multipart(content_type=ft)
150
- new_fields.append(rf)
151
-
152
- body, content_type = encode_multipart_formdata(new_fields)
153
-
154
- return body, content_type
155
-
156
-
157
- class RequestHooksMixin(object):
158
- def register_hook(self, event, hook):
159
- """Properly register a hook."""
160
-
161
- if event not in self.hooks:
162
- raise ValueError('Unsupported event specified, with event name "%s"' % (event))
163
-
164
- if isinstance(hook, collections.Callable):
165
- self.hooks[event].append(hook)
166
- elif hasattr(hook, '__iter__'):
167
- self.hooks[event].extend(h for h in hook if isinstance(h, collections.Callable))
168
-
169
- def deregister_hook(self, event, hook):
170
- """Deregister a previously registered hook.
171
- Returns True if the hook existed, False if not.
172
- """
173
-
174
- try:
175
- self.hooks[event].remove(hook)
176
- return True
177
- except ValueError:
178
- return False
179
-
180
-
181
- class Request(RequestHooksMixin):
182
- """A user-created :class:`Request <Request>` object.
183
-
184
- Used to prepare a :class:`PreparedRequest <PreparedRequest>`, which is sent to the server.
185
-
186
- :param method: HTTP method to use.
187
- :param url: URL to send.
188
- :param headers: dictionary of headers to send.
189
- :param files: dictionary of {filename: fileobject} files to multipart upload.
190
- :param data: the body to attach the request. If a dictionary is provided, form-encoding will take place.
191
- :param params: dictionary of URL parameters to append to the URL.
192
- :param auth: Auth handler or (user, pass) tuple.
193
- :param cookies: dictionary or CookieJar of cookies to attach to this request.
194
- :param hooks: dictionary of callback hooks, for internal usage.
195
-
196
- Usage::
197
-
198
- >>> import requests
199
- >>> req = requests.Request('GET', 'http://httpbin.org/get')
200
- >>> req.prepare()
201
- <PreparedRequest [GET]>
202
-
203
- """
204
- def __init__(self,
205
- method=None,
206
- url=None,
207
- headers=None,
208
- files=None,
209
- data=None,
210
- params=None,
211
- auth=None,
212
- cookies=None,
213
- hooks=None):
214
-
215
- # Default empty dicts for dict params.
216
- data = [] if data is None else data
217
- files = [] if files is None else files
218
- headers = {} if headers is None else headers
219
- params = {} if params is None else params
220
- hooks = {} if hooks is None else hooks
221
-
222
- self.hooks = default_hooks()
223
- for (k, v) in list(hooks.items()):
224
- self.register_hook(event=k, hook=v)
225
-
226
- self.method = method
227
- self.url = url
228
- self.headers = headers
229
- self.files = files
230
- self.data = data
231
- self.params = params
232
- self.auth = auth
233
- self.cookies = cookies
234
-
235
- def __repr__(self):
236
- return '<Request [%s]>' % (self.method)
237
-
238
- def prepare(self):
239
- """Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it."""
240
- p = PreparedRequest()
241
- p.prepare(
242
- method=self.method,
243
- url=self.url,
244
- headers=self.headers,
245
- files=self.files,
246
- data=self.data,
247
- params=self.params,
248
- auth=self.auth,
249
- cookies=self.cookies,
250
- hooks=self.hooks,
251
- )
252
- return p
253
-
254
-
255
- class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
256
- """The fully mutable :class:`PreparedRequest <PreparedRequest>` object,
257
- containing the exact bytes that will be sent to the server.
258
-
259
- Generated from either a :class:`Request <Request>` object or manually.
260
-
261
- Usage::
262
-
263
- >>> import requests
264
- >>> req = requests.Request('GET', 'http://httpbin.org/get')
265
- >>> r = req.prepare()
266
- <PreparedRequest [GET]>
267
-
268
- >>> s = requests.Session()
269
- >>> s.send(r)
270
- <Response [200]>
271
-
272
- """
273
-
274
- def __init__(self):
275
- #: HTTP verb to send to the server.
276
- self.method = None
277
- #: HTTP URL to send the request to.
278
- self.url = None
279
- #: dictionary of HTTP headers.
280
- self.headers = None
281
- # The `CookieJar` used to create the Cookie header will be stored here
282
- # after prepare_cookies is called
283
- self._cookies = None
284
- #: request body to send to the server.
285
- self.body = None
286
- #: dictionary of callback hooks, for internal usage.
287
- self.hooks = default_hooks()
288
-
289
- def prepare(self, method=None, url=None, headers=None, files=None,
290
- data=None, params=None, auth=None, cookies=None, hooks=None):
291
- """Prepares the entire request with the given parameters."""
292
-
293
- self.prepare_method(method)
294
- self.prepare_url(url, params)
295
- self.prepare_headers(headers)
296
- self.prepare_cookies(cookies)
297
- self.prepare_body(data, files)
298
- self.prepare_auth(auth, url)
299
- # Note that prepare_auth must be last to enable authentication schemes
300
- # such as OAuth to work on a fully prepared request.
301
-
302
- # This MUST go after prepare_auth. Authenticators could add a hook
303
- self.prepare_hooks(hooks)
304
-
305
- def __repr__(self):
306
- return '<PreparedRequest [%s]>' % (self.method)
307
-
308
- def copy(self):
309
- p = PreparedRequest()
310
- p.method = self.method
311
- p.url = self.url
312
- p.headers = self.headers.copy()
313
- p._cookies = self._cookies.copy()
314
- p.body = self.body
315
- p.hooks = self.hooks
316
- return p
317
-
318
- def prepare_method(self, method):
319
- """Prepares the given HTTP method."""
320
- self.method = method
321
- if self.method is not None:
322
- self.method = self.method.upper()
323
-
324
- def prepare_url(self, url, params):
325
- """Prepares the given HTTP URL."""
326
- #: Accept objects that have string representations.
327
- try:
328
- url = unicode(url)
329
- except NameError:
330
- # We're on Python 3.
331
- url = str(url)
332
- except UnicodeDecodeError:
333
- pass
334
-
335
- # Don't do any URL preparation for oddball schemes
336
- if ':' in url and not url.lower().startswith('http'):
337
- self.url = url
338
- return
339
-
340
- # Support for unicode domain names and paths.
341
- scheme, auth, host, port, path, query, fragment = parse_url(url)
342
-
343
- if not scheme:
344
- raise MissingSchema("Invalid URL {0!r}: No schema supplied. "
345
- "Perhaps you meant http://{0}?".format(url))
346
-
347
- if not host:
348
- raise InvalidURL("Invalid URL %r: No host supplied" % url)
349
-
350
- # Only want to apply IDNA to the hostname
351
- try:
352
- host = host.encode('idna').decode('utf-8')
353
- except UnicodeError:
354
- raise InvalidURL('URL has an invalid label.')
355
-
356
- # Carefully reconstruct the network location
357
- netloc = auth or ''
358
- if netloc:
359
- netloc += '@'
360
- netloc += host
361
- if port:
362
- netloc += ':' + str(port)
363
-
364
- # Bare domains aren't valid URLs.
365
- if not path:
366
- path = '/'
367
-
368
- if is_py2:
369
- if isinstance(scheme, str):
370
- scheme = scheme.encode('utf-8')
371
- if isinstance(netloc, str):
372
- netloc = netloc.encode('utf-8')
373
- if isinstance(path, str):
374
- path = path.encode('utf-8')
375
- if isinstance(query, str):
376
- query = query.encode('utf-8')
377
- if isinstance(fragment, str):
378
- fragment = fragment.encode('utf-8')
379
-
380
- enc_params = self._encode_params(params)
381
- if enc_params:
382
- if query:
383
- query = '%s&%s' % (query, enc_params)
384
- else:
385
- query = enc_params
386
-
387
- url = requote_uri(urlunparse([scheme, netloc, path, None, query, fragment]))
388
- self.url = url
389
-
390
- def prepare_headers(self, headers):
391
- """Prepares the given HTTP headers."""
392
-
393
- if headers:
394
- self.headers = CaseInsensitiveDict((to_native_string(name), value) for name, value in headers.items())
395
- else:
396
- self.headers = CaseInsensitiveDict()
397
-
398
- def prepare_body(self, data, files):
399
- """Prepares the given HTTP body data."""
400
-
401
- # Check if file, fo, generator, iterator.
402
- # If not, run through normal process.
403
-
404
- # Nottin' on you.
405
- body = None
406
- content_type = None
407
- length = None
408
-
409
- is_stream = all([
410
- hasattr(data, '__iter__'),
411
- not isinstance(data, (basestring, list, tuple, dict))
412
- ])
413
-
414
- try:
415
- length = super_len(data)
416
- except (TypeError, AttributeError, UnsupportedOperation):
417
- length = None
418
-
419
- if is_stream:
420
- body = data
421
-
422
- if files:
423
- raise NotImplementedError('Streamed bodies and files are mutually exclusive.')
424
-
425
- if length is not None:
426
- self.headers['Content-Length'] = builtin_str(length)
427
- else:
428
- self.headers['Transfer-Encoding'] = 'chunked'
429
- else:
430
- # Multi-part file uploads.
431
- if files:
432
- (body, content_type) = self._encode_files(files, data)
433
- else:
434
- if data:
435
- body = self._encode_params(data)
436
- if isinstance(data, str) or isinstance(data, builtin_str) or hasattr(data, 'read'):
437
- content_type = None
438
- else:
439
- content_type = 'application/x-www-form-urlencoded'
440
-
441
- self.prepare_content_length(body)
442
-
443
- # Add content-type if it wasn't explicitly provided.
444
- if (content_type) and (not 'content-type' in self.headers):
445
- self.headers['Content-Type'] = content_type
446
-
447
- self.body = body
448
-
449
- def prepare_content_length(self, body):
450
- if hasattr(body, 'seek') and hasattr(body, 'tell'):
451
- body.seek(0, 2)
452
- self.headers['Content-Length'] = builtin_str(body.tell())
453
- body.seek(0, 0)
454
- elif body is not None:
455
- l = super_len(body)
456
- if l:
457
- self.headers['Content-Length'] = builtin_str(l)
458
- elif self.method not in ('GET', 'HEAD'):
459
- self.headers['Content-Length'] = '0'
460
-
461
- def prepare_auth(self, auth, url=''):
462
- """Prepares the given HTTP auth data."""
463
-
464
- # If no Auth is explicitly provided, extract it from the URL first.
465
- if auth is None:
466
- url_auth = get_auth_from_url(self.url)
467
- auth = url_auth if any(url_auth) else None
468
-
469
- if auth:
470
- if isinstance(auth, tuple) and len(auth) == 2:
471
- # special-case basic HTTP auth
472
- auth = HTTPBasicAuth(*auth)
473
-
474
- # Allow auth to make its changes.
475
- r = auth(self)
476
-
477
- # Update self to reflect the auth changes.
478
- self.__dict__.update(r.__dict__)
479
-
480
- # Recompute Content-Length
481
- self.prepare_content_length(self.body)
482
-
483
- def prepare_cookies(self, cookies):
484
- """Prepares the given HTTP cookie data."""
485
-
486
- if isinstance(cookies, cookielib.CookieJar):
487
- self._cookies = cookies
488
- else:
489
- self._cookies = cookiejar_from_dict(cookies)
490
-
491
- cookie_header = get_cookie_header(self._cookies, self)
492
- if cookie_header is not None:
493
- self.headers['Cookie'] = cookie_header
494
-
495
- def prepare_hooks(self, hooks):
496
- """Prepares the given hooks."""
497
- for event in hooks:
498
- self.register_hook(event, hooks[event])
499
-
500
-
501
- class Response(object):
502
- """The :class:`Response <Response>` object, which contains a
503
- server's response to an HTTP request.
504
- """
505
-
506
- __attrs__ = [
507
- '_content',
508
- 'status_code',
509
- 'headers',
510
- 'url',
511
- 'history',
512
- 'encoding',
513
- 'reason',
514
- 'cookies',
515
- 'elapsed',
516
- 'request',
517
- ]
518
-
519
- def __init__(self):
520
- super(Response, self).__init__()
521
-
522
- self._content = False
523
- self._content_consumed = False
524
-
525
- #: Integer Code of responded HTTP Status, e.g. 404 or 200.
526
- self.status_code = None
527
-
528
- #: Case-insensitive Dictionary of Response Headers.
529
- #: For example, ``headers['content-encoding']`` will return the
530
- #: value of a ``'Content-Encoding'`` response header.
531
- self.headers = CaseInsensitiveDict()
532
-
533
- #: File-like object representation of response (for advanced usage).
534
- #: Use of ``raw`` requires that ``stream=True`` be set on the request.
535
- # This requirement does not apply for use internally to Requests.
536
- self.raw = None
537
-
538
- #: Final URL location of Response.
539
- self.url = None
540
-
541
- #: Encoding to decode with when accessing r.text.
542
- self.encoding = None
543
-
544
- #: A list of :class:`Response <Response>` objects from
545
- #: the history of the Request. Any redirect responses will end
546
- #: up here. The list is sorted from the oldest to the most recent request.
547
- self.history = []
548
-
549
- #: Textual reason of responded HTTP Status, e.g. "Not Found" or "OK".
550
- self.reason = None
551
-
552
- #: A CookieJar of Cookies the server sent back.
553
- self.cookies = cookiejar_from_dict({})
554
-
555
- #: The amount of time elapsed between sending the request
556
- #: and the arrival of the response (as a timedelta)
557
- self.elapsed = datetime.timedelta(0)
558
-
559
- def __getstate__(self):
560
- # Consume everything; accessing the content attribute makes
561
- # sure the content has been fully read.
562
- if not self._content_consumed:
563
- self.content
564
-
565
- return dict(
566
- (attr, getattr(self, attr, None))
567
- for attr in self.__attrs__
568
- )
569
-
570
- def __setstate__(self, state):
571
- for name, value in state.items():
572
- setattr(self, name, value)
573
-
574
- # pickled objects do not have .raw
575
- setattr(self, '_content_consumed', True)
576
- setattr(self, 'raw', None)
577
-
578
- def __repr__(self):
579
- return '<Response [%s]>' % (self.status_code)
580
-
581
- def __bool__(self):
582
- """Returns true if :attr:`status_code` is 'OK'."""
583
- return self.ok
584
-
585
- def __nonzero__(self):
586
- """Returns true if :attr:`status_code` is 'OK'."""
587
- return self.ok
588
-
589
- def __iter__(self):
590
- """Allows you to use a response as an iterator."""
591
- return self.iter_content(128)
592
-
593
- @property
594
- def ok(self):
595
- try:
596
- self.raise_for_status()
597
- except RequestException:
598
- return False
599
- return True
600
-
601
- @property
602
- def is_redirect(self):
603
- """True if this Response is a well-formed HTTP redirect that could have
604
- been processed automatically (by :meth:`Session.resolve_redirects`).
605
- """
606
- return ('location' in self.headers and self.status_code in REDIRECT_STATI)
607
-
608
- @property
609
- def apparent_encoding(self):
610
- """The apparent encoding, provided by the chardet library"""
611
- return chardet.detect(self.content)['encoding']
612
-
613
- def iter_content(self, chunk_size=1, decode_unicode=False):
614
- """Iterates over the response data. When stream=True is set on the
615
- request, this avoids reading the content at once into memory for
616
- large responses. The chunk size is the number of bytes it should
617
- read into memory. This is not necessarily the length of each item
618
- returned as decoding can take place.
619
-
620
- If decode_unicode is True, content will be decoded using the best
621
- available encoding based on the response.
622
- """
623
- def generate():
624
- try:
625
- # Special case for urllib3.
626
- try:
627
- for chunk in self.raw.stream(chunk_size, decode_content=True):
628
- yield chunk
629
- except IncompleteRead as e:
630
- raise ChunkedEncodingError(e)
631
- except DecodeError as e:
632
- raise ContentDecodingError(e)
633
- except AttributeError:
634
- # Standard file-like object.
635
- while True:
636
- chunk = self.raw.read(chunk_size)
637
- if not chunk:
638
- break
639
- yield chunk
640
-
641
- self._content_consumed = True
642
-
643
- # simulate reading small chunks of the content
644
- reused_chunks = iter_slices(self._content, chunk_size)
645
-
646
- stream_chunks = generate()
647
-
648
- chunks = reused_chunks if self._content_consumed else stream_chunks
649
-
650
- if decode_unicode:
651
- chunks = stream_decode_response_unicode(chunks, self)
652
-
653
- return chunks
654
-
655
- def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None):
656
- """Iterates over the response data, one line at a time. When
657
- stream=True is set on the request, this avoids reading the
658
- content at once into memory for large responses.
659
- """
660
-
661
- pending = None
662
-
663
- for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode):
664
-
665
- if pending is not None:
666
- chunk = pending + chunk
667
- lines = chunk.splitlines()
668
-
669
- if lines and lines[-1] and chunk and lines[-1][-1] == chunk[-1]:
670
- pending = lines.pop()
671
- else:
672
- pending = None
673
-
674
- for line in lines:
675
- yield line
676
-
677
- if pending is not None:
678
- yield pending
679
-
680
- @property
681
- def content(self):
682
- """Content of the response, in bytes."""
683
-
684
- if self._content is False:
685
- # Read the contents.
686
- try:
687
- if self._content_consumed:
688
- raise RuntimeError(
689
- 'The content for this response was already consumed')
690
-
691
- if self.status_code == 0:
692
- self._content = None
693
- else:
694
- self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
695
-
696
- except AttributeError:
697
- self._content = None
698
-
699
- self._content_consumed = True
700
- # don't need to release the connection; that's been handled by urllib3
701
- # since we exhausted the data.
702
- return self._content
703
-
704
- @property
705
- def text(self):
706
- """Content of the response, in unicode.
707
-
708
- If Response.encoding is None, encoding will be guessed using
709
- ``chardet``.
710
-
711
- The encoding of the response content is determined based solely on HTTP
712
- headers, following RFC 2616 to the letter. If you can take advantage of
713
- non-HTTP knowledge to make a better guess at the encoding, you should
714
- set ``r.encoding`` appropriately before accessing this property.
715
- """
716
-
717
- # Try charset from content-type
718
- content = None
719
- encoding = self.encoding
720
-
721
- if not self.content:
722
- return str('')
723
-
724
- # Fallback to auto-detected encoding.
725
- if self.encoding is None:
726
- encoding = self.apparent_encoding
727
-
728
- # Decode unicode from given encoding.
729
- try:
730
- content = str(self.content, encoding, errors='replace')
731
- except (LookupError, TypeError):
732
- # A LookupError is raised if the encoding was not found which could
733
- # indicate a misspelling or similar mistake.
734
- #
735
- # A TypeError can be raised if encoding is None
736
- #
737
- # So we try blindly encoding.
738
- content = str(self.content, errors='replace')
739
-
740
- return content
741
-
742
- def json(self, **kwargs):
743
- """Returns the json-encoded content of a response, if any.
744
-
745
- :param \*\*kwargs: Optional arguments that ``json.loads`` takes.
746
- """
747
-
748
- if not self.encoding and len(self.content) > 3:
749
- # No encoding set. JSON RFC 4627 section 3 states we should expect
750
- # UTF-8, -16 or -32. Detect which one to use; If the detection or
751
- # decoding fails, fall back to `self.text` (using chardet to make
752
- # a best guess).
753
- encoding = guess_json_utf(self.content)
754
- if encoding is not None:
755
- try:
756
- return json.loads(self.content.decode(encoding), **kwargs)
757
- except UnicodeDecodeError:
758
- # Wrong UTF codec detected; usually because it's not UTF-8
759
- # but some other 8-bit codec. This is an RFC violation,
760
- # and the server didn't bother to tell us what codec *was*
761
- # used.
762
- pass
763
- return json.loads(self.text, **kwargs)
764
-
765
- @property
766
- def links(self):
767
- """Returns the parsed header links of the response, if any."""
768
-
769
- header = self.headers.get('link')
770
-
771
- # l = MultiDict()
772
- l = {}
773
-
774
- if header:
775
- links = parse_header_links(header)
776
-
777
- for link in links:
778
- key = link.get('rel') or link.get('url')
779
- l[key] = link
780
-
781
- return l
782
-
783
- def raise_for_status(self):
784
- """Raises stored :class:`HTTPError`, if one occurred."""
785
-
786
- http_error_msg = ''
787
-
788
- if 400 <= self.status_code < 500:
789
- http_error_msg = '%s Client Error: %s' % (self.status_code, self.reason)
790
-
791
- elif 500 <= self.status_code < 600:
792
- http_error_msg = '%s Server Error: %s' % (self.status_code, self.reason)
793
-
794
- if http_error_msg:
795
- raise HTTPError(http_error_msg, response=self)
796
-
797
- def close(self):
798
- """Releases the connection back to the pool. Once this method has been
799
- called the underlying ``raw`` object must not be accessed again.
800
-
801
- *Note: Should not normally need to be called explicitly.*
802
- """
803
- return self.raw.release_conn()
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """
4
+ requests.models
5
+ ~~~~~~~~~~~~~~~
6
+
7
+ This module contains the primary objects that power Requests.
8
+ """
9
+
10
+ import collections
11
+ import datetime
12
+ import sys
13
+
14
+ # Import encoding now, to avoid implicit import later.
15
+ # Implicit import within threads may cause LookupError when standard library is in a ZIP,
16
+ # such as in Embedded Python. See https://github.com/requests/requests/issues/3578.
17
+ import encodings.idna
18
+
19
+ from pip._vendor.urllib3.fields import RequestField
20
+ from pip._vendor.urllib3.filepost import encode_multipart_formdata
21
+ from pip._vendor.urllib3.util import parse_url
22
+ from pip._vendor.urllib3.exceptions import (
23
+ DecodeError, ReadTimeoutError, ProtocolError, LocationParseError)
24
+
25
+ from io import UnsupportedOperation
26
+ from .hooks import default_hooks
27
+ from .structures import CaseInsensitiveDict
28
+
29
+ from .auth import HTTPBasicAuth
30
+ from .cookies import cookiejar_from_dict, get_cookie_header, _copy_cookie_jar
31
+ from .exceptions import (
32
+ HTTPError, MissingSchema, InvalidURL, ChunkedEncodingError,
33
+ ContentDecodingError, ConnectionError, StreamConsumedError)
34
+ from ._internal_utils import to_native_string, unicode_is_ascii
35
+ from .utils import (
36
+ guess_filename, get_auth_from_url, requote_uri,
37
+ stream_decode_response_unicode, to_key_val_list, parse_header_links,
38
+ iter_slices, guess_json_utf, super_len, check_header_validity)
39
+ from .compat import (
40
+ cookielib, urlunparse, urlsplit, urlencode, str, bytes,
41
+ is_py2, chardet, builtin_str, basestring)
42
+ from .compat import json as complexjson
43
+ from .status_codes import codes
44
+
45
+ #: The set of HTTP status codes that indicate an automatically
46
+ #: processable redirect.
47
+ REDIRECT_STATI = (
48
+ codes.moved, # 301
49
+ codes.found, # 302
50
+ codes.other, # 303
51
+ codes.temporary_redirect, # 307
52
+ codes.permanent_redirect, # 308
53
+ )
54
+
55
+ DEFAULT_REDIRECT_LIMIT = 30
56
+ CONTENT_CHUNK_SIZE = 10 * 1024
57
+ ITER_CHUNK_SIZE = 512
58
+
59
+
60
+ class RequestEncodingMixin(object):
61
+ @property
62
+ def path_url(self):
63
+ """Build the path URL to use."""
64
+
65
+ url = []
66
+
67
+ p = urlsplit(self.url)
68
+
69
+ path = p.path
70
+ if not path:
71
+ path = '/'
72
+
73
+ url.append(path)
74
+
75
+ query = p.query
76
+ if query:
77
+ url.append('?')
78
+ url.append(query)
79
+
80
+ return ''.join(url)
81
+
82
+ @staticmethod
83
+ def _encode_params(data):
84
+ """Encode parameters in a piece of data.
85
+
86
+ Will successfully encode parameters when passed as a dict or a list of
87
+ 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary
88
+ if parameters are supplied as a dict.
89
+ """
90
+
91
+ if isinstance(data, (str, bytes)):
92
+ return data
93
+ elif hasattr(data, 'read'):
94
+ return data
95
+ elif hasattr(data, '__iter__'):
96
+ result = []
97
+ for k, vs in to_key_val_list(data):
98
+ if isinstance(vs, basestring) or not hasattr(vs, '__iter__'):
99
+ vs = [vs]
100
+ for v in vs:
101
+ if v is not None:
102
+ result.append(
103
+ (k.encode('utf-8') if isinstance(k, str) else k,
104
+ v.encode('utf-8') if isinstance(v, str) else v))
105
+ return urlencode(result, doseq=True)
106
+ else:
107
+ return data
108
+
109
+ @staticmethod
110
+ def _encode_files(files, data):
111
+ """Build the body for a multipart/form-data request.
112
+
113
+ Will successfully encode files when passed as a dict or a list of
114
+ tuples. Order is retained if data is a list of tuples but arbitrary
115
+ if parameters are supplied as a dict.
116
+ The tuples may be 2-tuples (filename, fileobj), 3-tuples (filename, fileobj, contentype)
117
+ or 4-tuples (filename, fileobj, contentype, custom_headers).
118
+ """
119
+ if (not files):
120
+ raise ValueError("Files must be provided.")
121
+ elif isinstance(data, basestring):
122
+ raise ValueError("Data must not be a string.")
123
+
124
+ new_fields = []
125
+ fields = to_key_val_list(data or {})
126
+ files = to_key_val_list(files or {})
127
+
128
+ for field, val in fields:
129
+ if isinstance(val, basestring) or not hasattr(val, '__iter__'):
130
+ val = [val]
131
+ for v in val:
132
+ if v is not None:
133
+ # Don't call str() on bytestrings: in Py3 it all goes wrong.
134
+ if not isinstance(v, bytes):
135
+ v = str(v)
136
+
137
+ new_fields.append(
138
+ (field.decode('utf-8') if isinstance(field, bytes) else field,
139
+ v.encode('utf-8') if isinstance(v, str) else v))
140
+
141
+ for (k, v) in files:
142
+ # support for explicit filename
143
+ ft = None
144
+ fh = None
145
+ if isinstance(v, (tuple, list)):
146
+ if len(v) == 2:
147
+ fn, fp = v
148
+ elif len(v) == 3:
149
+ fn, fp, ft = v
150
+ else:
151
+ fn, fp, ft, fh = v
152
+ else:
153
+ fn = guess_filename(v) or k
154
+ fp = v
155
+
156
+ if isinstance(fp, (str, bytes, bytearray)):
157
+ fdata = fp
158
+ else:
159
+ fdata = fp.read()
160
+
161
+ rf = RequestField(name=k, data=fdata, filename=fn, headers=fh)
162
+ rf.make_multipart(content_type=ft)
163
+ new_fields.append(rf)
164
+
165
+ body, content_type = encode_multipart_formdata(new_fields)
166
+
167
+ return body, content_type
168
+
169
+
170
+ class RequestHooksMixin(object):
171
+ def register_hook(self, event, hook):
172
+ """Properly register a hook."""
173
+
174
+ if event not in self.hooks:
175
+ raise ValueError('Unsupported event specified, with event name "%s"' % (event))
176
+
177
+ if isinstance(hook, collections.Callable):
178
+ self.hooks[event].append(hook)
179
+ elif hasattr(hook, '__iter__'):
180
+ self.hooks[event].extend(h for h in hook if isinstance(h, collections.Callable))
181
+
182
+ def deregister_hook(self, event, hook):
183
+ """Deregister a previously registered hook.
184
+ Returns True if the hook existed, False if not.
185
+ """
186
+
187
+ try:
188
+ self.hooks[event].remove(hook)
189
+ return True
190
+ except ValueError:
191
+ return False
192
+
193
+
194
+ class Request(RequestHooksMixin):
195
+ """A user-created :class:`Request <Request>` object.
196
+
197
+ Used to prepare a :class:`PreparedRequest <PreparedRequest>`, which is sent to the server.
198
+
199
+ :param method: HTTP method to use.
200
+ :param url: URL to send.
201
+ :param headers: dictionary of headers to send.
202
+ :param files: dictionary of {filename: fileobject} files to multipart upload.
203
+ :param data: the body to attach to the request. If a dictionary is provided, form-encoding will take place.
204
+ :param json: json for the body to attach to the request (if files or data is not specified).
205
+ :param params: dictionary of URL parameters to append to the URL.
206
+ :param auth: Auth handler or (user, pass) tuple.
207
+ :param cookies: dictionary or CookieJar of cookies to attach to this request.
208
+ :param hooks: dictionary of callback hooks, for internal usage.
209
+
210
+ Usage::
211
+
212
+ >>> import requests
213
+ >>> req = requests.Request('GET', 'http://httpbin.org/get')
214
+ >>> req.prepare()
215
+ <PreparedRequest [GET]>
216
+ """
217
+
218
+ def __init__(self,
219
+ method=None, url=None, headers=None, files=None, data=None,
220
+ params=None, auth=None, cookies=None, hooks=None, json=None):
221
+
222
+ # Default empty dicts for dict params.
223
+ data = [] if data is None else data
224
+ files = [] if files is None else files
225
+ headers = {} if headers is None else headers
226
+ params = {} if params is None else params
227
+ hooks = {} if hooks is None else hooks
228
+
229
+ self.hooks = default_hooks()
230
+ for (k, v) in list(hooks.items()):
231
+ self.register_hook(event=k, hook=v)
232
+
233
+ self.method = method
234
+ self.url = url
235
+ self.headers = headers
236
+ self.files = files
237
+ self.data = data
238
+ self.json = json
239
+ self.params = params
240
+ self.auth = auth
241
+ self.cookies = cookies
242
+
243
+ def __repr__(self):
244
+ return '<Request [%s]>' % (self.method)
245
+
246
+ def prepare(self):
247
+ """Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it."""
248
+ p = PreparedRequest()
249
+ p.prepare(
250
+ method=self.method,
251
+ url=self.url,
252
+ headers=self.headers,
253
+ files=self.files,
254
+ data=self.data,
255
+ json=self.json,
256
+ params=self.params,
257
+ auth=self.auth,
258
+ cookies=self.cookies,
259
+ hooks=self.hooks,
260
+ )
261
+ return p
262
+
263
+
264
+ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
265
+ """The fully mutable :class:`PreparedRequest <PreparedRequest>` object,
266
+ containing the exact bytes that will be sent to the server.
267
+
268
+ Generated from either a :class:`Request <Request>` object or manually.
269
+
270
+ Usage::
271
+
272
+ >>> import requests
273
+ >>> req = requests.Request('GET', 'http://httpbin.org/get')
274
+ >>> r = req.prepare()
275
+ <PreparedRequest [GET]>
276
+
277
+ >>> s = requests.Session()
278
+ >>> s.send(r)
279
+ <Response [200]>
280
+ """
281
+
282
+ def __init__(self):
283
+ #: HTTP verb to send to the server.
284
+ self.method = None
285
+ #: HTTP URL to send the request to.
286
+ self.url = None
287
+ #: dictionary of HTTP headers.
288
+ self.headers = None
289
+ # The `CookieJar` used to create the Cookie header will be stored here
290
+ # after prepare_cookies is called
291
+ self._cookies = None
292
+ #: request body to send to the server.
293
+ self.body = None
294
+ #: dictionary of callback hooks, for internal usage.
295
+ self.hooks = default_hooks()
296
+ #: integer denoting starting position of a readable file-like body.
297
+ self._body_position = None
298
+
299
+ def prepare(self,
300
+ method=None, url=None, headers=None, files=None, data=None,
301
+ params=None, auth=None, cookies=None, hooks=None, json=None):
302
+ """Prepares the entire request with the given parameters."""
303
+
304
+ self.prepare_method(method)
305
+ self.prepare_url(url, params)
306
+ self.prepare_headers(headers)
307
+ self.prepare_cookies(cookies)
308
+ self.prepare_body(data, files, json)
309
+ self.prepare_auth(auth, url)
310
+
311
+ # Note that prepare_auth must be last to enable authentication schemes
312
+ # such as OAuth to work on a fully prepared request.
313
+
314
+ # This MUST go after prepare_auth. Authenticators could add a hook
315
+ self.prepare_hooks(hooks)
316
+
317
+ def __repr__(self):
318
+ return '<PreparedRequest [%s]>' % (self.method)
319
+
320
+ def copy(self):
321
+ p = PreparedRequest()
322
+ p.method = self.method
323
+ p.url = self.url
324
+ p.headers = self.headers.copy() if self.headers is not None else None
325
+ p._cookies = _copy_cookie_jar(self._cookies)
326
+ p.body = self.body
327
+ p.hooks = self.hooks
328
+ p._body_position = self._body_position
329
+ return p
330
+
331
+ def prepare_method(self, method):
332
+ """Prepares the given HTTP method."""
333
+ self.method = method
334
+ if self.method is not None:
335
+ self.method = to_native_string(self.method.upper())
336
+
337
+ @staticmethod
338
+ def _get_idna_encoded_host(host):
339
+ from pip._vendor import idna
340
+
341
+ try:
342
+ host = idna.encode(host, uts46=True).decode('utf-8')
343
+ except idna.IDNAError:
344
+ raise UnicodeError
345
+ return host
346
+
347
+ def prepare_url(self, url, params):
348
+ """Prepares the given HTTP URL."""
349
+ #: Accept objects that have string representations.
350
+ #: We're unable to blindly call unicode/str functions
351
+ #: as this will include the bytestring indicator (b'')
352
+ #: on python 3.x.
353
+ #: https://github.com/requests/requests/pull/2238
354
+ if isinstance(url, bytes):
355
+ url = url.decode('utf8')
356
+ else:
357
+ url = unicode(url) if is_py2 else str(url)
358
+
359
+ # Remove leading whitespaces from url
360
+ url = url.lstrip()
361
+
362
+ # Don't do any URL preparation for non-HTTP schemes like `mailto`,
363
+ # `data` etc to work around exceptions from `url_parse`, which
364
+ # handles RFC 3986 only.
365
+ if ':' in url and not url.lower().startswith('http'):
366
+ self.url = url
367
+ return
368
+
369
+ # Support for unicode domain names and paths.
370
+ try:
371
+ scheme, auth, host, port, path, query, fragment = parse_url(url)
372
+ except LocationParseError as e:
373
+ raise InvalidURL(*e.args)
374
+
375
+ if not scheme:
376
+ error = ("Invalid URL {0!r}: No schema supplied. Perhaps you meant http://{0}?")
377
+ error = error.format(to_native_string(url, 'utf8'))
378
+
379
+ raise MissingSchema(error)
380
+
381
+ if not host:
382
+ raise InvalidURL("Invalid URL %r: No host supplied" % url)
383
+
384
+ # In general, we want to try IDNA encoding the hostname if the string contains
385
+ # non-ASCII characters. This allows users to automatically get the correct IDNA
386
+ # behaviour. For strings containing only ASCII characters, we need to also verify
387
+ # it doesn't start with a wildcard (*), before allowing the unencoded hostname.
388
+ if not unicode_is_ascii(host):
389
+ try:
390
+ host = self._get_idna_encoded_host(host)
391
+ except UnicodeError:
392
+ raise InvalidURL('URL has an invalid label.')
393
+ elif host.startswith(u'*'):
394
+ raise InvalidURL('URL has an invalid label.')
395
+
396
+ # Carefully reconstruct the network location
397
+ netloc = auth or ''
398
+ if netloc:
399
+ netloc += '@'
400
+ netloc += host
401
+ if port:
402
+ netloc += ':' + str(port)
403
+
404
+ # Bare domains aren't valid URLs.
405
+ if not path:
406
+ path = '/'
407
+
408
+ if is_py2:
409
+ if isinstance(scheme, str):
410
+ scheme = scheme.encode('utf-8')
411
+ if isinstance(netloc, str):
412
+ netloc = netloc.encode('utf-8')
413
+ if isinstance(path, str):
414
+ path = path.encode('utf-8')
415
+ if isinstance(query, str):
416
+ query = query.encode('utf-8')
417
+ if isinstance(fragment, str):
418
+ fragment = fragment.encode('utf-8')
419
+
420
+ if isinstance(params, (str, bytes)):
421
+ params = to_native_string(params)
422
+
423
+ enc_params = self._encode_params(params)
424
+ if enc_params:
425
+ if query:
426
+ query = '%s&%s' % (query, enc_params)
427
+ else:
428
+ query = enc_params
429
+
430
+ url = requote_uri(urlunparse([scheme, netloc, path, None, query, fragment]))
431
+ self.url = url
432
+
433
+ def prepare_headers(self, headers):
434
+ """Prepares the given HTTP headers."""
435
+
436
+ self.headers = CaseInsensitiveDict()
437
+ if headers:
438
+ for header in headers.items():
439
+ # Raise exception on invalid header value.
440
+ check_header_validity(header)
441
+ name, value = header
442
+ self.headers[to_native_string(name)] = value
443
+
444
+ def prepare_body(self, data, files, json=None):
445
+ """Prepares the given HTTP body data."""
446
+
447
+ # Check if file, fo, generator, iterator.
448
+ # If not, run through normal process.
449
+
450
+ # Nottin' on you.
451
+ body = None
452
+ content_type = None
453
+
454
+ if not data and json is not None:
455
+ # urllib3 requires a bytes-like body. Python 2's json.dumps
456
+ # provides this natively, but Python 3 gives a Unicode string.
457
+ content_type = 'application/json'
458
+ body = complexjson.dumps(json)
459
+ if not isinstance(body, bytes):
460
+ body = body.encode('utf-8')
461
+
462
+ is_stream = all([
463
+ hasattr(data, '__iter__'),
464
+ not isinstance(data, (basestring, list, tuple, collections.Mapping))
465
+ ])
466
+
467
+ try:
468
+ length = super_len(data)
469
+ except (TypeError, AttributeError, UnsupportedOperation):
470
+ length = None
471
+
472
+ if is_stream:
473
+ body = data
474
+
475
+ if getattr(body, 'tell', None) is not None:
476
+ # Record the current file position before reading.
477
+ # This will allow us to rewind a file in the event
478
+ # of a redirect.
479
+ try:
480
+ self._body_position = body.tell()
481
+ except (IOError, OSError):
482
+ # This differentiates from None, allowing us to catch
483
+ # a failed `tell()` later when trying to rewind the body
484
+ self._body_position = object()
485
+
486
+ if files:
487
+ raise NotImplementedError('Streamed bodies and files are mutually exclusive.')
488
+
489
+ if length:
490
+ self.headers['Content-Length'] = builtin_str(length)
491
+ else:
492
+ self.headers['Transfer-Encoding'] = 'chunked'
493
+ else:
494
+ # Multi-part file uploads.
495
+ if files:
496
+ (body, content_type) = self._encode_files(files, data)
497
+ else:
498
+ if data:
499
+ body = self._encode_params(data)
500
+ if isinstance(data, basestring) or hasattr(data, 'read'):
501
+ content_type = None
502
+ else:
503
+ content_type = 'application/x-www-form-urlencoded'
504
+
505
+ self.prepare_content_length(body)
506
+
507
+ # Add content-type if it wasn't explicitly provided.
508
+ if content_type and ('content-type' not in self.headers):
509
+ self.headers['Content-Type'] = content_type
510
+
511
+ self.body = body
512
+
513
+ def prepare_content_length(self, body):
514
+ """Prepare Content-Length header based on request method and body"""
515
+ if body is not None:
516
+ length = super_len(body)
517
+ if length:
518
+ # If length exists, set it. Otherwise, we fallback
519
+ # to Transfer-Encoding: chunked.
520
+ self.headers['Content-Length'] = builtin_str(length)
521
+ elif self.method not in ('GET', 'HEAD') and self.headers.get('Content-Length') is None:
522
+ # Set Content-Length to 0 for methods that can have a body
523
+ # but don't provide one. (i.e. not GET or HEAD)
524
+ self.headers['Content-Length'] = '0'
525
+
526
+ def prepare_auth(self, auth, url=''):
527
+ """Prepares the given HTTP auth data."""
528
+
529
+ # If no Auth is explicitly provided, extract it from the URL first.
530
+ if auth is None:
531
+ url_auth = get_auth_from_url(self.url)
532
+ auth = url_auth if any(url_auth) else None
533
+
534
+ if auth:
535
+ if isinstance(auth, tuple) and len(auth) == 2:
536
+ # special-case basic HTTP auth
537
+ auth = HTTPBasicAuth(*auth)
538
+
539
+ # Allow auth to make its changes.
540
+ r = auth(self)
541
+
542
+ # Update self to reflect the auth changes.
543
+ self.__dict__.update(r.__dict__)
544
+
545
+ # Recompute Content-Length
546
+ self.prepare_content_length(self.body)
547
+
548
+ def prepare_cookies(self, cookies):
549
+ """Prepares the given HTTP cookie data.
550
+
551
+ This function eventually generates a ``Cookie`` header from the
552
+ given cookies using cookielib. Due to cookielib's design, the header
553
+ will not be regenerated if it already exists, meaning this function
554
+ can only be called once for the life of the
555
+ :class:`PreparedRequest <PreparedRequest>` object. Any subsequent calls
556
+ to ``prepare_cookies`` will have no actual effect, unless the "Cookie"
557
+ header is removed beforehand.
558
+ """
559
+ if isinstance(cookies, cookielib.CookieJar):
560
+ self._cookies = cookies
561
+ else:
562
+ self._cookies = cookiejar_from_dict(cookies)
563
+
564
+ cookie_header = get_cookie_header(self._cookies, self)
565
+ if cookie_header is not None:
566
+ self.headers['Cookie'] = cookie_header
567
+
568
+ def prepare_hooks(self, hooks):
569
+ """Prepares the given hooks."""
570
+ # hooks can be passed as None to the prepare method and to this
571
+ # method. To prevent iterating over None, simply use an empty list
572
+ # if hooks is False-y
573
+ hooks = hooks or []
574
+ for event in hooks:
575
+ self.register_hook(event, hooks[event])
576
+
577
+
578
+ class Response(object):
579
+ """The :class:`Response <Response>` object, which contains a
580
+ server's response to an HTTP request.
581
+ """
582
+
583
+ __attrs__ = [
584
+ '_content', 'status_code', 'headers', 'url', 'history',
585
+ 'encoding', 'reason', 'cookies', 'elapsed', 'request'
586
+ ]
587
+
588
+ def __init__(self):
589
+ self._content = False
590
+ self._content_consumed = False
591
+ self._next = None
592
+
593
+ #: Integer Code of responded HTTP Status, e.g. 404 or 200.
594
+ self.status_code = None
595
+
596
+ #: Case-insensitive Dictionary of Response Headers.
597
+ #: For example, ``headers['content-encoding']`` will return the
598
+ #: value of a ``'Content-Encoding'`` response header.
599
+ self.headers = CaseInsensitiveDict()
600
+
601
+ #: File-like object representation of response (for advanced usage).
602
+ #: Use of ``raw`` requires that ``stream=True`` be set on the request.
603
+ # This requirement does not apply for use internally to Requests.
604
+ self.raw = None
605
+
606
+ #: Final URL location of Response.
607
+ self.url = None
608
+
609
+ #: Encoding to decode with when accessing r.text.
610
+ self.encoding = None
611
+
612
+ #: A list of :class:`Response <Response>` objects from
613
+ #: the history of the Request. Any redirect responses will end
614
+ #: up here. The list is sorted from the oldest to the most recent request.
615
+ self.history = []
616
+
617
+ #: Textual reason of responded HTTP Status, e.g. "Not Found" or "OK".
618
+ self.reason = None
619
+
620
+ #: A CookieJar of Cookies the server sent back.
621
+ self.cookies = cookiejar_from_dict({})
622
+
623
+ #: The amount of time elapsed between sending the request
624
+ #: and the arrival of the response (as a timedelta).
625
+ #: This property specifically measures the time taken between sending
626
+ #: the first byte of the request and finishing parsing the headers. It
627
+ #: is therefore unaffected by consuming the response content or the
628
+ #: value of the ``stream`` keyword argument.
629
+ self.elapsed = datetime.timedelta(0)
630
+
631
+ #: The :class:`PreparedRequest <PreparedRequest>` object to which this
632
+ #: is a response.
633
+ self.request = None
634
+
635
+ def __enter__(self):
636
+ return self
637
+
638
+ def __exit__(self, *args):
639
+ self.close()
640
+
641
+ def __getstate__(self):
642
+ # Consume everything; accessing the content attribute makes
643
+ # sure the content has been fully read.
644
+ if not self._content_consumed:
645
+ self.content
646
+
647
+ return dict(
648
+ (attr, getattr(self, attr, None))
649
+ for attr in self.__attrs__
650
+ )
651
+
652
+ def __setstate__(self, state):
653
+ for name, value in state.items():
654
+ setattr(self, name, value)
655
+
656
+ # pickled objects do not have .raw
657
+ setattr(self, '_content_consumed', True)
658
+ setattr(self, 'raw', None)
659
+
660
+ def __repr__(self):
661
+ return '<Response [%s]>' % (self.status_code)
662
+
663
+ def __bool__(self):
664
+ """Returns True if :attr:`status_code` is less than 400.
665
+
666
+ This attribute checks if the status code of the response is between
667
+ 400 and 600 to see if there was a client error or a server error. If
668
+ the status code, is between 200 and 400, this will return True. This
669
+ is **not** a check to see if the response code is ``200 OK``.
670
+ """
671
+ return self.ok
672
+
673
+ def __nonzero__(self):
674
+ """Returns True if :attr:`status_code` is less than 400.
675
+
676
+ This attribute checks if the status code of the response is between
677
+ 400 and 600 to see if there was a client error or a server error. If
678
+ the status code, is between 200 and 400, this will return True. This
679
+ is **not** a check to see if the response code is ``200 OK``.
680
+ """
681
+ return self.ok
682
+
683
+ def __iter__(self):
684
+ """Allows you to use a response as an iterator."""
685
+ return self.iter_content(128)
686
+
687
+ @property
688
+ def ok(self):
689
+ """Returns True if :attr:`status_code` is less than 400.
690
+
691
+ This attribute checks if the status code of the response is between
692
+ 400 and 600 to see if there was a client error or a server error. If
693
+ the status code, is between 200 and 400, this will return True. This
694
+ is **not** a check to see if the response code is ``200 OK``.
695
+ """
696
+ try:
697
+ self.raise_for_status()
698
+ except HTTPError:
699
+ return False
700
+ return True
701
+
702
+ @property
703
+ def is_redirect(self):
704
+ """True if this Response is a well-formed HTTP redirect that could have
705
+ been processed automatically (by :meth:`Session.resolve_redirects`).
706
+ """
707
+ return ('location' in self.headers and self.status_code in REDIRECT_STATI)
708
+
709
+ @property
710
+ def is_permanent_redirect(self):
711
+ """True if this Response one of the permanent versions of redirect."""
712
+ return ('location' in self.headers and self.status_code in (codes.moved_permanently, codes.permanent_redirect))
713
+
714
+ @property
715
+ def next(self):
716
+ """Returns a PreparedRequest for the next request in a redirect chain, if there is one."""
717
+ return self._next
718
+
719
+ @property
720
+ def apparent_encoding(self):
721
+ """The apparent encoding, provided by the chardet library."""
722
+ return chardet.detect(self.content)['encoding']
723
+
724
+ def iter_content(self, chunk_size=1, decode_unicode=False):
725
+ """Iterates over the response data. When stream=True is set on the
726
+ request, this avoids reading the content at once into memory for
727
+ large responses. The chunk size is the number of bytes it should
728
+ read into memory. This is not necessarily the length of each item
729
+ returned as decoding can take place.
730
+
731
+ chunk_size must be of type int or None. A value of None will
732
+ function differently depending on the value of `stream`.
733
+ stream=True will read data as it arrives in whatever size the
734
+ chunks are received. If stream=False, data is returned as
735
+ a single chunk.
736
+
737
+ If decode_unicode is True, content will be decoded using the best
738
+ available encoding based on the response.
739
+ """
740
+
741
+ def generate():
742
+ # Special case for urllib3.
743
+ if hasattr(self.raw, 'stream'):
744
+ try:
745
+ for chunk in self.raw.stream(chunk_size, decode_content=True):
746
+ yield chunk
747
+ except ProtocolError as e:
748
+ raise ChunkedEncodingError(e)
749
+ except DecodeError as e:
750
+ raise ContentDecodingError(e)
751
+ except ReadTimeoutError as e:
752
+ raise ConnectionError(e)
753
+ else:
754
+ # Standard file-like object.
755
+ while True:
756
+ chunk = self.raw.read(chunk_size)
757
+ if not chunk:
758
+ break
759
+ yield chunk
760
+
761
+ self._content_consumed = True
762
+
763
+ if self._content_consumed and isinstance(self._content, bool):
764
+ raise StreamConsumedError()
765
+ elif chunk_size is not None and not isinstance(chunk_size, int):
766
+ raise TypeError("chunk_size must be an int, it is instead a %s." % type(chunk_size))
767
+ # simulate reading small chunks of the content
768
+ reused_chunks = iter_slices(self._content, chunk_size)
769
+
770
+ stream_chunks = generate()
771
+
772
+ chunks = reused_chunks if self._content_consumed else stream_chunks
773
+
774
+ if decode_unicode:
775
+ chunks = stream_decode_response_unicode(chunks, self)
776
+
777
+ return chunks
778
+
779
+ def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None, delimiter=None):
780
+ """Iterates over the response data, one line at a time. When
781
+ stream=True is set on the request, this avoids reading the
782
+ content at once into memory for large responses.
783
+
784
+ .. note:: This method is not reentrant safe.
785
+ """
786
+
787
+ pending = None
788
+
789
+ for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode):
790
+
791
+ if pending is not None:
792
+ chunk = pending + chunk
793
+
794
+ if delimiter:
795
+ lines = chunk.split(delimiter)
796
+ else:
797
+ lines = chunk.splitlines()
798
+
799
+ if lines and lines[-1] and chunk and lines[-1][-1] == chunk[-1]:
800
+ pending = lines.pop()
801
+ else:
802
+ pending = None
803
+
804
+ for line in lines:
805
+ yield line
806
+
807
+ if pending is not None:
808
+ yield pending
809
+
810
+ @property
811
+ def content(self):
812
+ """Content of the response, in bytes."""
813
+
814
+ if self._content is False:
815
+ # Read the contents.
816
+ if self._content_consumed:
817
+ raise RuntimeError(
818
+ 'The content for this response was already consumed')
819
+
820
+ if self.status_code == 0 or self.raw is None:
821
+ self._content = None
822
+ else:
823
+ self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
824
+
825
+ self._content_consumed = True
826
+ # don't need to release the connection; that's been handled by urllib3
827
+ # since we exhausted the data.
828
+ return self._content
829
+
830
+ @property
831
+ def text(self):
832
+ """Content of the response, in unicode.
833
+
834
+ If Response.encoding is None, encoding will be guessed using
835
+ ``chardet``.
836
+
837
+ The encoding of the response content is determined based solely on HTTP
838
+ headers, following RFC 2616 to the letter. If you can take advantage of
839
+ non-HTTP knowledge to make a better guess at the encoding, you should
840
+ set ``r.encoding`` appropriately before accessing this property.
841
+ """
842
+
843
+ # Try charset from content-type
844
+ content = None
845
+ encoding = self.encoding
846
+
847
+ if not self.content:
848
+ return str('')
849
+
850
+ # Fallback to auto-detected encoding.
851
+ if self.encoding is None:
852
+ encoding = self.apparent_encoding
853
+
854
+ # Decode unicode from given encoding.
855
+ try:
856
+ content = str(self.content, encoding, errors='replace')
857
+ except (LookupError, TypeError):
858
+ # A LookupError is raised if the encoding was not found which could
859
+ # indicate a misspelling or similar mistake.
860
+ #
861
+ # A TypeError can be raised if encoding is None
862
+ #
863
+ # So we try blindly encoding.
864
+ content = str(self.content, errors='replace')
865
+
866
+ return content
867
+
868
+ def json(self, **kwargs):
869
+ r"""Returns the json-encoded content of a response, if any.
870
+
871
+ :param \*\*kwargs: Optional arguments that ``json.loads`` takes.
872
+ :raises ValueError: If the response body does not contain valid json.
873
+ """
874
+
875
+ if not self.encoding and self.content and len(self.content) > 3:
876
+ # No encoding set. JSON RFC 4627 section 3 states we should expect
877
+ # UTF-8, -16 or -32. Detect which one to use; If the detection or
878
+ # decoding fails, fall back to `self.text` (using chardet to make
879
+ # a best guess).
880
+ encoding = guess_json_utf(self.content)
881
+ if encoding is not None:
882
+ try:
883
+ return complexjson.loads(
884
+ self.content.decode(encoding), **kwargs
885
+ )
886
+ except UnicodeDecodeError:
887
+ # Wrong UTF codec detected; usually because it's not UTF-8
888
+ # but some other 8-bit codec. This is an RFC violation,
889
+ # and the server didn't bother to tell us what codec *was*
890
+ # used.
891
+ pass
892
+ return complexjson.loads(self.text, **kwargs)
893
+
894
+ @property
895
+ def links(self):
896
+ """Returns the parsed header links of the response, if any."""
897
+
898
+ header = self.headers.get('link')
899
+
900
+ # l = MultiDict()
901
+ l = {}
902
+
903
+ if header:
904
+ links = parse_header_links(header)
905
+
906
+ for link in links:
907
+ key = link.get('rel') or link.get('url')
908
+ l[key] = link
909
+
910
+ return l
911
+
912
+ def raise_for_status(self):
913
+ """Raises stored :class:`HTTPError`, if one occurred."""
914
+
915
+ http_error_msg = ''
916
+ if isinstance(self.reason, bytes):
917
+ # We attempt to decode utf-8 first because some servers
918
+ # choose to localize their reason strings. If the string
919
+ # isn't utf-8, we fall back to iso-8859-1 for all other
920
+ # encodings. (See PR #3538)
921
+ try:
922
+ reason = self.reason.decode('utf-8')
923
+ except UnicodeDecodeError:
924
+ reason = self.reason.decode('iso-8859-1')
925
+ else:
926
+ reason = self.reason
927
+
928
+ if 400 <= self.status_code < 500:
929
+ http_error_msg = u'%s Client Error: %s for url: %s' % (self.status_code, reason, self.url)
930
+
931
+ elif 500 <= self.status_code < 600:
932
+ http_error_msg = u'%s Server Error: %s for url: %s' % (self.status_code, reason, self.url)
933
+
934
+ if http_error_msg:
935
+ raise HTTPError(http_error_msg, response=self)
936
+
937
+ def close(self):
938
+ """Releases the connection back to the pool. Once this method has been
939
+ called the underlying ``raw`` object must not be accessed again.
940
+
941
+ *Note: Should not normally need to be called explicitly.*
942
+ """
943
+ if not self._content_consumed:
944
+ self.raw.close()
945
+
946
+ release_conn = getattr(self.raw, 'release_conn', None)
947
+ if release_conn is not None:
948
+ release_conn()