com.googler.python 1.0.7 → 1.0.9

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 (354) hide show
  1. package/package.json +4 -2
  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/_vendor/_markerlib/__init__.py +0 -16
  290. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/_markerlib/markers.py +0 -119
  291. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/sanitizer.py +0 -271
  292. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/serializer/__init__.py +0 -16
  293. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/serializer/htmlserializer.py +0 -320
  294. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/html5lib/treewalkers/pulldom.py +0 -63
  295. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/re-vendor.py +0 -34
  296. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/__init__.py +0 -3
  297. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/big5freq.py +0 -925
  298. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/chardetect.py +0 -46
  299. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/charsetgroupprober.py +0 -106
  300. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/charsetprober.py +0 -62
  301. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/codingstatemachine.py +0 -61
  302. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/constants.py +0 -39
  303. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/escprober.py +0 -86
  304. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/escsm.py +0 -242
  305. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/eucjpprober.py +0 -90
  306. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/euckrfreq.py +0 -596
  307. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/mbcharsetprober.py +0 -86
  308. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/mbcssm.py +0 -575
  309. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/sbcharsetprober.py +0 -120
  310. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/sjisprober.py +0 -91
  311. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/chardet/universaldetector.py +0 -170
  312. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/__init__.py +0 -58
  313. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/_collections.py +0 -205
  314. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/connection.py +0 -204
  315. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py +0 -422
  316. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/exceptions.py +0 -126
  317. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/packages/six.py +0 -385
  318. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/poolmanager.py +0 -258
  319. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/response.py +0 -308
  320. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/util/__init__.py +0 -27
  321. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/util/connection.py +0 -45
  322. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/util/request.py +0 -68
  323. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/util/response.py +0 -13
  324. package/python3.4.2/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py +0 -133
  325. package/python3.4.2/lib/python3.4/site-packages/pip/backwardcompat/__init__.py +0 -138
  326. package/python3.4.2/lib/python3.4/site-packages/pip/basecommand.py +0 -201
  327. package/python3.4.2/lib/python3.4/site-packages/pip/cmdoptions.py +0 -371
  328. package/python3.4.2/lib/python3.4/site-packages/pip/commands/__init__.py +0 -88
  329. package/python3.4.2/lib/python3.4/site-packages/pip/commands/bundle.py +0 -42
  330. package/python3.4.2/lib/python3.4/site-packages/pip/commands/completion.py +0 -59
  331. package/python3.4.2/lib/python3.4/site-packages/pip/commands/freeze.py +0 -114
  332. package/python3.4.2/lib/python3.4/site-packages/pip/commands/install.py +0 -314
  333. package/python3.4.2/lib/python3.4/site-packages/pip/commands/list.py +0 -162
  334. package/python3.4.2/lib/python3.4/site-packages/pip/commands/search.py +0 -132
  335. package/python3.4.2/lib/python3.4/site-packages/pip/commands/show.py +0 -80
  336. package/python3.4.2/lib/python3.4/site-packages/pip/commands/uninstall.py +0 -59
  337. package/python3.4.2/lib/python3.4/site-packages/pip/commands/unzip.py +0 -7
  338. package/python3.4.2/lib/python3.4/site-packages/pip/commands/wheel.py +0 -195
  339. package/python3.4.2/lib/python3.4/site-packages/pip/commands/zip.py +0 -351
  340. package/python3.4.2/lib/python3.4/site-packages/pip/download.py +0 -644
  341. package/python3.4.2/lib/python3.4/site-packages/pip/exceptions.py +0 -46
  342. package/python3.4.2/lib/python3.4/site-packages/pip/index.py +0 -990
  343. package/python3.4.2/lib/python3.4/site-packages/pip/locations.py +0 -171
  344. package/python3.4.2/lib/python3.4/site-packages/pip/log.py +0 -276
  345. package/python3.4.2/lib/python3.4/site-packages/pip/pep425tags.py +0 -102
  346. package/python3.4.2/lib/python3.4/site-packages/pip/req.py +0 -1931
  347. package/python3.4.2/lib/python3.4/site-packages/pip/runner.py +0 -18
  348. package/python3.4.2/lib/python3.4/site-packages/pip/util.py +0 -720
  349. package/python3.4.2/lib/python3.4/site-packages/pip/vcs/__init__.py +0 -251
  350. package/python3.4.2/lib/python3.4/site-packages/pip/vcs/bazaar.py +0 -131
  351. package/python3.4.2/lib/python3.4/site-packages/pip/vcs/git.py +0 -194
  352. package/python3.4.2/lib/python3.4/site-packages/pip/vcs/mercurial.py +0 -151
  353. package/python3.4.2/lib/python3.4/site-packages/pip/vcs/subversion.py +0 -273
  354. package/python3.4.2/lib/python3.4/site-packages/pip/wheel.py +0 -560
@@ -1,710 +1,905 @@
1
- # urllib3/connectionpool.py
2
- # Copyright 2008-2013 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
3
- #
4
- # This module is part of urllib3 and is released under
5
- # the MIT License: http://www.opensource.org/licenses/mit-license.php
6
-
7
- import sys
8
- import errno
9
- import logging
10
-
11
- from socket import error as SocketError, timeout as SocketTimeout
12
- import socket
13
-
14
- try: # Python 3
15
- from queue import LifoQueue, Empty, Full
16
- except ImportError:
17
- from Queue import LifoQueue, Empty, Full
18
- import Queue as _ # Platform-specific: Windows
19
-
20
-
21
- from .exceptions import (
22
- ClosedPoolError,
23
- ConnectionError,
24
- ConnectTimeoutError,
25
- EmptyPoolError,
26
- HostChangedError,
27
- LocationParseError,
28
- MaxRetryError,
29
- SSLError,
30
- TimeoutError,
31
- ReadTimeoutError,
32
- ProxyError,
33
- )
34
- from .packages.ssl_match_hostname import CertificateError
35
- from .packages import six
36
- from .connection import (
37
- port_by_scheme,
38
- DummyConnection,
39
- HTTPConnection, HTTPSConnection, VerifiedHTTPSConnection,
40
- HTTPException, BaseSSLError,
41
- )
42
- from .request import RequestMethods
43
- from .response import HTTPResponse
44
- from .util import (
45
- get_host,
46
- is_connection_dropped,
47
- Timeout,
48
- )
49
-
50
-
51
- xrange = six.moves.xrange
52
-
53
- log = logging.getLogger(__name__)
54
-
55
- _Default = object()
56
-
57
- ## Pool objects
58
-
59
- class ConnectionPool(object):
60
- """
61
- Base class for all connection pools, such as
62
- :class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`.
63
- """
64
-
65
- scheme = None
66
- QueueCls = LifoQueue
67
-
68
- def __init__(self, host, port=None):
69
- if host is None:
70
- raise LocationParseError(host)
71
-
72
- # httplib doesn't like it when we include brackets in ipv6 addresses
73
- host = host.strip('[]')
74
-
75
- self.host = host
76
- self.port = port
77
-
78
- def __str__(self):
79
- return '%s(host=%r, port=%r)' % (type(self).__name__,
80
- self.host, self.port)
81
-
82
- # This is taken from http://hg.python.org/cpython/file/7aaba721ebc0/Lib/socket.py#l252
83
- _blocking_errnos = set([errno.EAGAIN, errno.EWOULDBLOCK])
84
-
85
- class HTTPConnectionPool(ConnectionPool, RequestMethods):
86
- """
87
- Thread-safe connection pool for one host.
88
-
89
- :param host:
90
- Host used for this HTTP Connection (e.g. "localhost"), passed into
91
- :class:`httplib.HTTPConnection`.
92
-
93
- :param port:
94
- Port used for this HTTP Connection (None is equivalent to 80), passed
95
- into :class:`httplib.HTTPConnection`.
96
-
97
- :param strict:
98
- Causes BadStatusLine to be raised if the status line can't be parsed
99
- as a valid HTTP/1.0 or 1.1 status line, passed into
100
- :class:`httplib.HTTPConnection`.
101
-
102
- .. note::
103
- Only works in Python 2. This parameter is ignored in Python 3.
104
-
105
- :param timeout:
106
- Socket timeout in seconds for each individual connection. This can
107
- be a float or integer, which sets the timeout for the HTTP request,
108
- or an instance of :class:`urllib3.util.Timeout` which gives you more
109
- fine-grained control over request timeouts. After the constructor has
110
- been parsed, this is always a `urllib3.util.Timeout` object.
111
-
112
- :param maxsize:
113
- Number of connections to save that can be reused. More than 1 is useful
114
- in multithreaded situations. If ``block`` is set to false, more
115
- connections will be created but they will not be saved once they've
116
- been used.
117
-
118
- :param block:
119
- If set to True, no more than ``maxsize`` connections will be used at
120
- a time. When no free connections are available, the call will block
121
- until a connection has been released. This is a useful side effect for
122
- particular multithreaded situations where one does not want to use more
123
- than maxsize connections per host to prevent flooding.
124
-
125
- :param headers:
126
- Headers to include with all requests, unless other headers are given
127
- explicitly.
128
-
129
- :param _proxy:
130
- Parsed proxy URL, should not be used directly, instead, see
131
- :class:`urllib3.connectionpool.ProxyManager`"
132
-
133
- :param _proxy_headers:
134
- A dictionary with proxy headers, should not be used directly,
135
- instead, see :class:`urllib3.connectionpool.ProxyManager`"
136
- """
137
-
138
- scheme = 'http'
139
- ConnectionCls = HTTPConnection
140
-
141
- def __init__(self, host, port=None, strict=False,
142
- timeout=Timeout.DEFAULT_TIMEOUT, maxsize=1, block=False,
143
- headers=None, _proxy=None, _proxy_headers=None, **conn_kw):
144
- ConnectionPool.__init__(self, host, port)
145
- RequestMethods.__init__(self, headers)
146
-
147
- self.strict = strict
148
-
149
- # This is for backwards compatibility and can be removed once a timeout
150
- # can only be set to a Timeout object
151
- if not isinstance(timeout, Timeout):
152
- timeout = Timeout.from_float(timeout)
153
-
154
- self.timeout = timeout
155
-
156
- self.pool = self.QueueCls(maxsize)
157
- self.block = block
158
-
159
- self.proxy = _proxy
160
- self.proxy_headers = _proxy_headers or {}
161
-
162
- # Fill the queue up so that doing get() on it will block properly
163
- for _ in xrange(maxsize):
164
- self.pool.put(None)
165
-
166
- # These are mostly for testing and debugging purposes.
167
- self.num_connections = 0
168
- self.num_requests = 0
169
-
170
- if sys.version_info < (2, 7): # Python 2.6 and older
171
- conn_kw.pop('source_address', None)
172
- self.conn_kw = conn_kw
173
-
174
- def _new_conn(self):
175
- """
176
- Return a fresh :class:`HTTPConnection`.
177
- """
178
- self.num_connections += 1
179
- log.info("Starting new HTTP connection (%d): %s" %
180
- (self.num_connections, self.host))
181
-
182
- conn = self.ConnectionCls(host=self.host, port=self.port,
183
- timeout=self.timeout.connect_timeout,
184
- strict=self.strict, **self.conn_kw)
185
- if self.proxy is not None:
186
- # Enable Nagle's algorithm for proxies, to avoid packet
187
- # fragmentation.
188
- conn.tcp_nodelay = 0
189
- return conn
190
-
191
- def _get_conn(self, timeout=None):
192
- """
193
- Get a connection. Will return a pooled connection if one is available.
194
-
195
- If no connections are available and :prop:`.block` is ``False``, then a
196
- fresh connection is returned.
197
-
198
- :param timeout:
199
- Seconds to wait before giving up and raising
200
- :class:`urllib3.exceptions.EmptyPoolError` if the pool is empty and
201
- :prop:`.block` is ``True``.
202
- """
203
- conn = None
204
- try:
205
- conn = self.pool.get(block=self.block, timeout=timeout)
206
-
207
- except AttributeError: # self.pool is None
208
- raise ClosedPoolError(self, "Pool is closed.")
209
-
210
- except Empty:
211
- if self.block:
212
- raise EmptyPoolError(self,
213
- "Pool reached maximum size and no more "
214
- "connections are allowed.")
215
- pass # Oh well, we'll create a new connection then
216
-
217
- # If this is a persistent connection, check if it got disconnected
218
- if conn and is_connection_dropped(conn):
219
- log.info("Resetting dropped connection: %s" % self.host)
220
- conn.close()
221
-
222
- return conn or self._new_conn()
223
-
224
- def _put_conn(self, conn):
225
- """
226
- Put a connection back into the pool.
227
-
228
- :param conn:
229
- Connection object for the current host and port as returned by
230
- :meth:`._new_conn` or :meth:`._get_conn`.
231
-
232
- If the pool is already full, the connection is closed and discarded
233
- because we exceeded maxsize. If connections are discarded frequently,
234
- then maxsize should be increased.
235
-
236
- If the pool is closed, then the connection will be closed and discarded.
237
- """
238
- try:
239
- self.pool.put(conn, block=False)
240
- return # Everything is dandy, done.
241
- except AttributeError:
242
- # self.pool is None.
243
- pass
244
- except Full:
245
- # This should never happen if self.block == True
246
- log.warning(
247
- "Connection pool is full, discarding connection: %s" %
248
- self.host)
249
-
250
- # Connection never got put back into the pool, close it.
251
- if conn:
252
- conn.close()
253
-
254
- def _get_timeout(self, timeout):
255
- """ Helper that always returns a :class:`urllib3.util.Timeout` """
256
- if timeout is _Default:
257
- return self.timeout.clone()
258
-
259
- if isinstance(timeout, Timeout):
260
- return timeout.clone()
261
- else:
262
- # User passed us an int/float. This is for backwards compatibility,
263
- # can be removed later
264
- return Timeout.from_float(timeout)
265
-
266
- def _make_request(self, conn, method, url, timeout=_Default,
267
- **httplib_request_kw):
268
- """
269
- Perform a request on a given urllib connection object taken from our
270
- pool.
271
-
272
- :param conn:
273
- a connection from one of our connection pools
274
-
275
- :param timeout:
276
- Socket timeout in seconds for the request. This can be a
277
- float or integer, which will set the same timeout value for
278
- the socket connect and the socket read, or an instance of
279
- :class:`urllib3.util.Timeout`, which gives you more fine-grained
280
- control over your timeouts.
281
- """
282
- self.num_requests += 1
283
-
284
- timeout_obj = self._get_timeout(timeout)
285
-
286
- try:
287
- timeout_obj.start_connect()
288
- conn.timeout = timeout_obj.connect_timeout
289
- # conn.request() calls httplib.*.request, not the method in
290
- # urllib3.request. It also calls makefile (recv) on the socket.
291
- conn.request(method, url, **httplib_request_kw)
292
- except SocketTimeout:
293
- raise ConnectTimeoutError(
294
- self, "Connection to %s timed out. (connect timeout=%s)" %
295
- (self.host, timeout_obj.connect_timeout))
296
-
297
- # Reset the timeout for the recv() on the socket
298
- read_timeout = timeout_obj.read_timeout
299
-
300
- # App Engine doesn't have a sock attr
301
- if hasattr(conn, 'sock'):
302
- # In Python 3 socket.py will catch EAGAIN and return None when you
303
- # try and read into the file pointer created by http.client, which
304
- # instead raises a BadStatusLine exception. Instead of catching
305
- # the exception and assuming all BadStatusLine exceptions are read
306
- # timeouts, check for a zero timeout before making the request.
307
- if read_timeout == 0:
308
- raise ReadTimeoutError(
309
- self, url,
310
- "Read timed out. (read timeout=%s)" % read_timeout)
311
- if read_timeout is Timeout.DEFAULT_TIMEOUT:
312
- conn.sock.settimeout(socket.getdefaulttimeout())
313
- else: # None or a value
314
- conn.sock.settimeout(read_timeout)
315
-
316
- # Receive the response from the server
317
- try:
318
- try: # Python 2.7+, use buffering of HTTP responses
319
- httplib_response = conn.getresponse(buffering=True)
320
- except TypeError: # Python 2.6 and older
321
- httplib_response = conn.getresponse()
322
- except SocketTimeout:
323
- raise ReadTimeoutError(
324
- self, url, "Read timed out. (read timeout=%s)" % read_timeout)
325
-
326
- except BaseSSLError as e:
327
- # Catch possible read timeouts thrown as SSL errors. If not the
328
- # case, rethrow the original. We need to do this because of:
329
- # http://bugs.python.org/issue10272
330
- if 'timed out' in str(e) or \
331
- 'did not complete (read)' in str(e): # Python 2.6
332
- raise ReadTimeoutError(self, url, "Read timed out.")
333
-
334
- raise
335
-
336
- except SocketError as e: # Platform-specific: Python 2
337
- # See the above comment about EAGAIN in Python 3. In Python 2 we
338
- # have to specifically catch it and throw the timeout error
339
- if e.errno in _blocking_errnos:
340
- raise ReadTimeoutError(
341
- self, url,
342
- "Read timed out. (read timeout=%s)" % read_timeout)
343
-
344
- raise
345
-
346
- # AppEngine doesn't have a version attr.
347
- http_version = getattr(conn, '_http_vsn_str', 'HTTP/?')
348
- log.debug("\"%s %s %s\" %s %s" % (method, url, http_version,
349
- httplib_response.status,
350
- httplib_response.length))
351
- return httplib_response
352
-
353
- def close(self):
354
- """
355
- Close all pooled connections and disable the pool.
356
- """
357
- # Disable access to the pool
358
- old_pool, self.pool = self.pool, None
359
-
360
- try:
361
- while True:
362
- conn = old_pool.get(block=False)
363
- if conn:
364
- conn.close()
365
-
366
- except Empty:
367
- pass # Done.
368
-
369
- def is_same_host(self, url):
370
- """
371
- Check if the given ``url`` is a member of the same host as this
372
- connection pool.
373
- """
374
- if url.startswith('/'):
375
- return True
376
-
377
- # TODO: Add optional support for socket.gethostbyname checking.
378
- scheme, host, port = get_host(url)
379
-
380
- # Use explicit default port for comparison when none is given
381
- if self.port and not port:
382
- port = port_by_scheme.get(scheme)
383
- elif not self.port and port == port_by_scheme.get(scheme):
384
- port = None
385
-
386
- return (scheme, host, port) == (self.scheme, self.host, self.port)
387
-
388
- def urlopen(self, method, url, body=None, headers=None, retries=3,
389
- redirect=True, assert_same_host=True, timeout=_Default,
390
- pool_timeout=None, release_conn=None, **response_kw):
391
- """
392
- Get a connection from the pool and perform an HTTP request. This is the
393
- lowest level call for making a request, so you'll need to specify all
394
- the raw details.
395
-
396
- .. note::
397
-
398
- More commonly, it's appropriate to use a convenience method provided
399
- by :class:`.RequestMethods`, such as :meth:`request`.
400
-
401
- .. note::
402
-
403
- `release_conn` will only behave as expected if
404
- `preload_content=False` because we want to make
405
- `preload_content=False` the default behaviour someday soon without
406
- breaking backwards compatibility.
407
-
408
- :param method:
409
- HTTP request method (such as GET, POST, PUT, etc.)
410
-
411
- :param body:
412
- Data to send in the request body (useful for creating
413
- POST requests, see HTTPConnectionPool.post_url for
414
- more convenience).
415
-
416
- :param headers:
417
- Dictionary of custom headers to send, such as User-Agent,
418
- If-None-Match, etc. If None, pool headers are used. If provided,
419
- these headers completely replace any pool-specific headers.
420
-
421
- :param retries:
422
- Number of retries to allow before raising a MaxRetryError exception.
423
- If `False`, then retries are disabled and any exception is raised
424
- immediately.
425
-
426
- :param redirect:
427
- If True, automatically handle redirects (status codes 301, 302,
428
- 303, 307, 308). Each redirect counts as a retry. Disabling retries
429
- will disable redirect, too.
430
-
431
- :param assert_same_host:
432
- If ``True``, will make sure that the host of the pool requests is
433
- consistent else will raise HostChangedError. When False, you can
434
- use the pool on an HTTP proxy and request foreign hosts.
435
-
436
- :param timeout:
437
- If specified, overrides the default timeout for this one
438
- request. It may be a float (in seconds) or an instance of
439
- :class:`urllib3.util.Timeout`.
440
-
441
- :param pool_timeout:
442
- If set and the pool is set to block=True, then this method will
443
- block for ``pool_timeout`` seconds and raise EmptyPoolError if no
444
- connection is available within the time period.
445
-
446
- :param release_conn:
447
- If False, then the urlopen call will not release the connection
448
- back into the pool once a response is received (but will release if
449
- you read the entire contents of the response such as when
450
- `preload_content=True`). This is useful if you're not preloading
451
- the response's content immediately. You will need to call
452
- ``r.release_conn()`` on the response ``r`` to return the connection
453
- back into the pool. If None, it takes the value of
454
- ``response_kw.get('preload_content', True)``.
455
-
456
- :param \**response_kw:
457
- Additional parameters are passed to
458
- :meth:`urllib3.response.HTTPResponse.from_httplib`
459
- """
460
- if headers is None:
461
- headers = self.headers
462
-
463
- if retries < 0 and retries is not False:
464
- raise MaxRetryError(self, url)
465
-
466
- if release_conn is None:
467
- release_conn = response_kw.get('preload_content', True)
468
-
469
- # Check host
470
- if assert_same_host and not self.is_same_host(url):
471
- raise HostChangedError(self, url, retries - 1)
472
-
473
- conn = None
474
-
475
- # Merge the proxy headers. Only do this in HTTP. We have to copy the
476
- # headers dict so we can safely change it without those changes being
477
- # reflected in anyone else's copy.
478
- if self.scheme == 'http':
479
- headers = headers.copy()
480
- headers.update(self.proxy_headers)
481
-
482
- # Must keep the exception bound to a separate variable or else Python 3
483
- # complains about UnboundLocalError.
484
- err = None
485
-
486
- try:
487
- # Request a connection from the queue
488
- conn = self._get_conn(timeout=pool_timeout)
489
-
490
- # Make the request on the httplib connection object
491
- httplib_response = self._make_request(conn, method, url,
492
- timeout=timeout,
493
- body=body, headers=headers)
494
-
495
- # If we're going to release the connection in ``finally:``, then
496
- # the request doesn't need to know about the connection. Otherwise
497
- # it will also try to release it and we'll have a double-release
498
- # mess.
499
- response_conn = not release_conn and conn
500
-
501
- # Import httplib's response into our own wrapper object
502
- response = HTTPResponse.from_httplib(httplib_response,
503
- pool=self,
504
- connection=response_conn,
505
- **response_kw)
506
-
507
- # else:
508
- # The connection will be put back into the pool when
509
- # ``response.release_conn()`` is called (implicitly by
510
- # ``response.read()``)
511
-
512
- except Empty:
513
- # Timed out by queue.
514
- raise EmptyPoolError(self, "No pool connections are available.")
515
-
516
- except (BaseSSLError, CertificateError) as e:
517
- # Release connection unconditionally because there is no way to
518
- # close it externally in case of exception.
519
- release_conn = True
520
- raise SSLError(e)
521
-
522
- except (TimeoutError, HTTPException, SocketError) as e:
523
- if conn:
524
- # Discard the connection for these exceptions. It will be
525
- # be replaced during the next _get_conn() call.
526
- conn.close()
527
- conn = None
528
-
529
- if not retries:
530
- if isinstance(e, TimeoutError):
531
- # TimeoutError is exempt from MaxRetryError-wrapping.
532
- # FIXME: ... Not sure why. Add a reason here.
533
- raise
534
-
535
- # Wrap unexpected exceptions with the most appropriate
536
- # module-level exception and re-raise.
537
- if isinstance(e, SocketError) and self.proxy:
538
- raise ProxyError('Cannot connect to proxy.', e)
539
-
540
- if retries is False:
541
- raise ConnectionError('Connection failed.', e)
542
-
543
- raise MaxRetryError(self, url, e)
544
-
545
- # Keep track of the error for the retry warning.
546
- err = e
547
-
548
- finally:
549
- if release_conn:
550
- # Put the connection back to be reused. If the connection is
551
- # expired then it will be None, which will get replaced with a
552
- # fresh connection during _get_conn.
553
- self._put_conn(conn)
554
-
555
- if not conn:
556
- # Try again
557
- log.warning("Retrying (%d attempts remain) after connection "
558
- "broken by '%r': %s" % (retries, err, url))
559
- return self.urlopen(method, url, body, headers, retries - 1,
560
- redirect, assert_same_host,
561
- timeout=timeout, pool_timeout=pool_timeout,
562
- release_conn=release_conn, **response_kw)
563
-
564
- # Handle redirect?
565
- redirect_location = redirect and response.get_redirect_location()
566
- if redirect_location and retries is not False:
567
- if response.status == 303:
568
- method = 'GET'
569
- log.info("Redirecting %s -> %s" % (url, redirect_location))
570
- return self.urlopen(method, redirect_location, body, headers,
571
- retries - 1, redirect, assert_same_host,
572
- timeout=timeout, pool_timeout=pool_timeout,
573
- release_conn=release_conn, **response_kw)
574
-
575
- return response
576
-
577
-
578
- class HTTPSConnectionPool(HTTPConnectionPool):
579
- """
580
- Same as :class:`.HTTPConnectionPool`, but HTTPS.
581
-
582
- When Python is compiled with the :mod:`ssl` module, then
583
- :class:`.VerifiedHTTPSConnection` is used, which *can* verify certificates,
584
- instead of :class:`.HTTPSConnection`.
585
-
586
- :class:`.VerifiedHTTPSConnection` uses one of ``assert_fingerprint``,
587
- ``assert_hostname`` and ``host`` in this order to verify connections.
588
- If ``assert_hostname`` is False, no verification is done.
589
-
590
- The ``key_file``, ``cert_file``, ``cert_reqs``, ``ca_certs`` and
591
- ``ssl_version`` are only used if :mod:`ssl` is available and are fed into
592
- :meth:`urllib3.util.ssl_wrap_socket` to upgrade the connection socket
593
- into an SSL socket.
594
- """
595
-
596
- scheme = 'https'
597
- ConnectionCls = HTTPSConnection
598
-
599
- def __init__(self, host, port=None,
600
- strict=False, timeout=None, maxsize=1,
601
- block=False, headers=None,
602
- _proxy=None, _proxy_headers=None,
603
- key_file=None, cert_file=None, cert_reqs=None,
604
- ca_certs=None, ssl_version=None,
605
- assert_hostname=None, assert_fingerprint=None,
606
- **conn_kw):
607
-
608
- if sys.version_info < (2, 7): # Python 2.6 or older
609
- conn_kw.pop('source_address', None)
610
-
611
- HTTPConnectionPool.__init__(self, host, port, strict, timeout, maxsize,
612
- block, headers, _proxy, _proxy_headers, **conn_kw)
613
- self.key_file = key_file
614
- self.cert_file = cert_file
615
- self.cert_reqs = cert_reqs
616
- self.ca_certs = ca_certs
617
- self.ssl_version = ssl_version
618
- self.assert_hostname = assert_hostname
619
- self.assert_fingerprint = assert_fingerprint
620
- self.conn_kw = conn_kw
621
-
622
- def _prepare_conn(self, conn):
623
- """
624
- Prepare the ``connection`` for :meth:`urllib3.util.ssl_wrap_socket`
625
- and establish the tunnel if proxy is used.
626
- """
627
-
628
- if isinstance(conn, VerifiedHTTPSConnection):
629
- conn.set_cert(key_file=self.key_file,
630
- cert_file=self.cert_file,
631
- cert_reqs=self.cert_reqs,
632
- ca_certs=self.ca_certs,
633
- assert_hostname=self.assert_hostname,
634
- assert_fingerprint=self.assert_fingerprint)
635
- conn.ssl_version = self.ssl_version
636
- conn.conn_kw = self.conn_kw
637
-
638
- if self.proxy is not None:
639
- # Python 2.7+
640
- try:
641
- set_tunnel = conn.set_tunnel
642
- except AttributeError: # Platform-specific: Python 2.6
643
- set_tunnel = conn._set_tunnel
644
- set_tunnel(self.host, self.port, self.proxy_headers)
645
- # Establish tunnel connection early, because otherwise httplib
646
- # would improperly set Host: header to proxy's IP:port.
647
- conn.connect()
648
-
649
- return conn
650
-
651
- def _new_conn(self):
652
- """
653
- Return a fresh :class:`httplib.HTTPSConnection`.
654
- """
655
- self.num_connections += 1
656
- log.info("Starting new HTTPS connection (%d): %s"
657
- % (self.num_connections, self.host))
658
-
659
- if not self.ConnectionCls or self.ConnectionCls is DummyConnection:
660
- # Platform-specific: Python without ssl
661
- raise SSLError("Can't connect to HTTPS URL because the SSL "
662
- "module is not available.")
663
-
664
- actual_host = self.host
665
- actual_port = self.port
666
- if self.proxy is not None:
667
- actual_host = self.proxy.host
668
- actual_port = self.proxy.port
669
-
670
- extra_params = {}
671
- if not six.PY3: # Python 2
672
- extra_params['strict'] = self.strict
673
- extra_params.update(self.conn_kw)
674
-
675
- conn = self.ConnectionCls(host=actual_host, port=actual_port,
676
- timeout=self.timeout.connect_timeout,
677
- **extra_params)
678
- if self.proxy is not None:
679
- # Enable Nagle's algorithm for proxies, to avoid packet
680
- # fragmentation.
681
- conn.tcp_nodelay = 0
682
-
683
- return self._prepare_conn(conn)
684
-
685
-
686
- def connection_from_url(url, **kw):
687
- """
688
- Given a url, return an :class:`.ConnectionPool` instance of its host.
689
-
690
- This is a shortcut for not having to parse out the scheme, host, and port
691
- of the url before creating an :class:`.ConnectionPool` instance.
692
-
693
- :param url:
694
- Absolute URL string that must include the scheme. Port is optional.
695
-
696
- :param \**kw:
697
- Passes additional parameters to the constructor of the appropriate
698
- :class:`.ConnectionPool`. Useful for specifying things like
699
- timeout, maxsize, headers, etc.
700
-
701
- Example: ::
702
-
703
- >>> conn = connection_from_url('http://google.com/')
704
- >>> r = conn.request('GET', '/')
705
- """
706
- scheme, host, port = get_host(url)
707
- if scheme == 'https':
708
- return HTTPSConnectionPool(host, port=port, **kw)
709
- else:
710
- return HTTPConnectionPool(host, port=port, **kw)
1
+ from __future__ import absolute_import
2
+ import errno
3
+ import logging
4
+ import sys
5
+ import warnings
6
+
7
+ from socket import error as SocketError, timeout as SocketTimeout
8
+ import socket
9
+
10
+
11
+ from .exceptions import (
12
+ ClosedPoolError,
13
+ ProtocolError,
14
+ EmptyPoolError,
15
+ HeaderParsingError,
16
+ HostChangedError,
17
+ LocationValueError,
18
+ MaxRetryError,
19
+ ProxyError,
20
+ ReadTimeoutError,
21
+ SSLError,
22
+ TimeoutError,
23
+ InsecureRequestWarning,
24
+ NewConnectionError,
25
+ )
26
+ from .packages.ssl_match_hostname import CertificateError
27
+ from .packages import six
28
+ from .packages.six.moves import queue
29
+ from .connection import (
30
+ port_by_scheme,
31
+ DummyConnection,
32
+ HTTPConnection, HTTPSConnection, VerifiedHTTPSConnection,
33
+ HTTPException, BaseSSLError,
34
+ )
35
+ from .request import RequestMethods
36
+ from .response import HTTPResponse
37
+
38
+ from .util.connection import is_connection_dropped
39
+ from .util.request import set_file_position
40
+ from .util.response import assert_header_parsing
41
+ from .util.retry import Retry
42
+ from .util.timeout import Timeout
43
+ from .util.url import get_host, Url
44
+
45
+
46
+ if six.PY2:
47
+ # Queue is imported for side effects on MS Windows
48
+ import Queue as _unused_module_Queue # noqa: F401
49
+
50
+ xrange = six.moves.xrange
51
+
52
+ log = logging.getLogger(__name__)
53
+
54
+ _Default = object()
55
+
56
+
57
+ # Pool objects
58
+ class ConnectionPool(object):
59
+ """
60
+ Base class for all connection pools, such as
61
+ :class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`.
62
+ """
63
+
64
+ scheme = None
65
+ QueueCls = queue.LifoQueue
66
+
67
+ def __init__(self, host, port=None):
68
+ if not host:
69
+ raise LocationValueError("No host specified.")
70
+
71
+ self.host = _ipv6_host(host).lower()
72
+ self._proxy_host = host.lower()
73
+ self.port = port
74
+
75
+ def __str__(self):
76
+ return '%s(host=%r, port=%r)' % (type(self).__name__,
77
+ self.host, self.port)
78
+
79
+ def __enter__(self):
80
+ return self
81
+
82
+ def __exit__(self, exc_type, exc_val, exc_tb):
83
+ self.close()
84
+ # Return False to re-raise any potential exceptions
85
+ return False
86
+
87
+ def close(self):
88
+ """
89
+ Close all pooled connections and disable the pool.
90
+ """
91
+ pass
92
+
93
+
94
+ # This is taken from http://hg.python.org/cpython/file/7aaba721ebc0/Lib/socket.py#l252
95
+ _blocking_errnos = set([errno.EAGAIN, errno.EWOULDBLOCK])
96
+
97
+
98
+ class HTTPConnectionPool(ConnectionPool, RequestMethods):
99
+ """
100
+ Thread-safe connection pool for one host.
101
+
102
+ :param host:
103
+ Host used for this HTTP Connection (e.g. "localhost"), passed into
104
+ :class:`httplib.HTTPConnection`.
105
+
106
+ :param port:
107
+ Port used for this HTTP Connection (None is equivalent to 80), passed
108
+ into :class:`httplib.HTTPConnection`.
109
+
110
+ :param strict:
111
+ Causes BadStatusLine to be raised if the status line can't be parsed
112
+ as a valid HTTP/1.0 or 1.1 status line, passed into
113
+ :class:`httplib.HTTPConnection`.
114
+
115
+ .. note::
116
+ Only works in Python 2. This parameter is ignored in Python 3.
117
+
118
+ :param timeout:
119
+ Socket timeout in seconds for each individual connection. This can
120
+ be a float or integer, which sets the timeout for the HTTP request,
121
+ or an instance of :class:`urllib3.util.Timeout` which gives you more
122
+ fine-grained control over request timeouts. After the constructor has
123
+ been parsed, this is always a `urllib3.util.Timeout` object.
124
+
125
+ :param maxsize:
126
+ Number of connections to save that can be reused. More than 1 is useful
127
+ in multithreaded situations. If ``block`` is set to False, more
128
+ connections will be created but they will not be saved once they've
129
+ been used.
130
+
131
+ :param block:
132
+ If set to True, no more than ``maxsize`` connections will be used at
133
+ a time. When no free connections are available, the call will block
134
+ until a connection has been released. This is a useful side effect for
135
+ particular multithreaded situations where one does not want to use more
136
+ than maxsize connections per host to prevent flooding.
137
+
138
+ :param headers:
139
+ Headers to include with all requests, unless other headers are given
140
+ explicitly.
141
+
142
+ :param retries:
143
+ Retry configuration to use by default with requests in this pool.
144
+
145
+ :param _proxy:
146
+ Parsed proxy URL, should not be used directly, instead, see
147
+ :class:`urllib3.connectionpool.ProxyManager`"
148
+
149
+ :param _proxy_headers:
150
+ A dictionary with proxy headers, should not be used directly,
151
+ instead, see :class:`urllib3.connectionpool.ProxyManager`"
152
+
153
+ :param \\**conn_kw:
154
+ Additional parameters are used to create fresh :class:`urllib3.connection.HTTPConnection`,
155
+ :class:`urllib3.connection.HTTPSConnection` instances.
156
+ """
157
+
158
+ scheme = 'http'
159
+ ConnectionCls = HTTPConnection
160
+ ResponseCls = HTTPResponse
161
+
162
+ def __init__(self, host, port=None, strict=False,
163
+ timeout=Timeout.DEFAULT_TIMEOUT, maxsize=1, block=False,
164
+ headers=None, retries=None,
165
+ _proxy=None, _proxy_headers=None,
166
+ **conn_kw):
167
+ ConnectionPool.__init__(self, host, port)
168
+ RequestMethods.__init__(self, headers)
169
+
170
+ self.strict = strict
171
+
172
+ if not isinstance(timeout, Timeout):
173
+ timeout = Timeout.from_float(timeout)
174
+
175
+ if retries is None:
176
+ retries = Retry.DEFAULT
177
+
178
+ self.timeout = timeout
179
+ self.retries = retries
180
+
181
+ self.pool = self.QueueCls(maxsize)
182
+ self.block = block
183
+
184
+ self.proxy = _proxy
185
+ self.proxy_headers = _proxy_headers or {}
186
+
187
+ # Fill the queue up so that doing get() on it will block properly
188
+ for _ in xrange(maxsize):
189
+ self.pool.put(None)
190
+
191
+ # These are mostly for testing and debugging purposes.
192
+ self.num_connections = 0
193
+ self.num_requests = 0
194
+ self.conn_kw = conn_kw
195
+
196
+ if self.proxy:
197
+ # Enable Nagle's algorithm for proxies, to avoid packet fragmentation.
198
+ # We cannot know if the user has added default socket options, so we cannot replace the
199
+ # list.
200
+ self.conn_kw.setdefault('socket_options', [])
201
+
202
+ def _new_conn(self):
203
+ """
204
+ Return a fresh :class:`HTTPConnection`.
205
+ """
206
+ self.num_connections += 1
207
+ log.debug("Starting new HTTP connection (%d): %s",
208
+ self.num_connections, self.host)
209
+
210
+ conn = self.ConnectionCls(host=self.host, port=self.port,
211
+ timeout=self.timeout.connect_timeout,
212
+ strict=self.strict, **self.conn_kw)
213
+ return conn
214
+
215
+ def _get_conn(self, timeout=None):
216
+ """
217
+ Get a connection. Will return a pooled connection if one is available.
218
+
219
+ If no connections are available and :prop:`.block` is ``False``, then a
220
+ fresh connection is returned.
221
+
222
+ :param timeout:
223
+ Seconds to wait before giving up and raising
224
+ :class:`urllib3.exceptions.EmptyPoolError` if the pool is empty and
225
+ :prop:`.block` is ``True``.
226
+ """
227
+ conn = None
228
+ try:
229
+ conn = self.pool.get(block=self.block, timeout=timeout)
230
+
231
+ except AttributeError: # self.pool is None
232
+ raise ClosedPoolError(self, "Pool is closed.")
233
+
234
+ except queue.Empty:
235
+ if self.block:
236
+ raise EmptyPoolError(self,
237
+ "Pool reached maximum size and no more "
238
+ "connections are allowed.")
239
+ pass # Oh well, we'll create a new connection then
240
+
241
+ # If this is a persistent connection, check if it got disconnected
242
+ if conn and is_connection_dropped(conn):
243
+ log.debug("Resetting dropped connection: %s", self.host)
244
+ conn.close()
245
+ if getattr(conn, 'auto_open', 1) == 0:
246
+ # This is a proxied connection that has been mutated by
247
+ # httplib._tunnel() and cannot be reused (since it would
248
+ # attempt to bypass the proxy)
249
+ conn = None
250
+
251
+ return conn or self._new_conn()
252
+
253
+ def _put_conn(self, conn):
254
+ """
255
+ Put a connection back into the pool.
256
+
257
+ :param conn:
258
+ Connection object for the current host and port as returned by
259
+ :meth:`._new_conn` or :meth:`._get_conn`.
260
+
261
+ If the pool is already full, the connection is closed and discarded
262
+ because we exceeded maxsize. If connections are discarded frequently,
263
+ then maxsize should be increased.
264
+
265
+ If the pool is closed, then the connection will be closed and discarded.
266
+ """
267
+ try:
268
+ self.pool.put(conn, block=False)
269
+ return # Everything is dandy, done.
270
+ except AttributeError:
271
+ # self.pool is None.
272
+ pass
273
+ except queue.Full:
274
+ # This should never happen if self.block == True
275
+ log.warning(
276
+ "Connection pool is full, discarding connection: %s",
277
+ self.host)
278
+
279
+ # Connection never got put back into the pool, close it.
280
+ if conn:
281
+ conn.close()
282
+
283
+ def _validate_conn(self, conn):
284
+ """
285
+ Called right before a request is made, after the socket is created.
286
+ """
287
+ pass
288
+
289
+ def _prepare_proxy(self, conn):
290
+ # Nothing to do for HTTP connections.
291
+ pass
292
+
293
+ def _get_timeout(self, timeout):
294
+ """ Helper that always returns a :class:`urllib3.util.Timeout` """
295
+ if timeout is _Default:
296
+ return self.timeout.clone()
297
+
298
+ if isinstance(timeout, Timeout):
299
+ return timeout.clone()
300
+ else:
301
+ # User passed us an int/float. This is for backwards compatibility,
302
+ # can be removed later
303
+ return Timeout.from_float(timeout)
304
+
305
+ def _raise_timeout(self, err, url, timeout_value):
306
+ """Is the error actually a timeout? Will raise a ReadTimeout or pass"""
307
+
308
+ if isinstance(err, SocketTimeout):
309
+ raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
310
+
311
+ # See the above comment about EAGAIN in Python 3. In Python 2 we have
312
+ # to specifically catch it and throw the timeout error
313
+ if hasattr(err, 'errno') and err.errno in _blocking_errnos:
314
+ raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
315
+
316
+ # Catch possible read timeouts thrown as SSL errors. If not the
317
+ # case, rethrow the original. We need to do this because of:
318
+ # http://bugs.python.org/issue10272
319
+ if 'timed out' in str(err) or 'did not complete (read)' in str(err): # Python 2.6
320
+ raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
321
+
322
+ def _make_request(self, conn, method, url, timeout=_Default, chunked=False,
323
+ **httplib_request_kw):
324
+ """
325
+ Perform a request on a given urllib connection object taken from our
326
+ pool.
327
+
328
+ :param conn:
329
+ a connection from one of our connection pools
330
+
331
+ :param timeout:
332
+ Socket timeout in seconds for the request. This can be a
333
+ float or integer, which will set the same timeout value for
334
+ the socket connect and the socket read, or an instance of
335
+ :class:`urllib3.util.Timeout`, which gives you more fine-grained
336
+ control over your timeouts.
337
+ """
338
+ self.num_requests += 1
339
+
340
+ timeout_obj = self._get_timeout(timeout)
341
+ timeout_obj.start_connect()
342
+ conn.timeout = timeout_obj.connect_timeout
343
+
344
+ # Trigger any extra validation we need to do.
345
+ try:
346
+ self._validate_conn(conn)
347
+ except (SocketTimeout, BaseSSLError) as e:
348
+ # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.
349
+ self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
350
+ raise
351
+
352
+ # conn.request() calls httplib.*.request, not the method in
353
+ # urllib3.request. It also calls makefile (recv) on the socket.
354
+ if chunked:
355
+ conn.request_chunked(method, url, **httplib_request_kw)
356
+ else:
357
+ conn.request(method, url, **httplib_request_kw)
358
+
359
+ # Reset the timeout for the recv() on the socket
360
+ read_timeout = timeout_obj.read_timeout
361
+
362
+ # App Engine doesn't have a sock attr
363
+ if getattr(conn, 'sock', None):
364
+ # In Python 3 socket.py will catch EAGAIN and return None when you
365
+ # try and read into the file pointer created by http.client, which
366
+ # instead raises a BadStatusLine exception. Instead of catching
367
+ # the exception and assuming all BadStatusLine exceptions are read
368
+ # timeouts, check for a zero timeout before making the request.
369
+ if read_timeout == 0:
370
+ raise ReadTimeoutError(
371
+ self, url, "Read timed out. (read timeout=%s)" % read_timeout)
372
+ if read_timeout is Timeout.DEFAULT_TIMEOUT:
373
+ conn.sock.settimeout(socket.getdefaulttimeout())
374
+ else: # None or a value
375
+ conn.sock.settimeout(read_timeout)
376
+
377
+ # Receive the response from the server
378
+ try:
379
+ try: # Python 2.7, use buffering of HTTP responses
380
+ httplib_response = conn.getresponse(buffering=True)
381
+ except TypeError: # Python 2.6 and older, Python 3
382
+ try:
383
+ httplib_response = conn.getresponse()
384
+ except Exception as e:
385
+ # Remove the TypeError from the exception chain in Python 3;
386
+ # otherwise it looks like a programming error was the cause.
387
+ six.raise_from(e, None)
388
+ except (SocketTimeout, BaseSSLError, SocketError) as e:
389
+ self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
390
+ raise
391
+
392
+ # AppEngine doesn't have a version attr.
393
+ http_version = getattr(conn, '_http_vsn_str', 'HTTP/?')
394
+ log.debug("%s://%s:%s \"%s %s %s\" %s %s", self.scheme, self.host, self.port,
395
+ method, url, http_version, httplib_response.status,
396
+ httplib_response.length)
397
+
398
+ try:
399
+ assert_header_parsing(httplib_response.msg)
400
+ except (HeaderParsingError, TypeError) as hpe: # Platform-specific: Python 3
401
+ log.warning(
402
+ 'Failed to parse headers (url=%s): %s',
403
+ self._absolute_url(url), hpe, exc_info=True)
404
+
405
+ return httplib_response
406
+
407
+ def _absolute_url(self, path):
408
+ return Url(scheme=self.scheme, host=self.host, port=self.port, path=path).url
409
+
410
+ def close(self):
411
+ """
412
+ Close all pooled connections and disable the pool.
413
+ """
414
+ # Disable access to the pool
415
+ old_pool, self.pool = self.pool, None
416
+
417
+ try:
418
+ while True:
419
+ conn = old_pool.get(block=False)
420
+ if conn:
421
+ conn.close()
422
+
423
+ except queue.Empty:
424
+ pass # Done.
425
+
426
+ def is_same_host(self, url):
427
+ """
428
+ Check if the given ``url`` is a member of the same host as this
429
+ connection pool.
430
+ """
431
+ if url.startswith('/'):
432
+ return True
433
+
434
+ # TODO: Add optional support for socket.gethostbyname checking.
435
+ scheme, host, port = get_host(url)
436
+
437
+ host = _ipv6_host(host).lower()
438
+
439
+ # Use explicit default port for comparison when none is given
440
+ if self.port and not port:
441
+ port = port_by_scheme.get(scheme)
442
+ elif not self.port and port == port_by_scheme.get(scheme):
443
+ port = None
444
+
445
+ return (scheme, host, port) == (self.scheme, self.host, self.port)
446
+
447
+ def urlopen(self, method, url, body=None, headers=None, retries=None,
448
+ redirect=True, assert_same_host=True, timeout=_Default,
449
+ pool_timeout=None, release_conn=None, chunked=False,
450
+ body_pos=None, **response_kw):
451
+ """
452
+ Get a connection from the pool and perform an HTTP request. This is the
453
+ lowest level call for making a request, so you'll need to specify all
454
+ the raw details.
455
+
456
+ .. note::
457
+
458
+ More commonly, it's appropriate to use a convenience method provided
459
+ by :class:`.RequestMethods`, such as :meth:`request`.
460
+
461
+ .. note::
462
+
463
+ `release_conn` will only behave as expected if
464
+ `preload_content=False` because we want to make
465
+ `preload_content=False` the default behaviour someday soon without
466
+ breaking backwards compatibility.
467
+
468
+ :param method:
469
+ HTTP request method (such as GET, POST, PUT, etc.)
470
+
471
+ :param body:
472
+ Data to send in the request body (useful for creating
473
+ POST requests, see HTTPConnectionPool.post_url for
474
+ more convenience).
475
+
476
+ :param headers:
477
+ Dictionary of custom headers to send, such as User-Agent,
478
+ If-None-Match, etc. If None, pool headers are used. If provided,
479
+ these headers completely replace any pool-specific headers.
480
+
481
+ :param retries:
482
+ Configure the number of retries to allow before raising a
483
+ :class:`~urllib3.exceptions.MaxRetryError` exception.
484
+
485
+ Pass ``None`` to retry until you receive a response. Pass a
486
+ :class:`~urllib3.util.retry.Retry` object for fine-grained control
487
+ over different types of retries.
488
+ Pass an integer number to retry connection errors that many times,
489
+ but no other types of errors. Pass zero to never retry.
490
+
491
+ If ``False``, then retries are disabled and any exception is raised
492
+ immediately. Also, instead of raising a MaxRetryError on redirects,
493
+ the redirect response will be returned.
494
+
495
+ :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
496
+
497
+ :param redirect:
498
+ If True, automatically handle redirects (status codes 301, 302,
499
+ 303, 307, 308). Each redirect counts as a retry. Disabling retries
500
+ will disable redirect, too.
501
+
502
+ :param assert_same_host:
503
+ If ``True``, will make sure that the host of the pool requests is
504
+ consistent else will raise HostChangedError. When False, you can
505
+ use the pool on an HTTP proxy and request foreign hosts.
506
+
507
+ :param timeout:
508
+ If specified, overrides the default timeout for this one
509
+ request. It may be a float (in seconds) or an instance of
510
+ :class:`urllib3.util.Timeout`.
511
+
512
+ :param pool_timeout:
513
+ If set and the pool is set to block=True, then this method will
514
+ block for ``pool_timeout`` seconds and raise EmptyPoolError if no
515
+ connection is available within the time period.
516
+
517
+ :param release_conn:
518
+ If False, then the urlopen call will not release the connection
519
+ back into the pool once a response is received (but will release if
520
+ you read the entire contents of the response such as when
521
+ `preload_content=True`). This is useful if you're not preloading
522
+ the response's content immediately. You will need to call
523
+ ``r.release_conn()`` on the response ``r`` to return the connection
524
+ back into the pool. If None, it takes the value of
525
+ ``response_kw.get('preload_content', True)``.
526
+
527
+ :param chunked:
528
+ If True, urllib3 will send the body using chunked transfer
529
+ encoding. Otherwise, urllib3 will send the body using the standard
530
+ content-length form. Defaults to False.
531
+
532
+ :param int body_pos:
533
+ Position to seek to in file-like body in the event of a retry or
534
+ redirect. Typically this won't need to be set because urllib3 will
535
+ auto-populate the value when needed.
536
+
537
+ :param \\**response_kw:
538
+ Additional parameters are passed to
539
+ :meth:`urllib3.response.HTTPResponse.from_httplib`
540
+ """
541
+ if headers is None:
542
+ headers = self.headers
543
+
544
+ if not isinstance(retries, Retry):
545
+ retries = Retry.from_int(retries, redirect=redirect, default=self.retries)
546
+
547
+ if release_conn is None:
548
+ release_conn = response_kw.get('preload_content', True)
549
+
550
+ # Check host
551
+ if assert_same_host and not self.is_same_host(url):
552
+ raise HostChangedError(self, url, retries)
553
+
554
+ conn = None
555
+
556
+ # Track whether `conn` needs to be released before
557
+ # returning/raising/recursing. Update this variable if necessary, and
558
+ # leave `release_conn` constant throughout the function. That way, if
559
+ # the function recurses, the original value of `release_conn` will be
560
+ # passed down into the recursive call, and its value will be respected.
561
+ #
562
+ # See issue #651 [1] for details.
563
+ #
564
+ # [1] <https://github.com/shazow/urllib3/issues/651>
565
+ release_this_conn = release_conn
566
+
567
+ # Merge the proxy headers. Only do this in HTTP. We have to copy the
568
+ # headers dict so we can safely change it without those changes being
569
+ # reflected in anyone else's copy.
570
+ if self.scheme == 'http':
571
+ headers = headers.copy()
572
+ headers.update(self.proxy_headers)
573
+
574
+ # Must keep the exception bound to a separate variable or else Python 3
575
+ # complains about UnboundLocalError.
576
+ err = None
577
+
578
+ # Keep track of whether we cleanly exited the except block. This
579
+ # ensures we do proper cleanup in finally.
580
+ clean_exit = False
581
+
582
+ # Rewind body position, if needed. Record current position
583
+ # for future rewinds in the event of a redirect/retry.
584
+ body_pos = set_file_position(body, body_pos)
585
+
586
+ try:
587
+ # Request a connection from the queue.
588
+ timeout_obj = self._get_timeout(timeout)
589
+ conn = self._get_conn(timeout=pool_timeout)
590
+
591
+ conn.timeout = timeout_obj.connect_timeout
592
+
593
+ is_new_proxy_conn = self.proxy is not None and not getattr(conn, 'sock', None)
594
+ if is_new_proxy_conn:
595
+ self._prepare_proxy(conn)
596
+
597
+ # Make the request on the httplib connection object.
598
+ httplib_response = self._make_request(conn, method, url,
599
+ timeout=timeout_obj,
600
+ body=body, headers=headers,
601
+ chunked=chunked)
602
+
603
+ # If we're going to release the connection in ``finally:``, then
604
+ # the response doesn't need to know about the connection. Otherwise
605
+ # it will also try to release it and we'll have a double-release
606
+ # mess.
607
+ response_conn = conn if not release_conn else None
608
+
609
+ # Pass method to Response for length checking
610
+ response_kw['request_method'] = method
611
+
612
+ # Import httplib's response into our own wrapper object
613
+ response = self.ResponseCls.from_httplib(httplib_response,
614
+ pool=self,
615
+ connection=response_conn,
616
+ retries=retries,
617
+ **response_kw)
618
+
619
+ # Everything went great!
620
+ clean_exit = True
621
+
622
+ except queue.Empty:
623
+ # Timed out by queue.
624
+ raise EmptyPoolError(self, "No pool connections are available.")
625
+
626
+ except (TimeoutError, HTTPException, SocketError, ProtocolError,
627
+ BaseSSLError, SSLError, CertificateError) as e:
628
+ # Discard the connection for these exceptions. It will be
629
+ # replaced during the next _get_conn() call.
630
+ clean_exit = False
631
+ if isinstance(e, (BaseSSLError, CertificateError)):
632
+ e = SSLError(e)
633
+ elif isinstance(e, (SocketError, NewConnectionError)) and self.proxy:
634
+ e = ProxyError('Cannot connect to proxy.', e)
635
+ elif isinstance(e, (SocketError, HTTPException)):
636
+ e = ProtocolError('Connection aborted.', e)
637
+
638
+ retries = retries.increment(method, url, error=e, _pool=self,
639
+ _stacktrace=sys.exc_info()[2])
640
+ retries.sleep()
641
+
642
+ # Keep track of the error for the retry warning.
643
+ err = e
644
+
645
+ finally:
646
+ if not clean_exit:
647
+ # We hit some kind of exception, handled or otherwise. We need
648
+ # to throw the connection away unless explicitly told not to.
649
+ # Close the connection, set the variable to None, and make sure
650
+ # we put the None back in the pool to avoid leaking it.
651
+ conn = conn and conn.close()
652
+ release_this_conn = True
653
+
654
+ if release_this_conn:
655
+ # Put the connection back to be reused. If the connection is
656
+ # expired then it will be None, which will get replaced with a
657
+ # fresh connection during _get_conn.
658
+ self._put_conn(conn)
659
+
660
+ if not conn:
661
+ # Try again
662
+ log.warning("Retrying (%r) after connection "
663
+ "broken by '%r': %s", retries, err, url)
664
+ return self.urlopen(method, url, body, headers, retries,
665
+ redirect, assert_same_host,
666
+ timeout=timeout, pool_timeout=pool_timeout,
667
+ release_conn=release_conn, body_pos=body_pos,
668
+ **response_kw)
669
+
670
+ def drain_and_release_conn(response):
671
+ try:
672
+ # discard any remaining response body, the connection will be
673
+ # released back to the pool once the entire response is read
674
+ response.read()
675
+ except (TimeoutError, HTTPException, SocketError, ProtocolError,
676
+ BaseSSLError, SSLError) as e:
677
+ pass
678
+
679
+ # Handle redirect?
680
+ redirect_location = redirect and response.get_redirect_location()
681
+ if redirect_location:
682
+ if response.status == 303:
683
+ method = 'GET'
684
+
685
+ try:
686
+ retries = retries.increment(method, url, response=response, _pool=self)
687
+ except MaxRetryError:
688
+ if retries.raise_on_redirect:
689
+ # Drain and release the connection for this response, since
690
+ # we're not returning it to be released manually.
691
+ drain_and_release_conn(response)
692
+ raise
693
+ return response
694
+
695
+ # drain and return the connection to the pool before recursing
696
+ drain_and_release_conn(response)
697
+
698
+ retries.sleep_for_retry(response)
699
+ log.debug("Redirecting %s -> %s", url, redirect_location)
700
+ return self.urlopen(
701
+ method, redirect_location, body, headers,
702
+ retries=retries, redirect=redirect,
703
+ assert_same_host=assert_same_host,
704
+ timeout=timeout, pool_timeout=pool_timeout,
705
+ release_conn=release_conn, body_pos=body_pos,
706
+ **response_kw)
707
+
708
+ # Check if we should retry the HTTP response.
709
+ has_retry_after = bool(response.getheader('Retry-After'))
710
+ if retries.is_retry(method, response.status, has_retry_after):
711
+ try:
712
+ retries = retries.increment(method, url, response=response, _pool=self)
713
+ except MaxRetryError:
714
+ if retries.raise_on_status:
715
+ # Drain and release the connection for this response, since
716
+ # we're not returning it to be released manually.
717
+ drain_and_release_conn(response)
718
+ raise
719
+ return response
720
+
721
+ # drain and return the connection to the pool before recursing
722
+ drain_and_release_conn(response)
723
+
724
+ retries.sleep(response)
725
+ log.debug("Retry: %s", url)
726
+ return self.urlopen(
727
+ method, url, body, headers,
728
+ retries=retries, redirect=redirect,
729
+ assert_same_host=assert_same_host,
730
+ timeout=timeout, pool_timeout=pool_timeout,
731
+ release_conn=release_conn,
732
+ body_pos=body_pos, **response_kw)
733
+
734
+ return response
735
+
736
+
737
+ class HTTPSConnectionPool(HTTPConnectionPool):
738
+ """
739
+ Same as :class:`.HTTPConnectionPool`, but HTTPS.
740
+
741
+ When Python is compiled with the :mod:`ssl` module, then
742
+ :class:`.VerifiedHTTPSConnection` is used, which *can* verify certificates,
743
+ instead of :class:`.HTTPSConnection`.
744
+
745
+ :class:`.VerifiedHTTPSConnection` uses one of ``assert_fingerprint``,
746
+ ``assert_hostname`` and ``host`` in this order to verify connections.
747
+ If ``assert_hostname`` is False, no verification is done.
748
+
749
+ The ``key_file``, ``cert_file``, ``cert_reqs``, ``ca_certs``,
750
+ ``ca_cert_dir``, and ``ssl_version`` are only used if :mod:`ssl` is
751
+ available and are fed into :meth:`urllib3.util.ssl_wrap_socket` to upgrade
752
+ the connection socket into an SSL socket.
753
+ """
754
+
755
+ scheme = 'https'
756
+ ConnectionCls = HTTPSConnection
757
+
758
+ def __init__(self, host, port=None,
759
+ strict=False, timeout=Timeout.DEFAULT_TIMEOUT, maxsize=1,
760
+ block=False, headers=None, retries=None,
761
+ _proxy=None, _proxy_headers=None,
762
+ key_file=None, cert_file=None, cert_reqs=None,
763
+ ca_certs=None, ssl_version=None,
764
+ assert_hostname=None, assert_fingerprint=None,
765
+ ca_cert_dir=None, **conn_kw):
766
+
767
+ HTTPConnectionPool.__init__(self, host, port, strict, timeout, maxsize,
768
+ block, headers, retries, _proxy, _proxy_headers,
769
+ **conn_kw)
770
+
771
+ if ca_certs and cert_reqs is None:
772
+ cert_reqs = 'CERT_REQUIRED'
773
+
774
+ self.key_file = key_file
775
+ self.cert_file = cert_file
776
+ self.cert_reqs = cert_reqs
777
+ self.ca_certs = ca_certs
778
+ self.ca_cert_dir = ca_cert_dir
779
+ self.ssl_version = ssl_version
780
+ self.assert_hostname = assert_hostname
781
+ self.assert_fingerprint = assert_fingerprint
782
+
783
+ def _prepare_conn(self, conn):
784
+ """
785
+ Prepare the ``connection`` for :meth:`urllib3.util.ssl_wrap_socket`
786
+ and establish the tunnel if proxy is used.
787
+ """
788
+
789
+ if isinstance(conn, VerifiedHTTPSConnection):
790
+ conn.set_cert(key_file=self.key_file,
791
+ cert_file=self.cert_file,
792
+ cert_reqs=self.cert_reqs,
793
+ ca_certs=self.ca_certs,
794
+ ca_cert_dir=self.ca_cert_dir,
795
+ assert_hostname=self.assert_hostname,
796
+ assert_fingerprint=self.assert_fingerprint)
797
+ conn.ssl_version = self.ssl_version
798
+ return conn
799
+
800
+ def _prepare_proxy(self, conn):
801
+ """
802
+ Establish tunnel connection early, because otherwise httplib
803
+ would improperly set Host: header to proxy's IP:port.
804
+ """
805
+ # Python 2.7+
806
+ try:
807
+ set_tunnel = conn.set_tunnel
808
+ except AttributeError: # Platform-specific: Python 2.6
809
+ set_tunnel = conn._set_tunnel
810
+
811
+ if sys.version_info <= (2, 6, 4) and not self.proxy_headers: # Python 2.6.4 and older
812
+ set_tunnel(self._proxy_host, self.port)
813
+ else:
814
+ set_tunnel(self._proxy_host, self.port, self.proxy_headers)
815
+
816
+ conn.connect()
817
+
818
+ def _new_conn(self):
819
+ """
820
+ Return a fresh :class:`httplib.HTTPSConnection`.
821
+ """
822
+ self.num_connections += 1
823
+ log.debug("Starting new HTTPS connection (%d): %s",
824
+ self.num_connections, self.host)
825
+
826
+ if not self.ConnectionCls or self.ConnectionCls is DummyConnection:
827
+ raise SSLError("Can't connect to HTTPS URL because the SSL "
828
+ "module is not available.")
829
+
830
+ actual_host = self.host
831
+ actual_port = self.port
832
+ if self.proxy is not None:
833
+ actual_host = self.proxy.host
834
+ actual_port = self.proxy.port
835
+
836
+ conn = self.ConnectionCls(host=actual_host, port=actual_port,
837
+ timeout=self.timeout.connect_timeout,
838
+ strict=self.strict, **self.conn_kw)
839
+
840
+ return self._prepare_conn(conn)
841
+
842
+ def _validate_conn(self, conn):
843
+ """
844
+ Called right before a request is made, after the socket is created.
845
+ """
846
+ super(HTTPSConnectionPool, self)._validate_conn(conn)
847
+
848
+ # Force connect early to allow us to validate the connection.
849
+ if not getattr(conn, 'sock', None): # AppEngine might not have `.sock`
850
+ conn.connect()
851
+
852
+ if not conn.is_verified:
853
+ warnings.warn((
854
+ 'Unverified HTTPS request is being made. '
855
+ 'Adding certificate verification is strongly advised. See: '
856
+ 'https://urllib3.readthedocs.io/en/latest/advanced-usage.html'
857
+ '#ssl-warnings'),
858
+ InsecureRequestWarning)
859
+
860
+
861
+ def connection_from_url(url, **kw):
862
+ """
863
+ Given a url, return an :class:`.ConnectionPool` instance of its host.
864
+
865
+ This is a shortcut for not having to parse out the scheme, host, and port
866
+ of the url before creating an :class:`.ConnectionPool` instance.
867
+
868
+ :param url:
869
+ Absolute URL string that must include the scheme. Port is optional.
870
+
871
+ :param \\**kw:
872
+ Passes additional parameters to the constructor of the appropriate
873
+ :class:`.ConnectionPool`. Useful for specifying things like
874
+ timeout, maxsize, headers, etc.
875
+
876
+ Example::
877
+
878
+ >>> conn = connection_from_url('http://google.com/')
879
+ >>> r = conn.request('GET', '/')
880
+ """
881
+ scheme, host, port = get_host(url)
882
+ port = port or port_by_scheme.get(scheme, 80)
883
+ if scheme == 'https':
884
+ return HTTPSConnectionPool(host, port=port, **kw)
885
+ else:
886
+ return HTTPConnectionPool(host, port=port, **kw)
887
+
888
+
889
+ def _ipv6_host(host):
890
+ """
891
+ Process IPv6 address literals
892
+ """
893
+
894
+ # httplib doesn't like it when we include brackets in IPv6 addresses
895
+ # Specifically, if we include brackets but also pass the port then
896
+ # httplib crazily doubles up the square brackets on the Host header.
897
+ # Instead, we need to make sure we never pass ``None`` as the port.
898
+ # However, for backward compatibility reasons we can't actually
899
+ # *assert* that. See http://bugs.python.org/issue28539
900
+ #
901
+ # Also if an IPv6 address literal has a zone identifier, the
902
+ # percent sign might be URIencoded, convert it back into ASCII
903
+ if host.startswith('[') and host.endswith(']'):
904
+ host = host.replace('%25', '%').strip('[]')
905
+ return host