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,1064 +1,1117 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2013 Vinay Sajip.
4
- # Licensed to the Python Software Foundation under a contributor agreement.
5
- # See LICENSE.txt and CONTRIBUTORS.txt.
6
- #
7
- from __future__ import absolute_import
8
-
9
- import os
10
- import re
11
- import sys
12
-
13
- if sys.version_info[0] < 3:
14
- from StringIO import StringIO
15
- string_types = basestring,
16
- text_type = unicode
17
- from types import FileType as file_type
18
- import __builtin__ as builtins
19
- import ConfigParser as configparser
20
- from ._backport import shutil
21
- from urlparse import urlparse, urlunparse, urljoin, urlsplit, urlunsplit
22
- from urllib import (urlretrieve, quote as _quote, unquote, url2pathname,
23
- pathname2url, ContentTooShortError, splittype)
24
-
25
- def quote(s):
26
- if isinstance(s, unicode):
27
- s = s.encode('utf-8')
28
- return _quote(s)
29
-
30
- import urllib2
31
- from urllib2 import (Request, urlopen, URLError, HTTPError,
32
- HTTPBasicAuthHandler, HTTPPasswordMgr,
33
- HTTPSHandler, HTTPHandler, HTTPRedirectHandler,
34
- build_opener)
35
- import httplib
36
- import xmlrpclib
37
- import Queue as queue
38
- from HTMLParser import HTMLParser
39
- import htmlentitydefs
40
- raw_input = raw_input
41
- from itertools import ifilter as filter
42
- from itertools import ifilterfalse as filterfalse
43
-
44
- _userprog = None
45
- def splituser(host):
46
- """splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'."""
47
- global _userprog
48
- if _userprog is None:
49
- import re
50
- _userprog = re.compile('^(.*)@(.*)$')
51
-
52
- match = _userprog.match(host)
53
- if match: return match.group(1, 2)
54
- return None, host
55
-
56
- else:
57
- from io import StringIO
58
- string_types = str,
59
- text_type = str
60
- from io import TextIOWrapper as file_type
61
- import builtins
62
- import configparser
63
- import shutil
64
- from urllib.parse import (urlparse, urlunparse, urljoin, splituser, quote,
65
- unquote, urlsplit, urlunsplit, splittype)
66
- from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
67
- pathname2url,
68
- HTTPBasicAuthHandler, HTTPPasswordMgr,
69
- HTTPSHandler, HTTPHandler, HTTPRedirectHandler,
70
- build_opener)
71
- from urllib.error import HTTPError, URLError, ContentTooShortError
72
- import http.client as httplib
73
- import urllib.request as urllib2
74
- import xmlrpc.client as xmlrpclib
75
- import queue
76
- from html.parser import HTMLParser
77
- import html.entities as htmlentitydefs
78
- raw_input = input
79
- from itertools import filterfalse
80
- filter = filter
81
-
82
- try:
83
- from ssl import match_hostname, CertificateError
84
- except ImportError:
85
- class CertificateError(ValueError):
86
- pass
87
-
88
-
89
- def _dnsname_to_pat(dn):
90
- pats = []
91
- for frag in dn.split(r'.'):
92
- if frag == '*':
93
- # When '*' is a fragment by itself, it matches a non-empty
94
- # dotless fragment.
95
- pats.append('[^.]+')
96
- else:
97
- # Otherwise, '*' matches any dotless fragment.
98
- frag = re.escape(frag)
99
- pats.append(frag.replace(r'\*', '[^.]*'))
100
- return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
101
-
102
-
103
- def match_hostname(cert, hostname):
104
- """Verify that *cert* (in decoded format as returned by
105
- SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules
106
- are mostly followed, but IP addresses are not accepted for *hostname*.
107
-
108
- CertificateError is raised on failure. On success, the function
109
- returns nothing.
110
- """
111
- if not cert:
112
- raise ValueError("empty or no certificate")
113
- dnsnames = []
114
- san = cert.get('subjectAltName', ())
115
- for key, value in san:
116
- if key == 'DNS':
117
- if _dnsname_to_pat(value).match(hostname):
118
- return
119
- dnsnames.append(value)
120
- if not dnsnames:
121
- # The subject is only checked when there is no dNSName entry
122
- # in subjectAltName
123
- for sub in cert.get('subject', ()):
124
- for key, value in sub:
125
- # XXX according to RFC 2818, the most specific Common Name
126
- # must be used.
127
- if key == 'commonName':
128
- if _dnsname_to_pat(value).match(hostname):
129
- return
130
- dnsnames.append(value)
131
- if len(dnsnames) > 1:
132
- raise CertificateError("hostname %r "
133
- "doesn't match either of %s"
134
- % (hostname, ', '.join(map(repr, dnsnames))))
135
- elif len(dnsnames) == 1:
136
- raise CertificateError("hostname %r "
137
- "doesn't match %r"
138
- % (hostname, dnsnames[0]))
139
- else:
140
- raise CertificateError("no appropriate commonName or "
141
- "subjectAltName fields were found")
142
-
143
-
144
- try:
145
- from types import SimpleNamespace as Container
146
- except ImportError:
147
- class Container(object):
148
- """
149
- A generic container for when multiple values need to be returned
150
- """
151
- def __init__(self, **kwargs):
152
- self.__dict__.update(kwargs)
153
-
154
-
155
- try:
156
- from shutil import which
157
- except ImportError:
158
- # Implementation from Python 3.3
159
- def which(cmd, mode=os.F_OK | os.X_OK, path=None):
160
- """Given a command, mode, and a PATH string, return the path which
161
- conforms to the given mode on the PATH, or None if there is no such
162
- file.
163
-
164
- `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
165
- of os.environ.get("PATH"), or can be overridden with a custom search
166
- path.
167
-
168
- """
169
- # Check that a given file can be accessed with the correct mode.
170
- # Additionally check that `file` is not a directory, as on Windows
171
- # directories pass the os.access check.
172
- def _access_check(fn, mode):
173
- return (os.path.exists(fn) and os.access(fn, mode)
174
- and not os.path.isdir(fn))
175
-
176
- # If we're given a path with a directory part, look it up directly rather
177
- # than referring to PATH directories. This includes checking relative to the
178
- # current directory, e.g. ./script
179
- if os.path.dirname(cmd):
180
- if _access_check(cmd, mode):
181
- return cmd
182
- return None
183
-
184
- if path is None:
185
- path = os.environ.get("PATH", os.defpath)
186
- if not path:
187
- return None
188
- path = path.split(os.pathsep)
189
-
190
- if sys.platform == "win32":
191
- # The current directory takes precedence on Windows.
192
- if not os.curdir in path:
193
- path.insert(0, os.curdir)
194
-
195
- # PATHEXT is necessary to check on Windows.
196
- pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
197
- # See if the given file matches any of the expected path extensions.
198
- # This will allow us to short circuit when given "python.exe".
199
- # If it does match, only test that one, otherwise we have to try
200
- # others.
201
- if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
202
- files = [cmd]
203
- else:
204
- files = [cmd + ext for ext in pathext]
205
- else:
206
- # On other platforms you don't have things like PATHEXT to tell you
207
- # what file suffixes are executable, so just pass on cmd as-is.
208
- files = [cmd]
209
-
210
- seen = set()
211
- for dir in path:
212
- normdir = os.path.normcase(dir)
213
- if not normdir in seen:
214
- seen.add(normdir)
215
- for thefile in files:
216
- name = os.path.join(dir, thefile)
217
- if _access_check(name, mode):
218
- return name
219
- return None
220
-
221
-
222
- # ZipFile is a context manager in 2.7, but not in 2.6
223
-
224
- from zipfile import ZipFile as BaseZipFile
225
-
226
- if hasattr(BaseZipFile, '__enter__'):
227
- ZipFile = BaseZipFile
228
- else:
229
- from zipfile import ZipExtFile as BaseZipExtFile
230
-
231
- class ZipExtFile(BaseZipExtFile):
232
- def __init__(self, base):
233
- self.__dict__.update(base.__dict__)
234
-
235
- def __enter__(self):
236
- return self
237
-
238
- def __exit__(self, *exc_info):
239
- self.close()
240
- # return None, so if an exception occurred, it will propagate
241
-
242
- class ZipFile(BaseZipFile):
243
- def __enter__(self):
244
- return self
245
-
246
- def __exit__(self, *exc_info):
247
- self.close()
248
- # return None, so if an exception occurred, it will propagate
249
-
250
- def open(self, *args, **kwargs):
251
- base = BaseZipFile.open(self, *args, **kwargs)
252
- return ZipExtFile(base)
253
-
254
- try:
255
- from platform import python_implementation
256
- except ImportError: # pragma: no cover
257
- def python_implementation():
258
- """Return a string identifying the Python implementation."""
259
- if 'PyPy' in sys.version:
260
- return 'PyPy'
261
- if os.name == 'java':
262
- return 'Jython'
263
- if sys.version.startswith('IronPython'):
264
- return 'IronPython'
265
- return 'CPython'
266
-
267
- try:
268
- import sysconfig
269
- except ImportError: # pragma: no cover
270
- from ._backport import sysconfig
271
-
272
- try:
273
- callable = callable
274
- except NameError: # pragma: no cover
275
- from collections import Callable
276
-
277
- def callable(obj):
278
- return isinstance(obj, Callable)
279
-
280
-
281
- try:
282
- fsencode = os.fsencode
283
- fsdecode = os.fsdecode
284
- except AttributeError: # pragma: no cover
285
- _fsencoding = sys.getfilesystemencoding()
286
- if _fsencoding == 'mbcs':
287
- _fserrors = 'strict'
288
- else:
289
- _fserrors = 'surrogateescape'
290
-
291
- def fsencode(filename):
292
- if isinstance(filename, bytes):
293
- return filename
294
- elif isinstance(filename, text_type):
295
- return filename.encode(_fsencoding, _fserrors)
296
- else:
297
- raise TypeError("expect bytes or str, not %s" %
298
- type(filename).__name__)
299
-
300
- def fsdecode(filename):
301
- if isinstance(filename, text_type):
302
- return filename
303
- elif isinstance(filename, bytes):
304
- return filename.decode(_fsencoding, _fserrors)
305
- else:
306
- raise TypeError("expect bytes or str, not %s" %
307
- type(filename).__name__)
308
-
309
- try:
310
- from tokenize import detect_encoding
311
- except ImportError: # pragma: no cover
312
- from codecs import BOM_UTF8, lookup
313
- import re
314
-
315
- cookie_re = re.compile("coding[:=]\s*([-\w.]+)")
316
-
317
- def _get_normal_name(orig_enc):
318
- """Imitates get_normal_name in tokenizer.c."""
319
- # Only care about the first 12 characters.
320
- enc = orig_enc[:12].lower().replace("_", "-")
321
- if enc == "utf-8" or enc.startswith("utf-8-"):
322
- return "utf-8"
323
- if enc in ("latin-1", "iso-8859-1", "iso-latin-1") or \
324
- enc.startswith(("latin-1-", "iso-8859-1-", "iso-latin-1-")):
325
- return "iso-8859-1"
326
- return orig_enc
327
-
328
- def detect_encoding(readline):
329
- """
330
- The detect_encoding() function is used to detect the encoding that should
331
- be used to decode a Python source file. It requires one argment, readline,
332
- in the same way as the tokenize() generator.
333
-
334
- It will call readline a maximum of twice, and return the encoding used
335
- (as a string) and a list of any lines (left as bytes) it has read in.
336
-
337
- It detects the encoding from the presence of a utf-8 bom or an encoding
338
- cookie as specified in pep-0263. If both a bom and a cookie are present,
339
- but disagree, a SyntaxError will be raised. If the encoding cookie is an
340
- invalid charset, raise a SyntaxError. Note that if a utf-8 bom is found,
341
- 'utf-8-sig' is returned.
342
-
343
- If no encoding is specified, then the default of 'utf-8' will be returned.
344
- """
345
- try:
346
- filename = readline.__self__.name
347
- except AttributeError:
348
- filename = None
349
- bom_found = False
350
- encoding = None
351
- default = 'utf-8'
352
- def read_or_stop():
353
- try:
354
- return readline()
355
- except StopIteration:
356
- return b''
357
-
358
- def find_cookie(line):
359
- try:
360
- # Decode as UTF-8. Either the line is an encoding declaration,
361
- # in which case it should be pure ASCII, or it must be UTF-8
362
- # per default encoding.
363
- line_string = line.decode('utf-8')
364
- except UnicodeDecodeError:
365
- msg = "invalid or missing encoding declaration"
366
- if filename is not None:
367
- msg = '{} for {!r}'.format(msg, filename)
368
- raise SyntaxError(msg)
369
-
370
- matches = cookie_re.findall(line_string)
371
- if not matches:
372
- return None
373
- encoding = _get_normal_name(matches[0])
374
- try:
375
- codec = lookup(encoding)
376
- except LookupError:
377
- # This behaviour mimics the Python interpreter
378
- if filename is None:
379
- msg = "unknown encoding: " + encoding
380
- else:
381
- msg = "unknown encoding for {!r}: {}".format(filename,
382
- encoding)
383
- raise SyntaxError(msg)
384
-
385
- if bom_found:
386
- if codec.name != 'utf-8':
387
- # This behaviour mimics the Python interpreter
388
- if filename is None:
389
- msg = 'encoding problem: utf-8'
390
- else:
391
- msg = 'encoding problem for {!r}: utf-8'.format(filename)
392
- raise SyntaxError(msg)
393
- encoding += '-sig'
394
- return encoding
395
-
396
- first = read_or_stop()
397
- if first.startswith(BOM_UTF8):
398
- bom_found = True
399
- first = first[3:]
400
- default = 'utf-8-sig'
401
- if not first:
402
- return default, []
403
-
404
- encoding = find_cookie(first)
405
- if encoding:
406
- return encoding, [first]
407
-
408
- second = read_or_stop()
409
- if not second:
410
- return default, [first]
411
-
412
- encoding = find_cookie(second)
413
- if encoding:
414
- return encoding, [first, second]
415
-
416
- return default, [first, second]
417
-
418
- # For converting & <-> &amp; etc.
419
- try:
420
- from html import escape
421
- except ImportError:
422
- from cgi import escape
423
- if sys.version_info[:2] < (3, 4):
424
- unescape = HTMLParser().unescape
425
- else:
426
- from html import unescape
427
-
428
- try:
429
- from collections import ChainMap
430
- except ImportError: # pragma: no cover
431
- from collections import MutableMapping
432
-
433
- try:
434
- from reprlib import recursive_repr as _recursive_repr
435
- except ImportError:
436
- def _recursive_repr(fillvalue='...'):
437
- '''
438
- Decorator to make a repr function return fillvalue for a recursive
439
- call
440
- '''
441
-
442
- def decorating_function(user_function):
443
- repr_running = set()
444
-
445
- def wrapper(self):
446
- key = id(self), get_ident()
447
- if key in repr_running:
448
- return fillvalue
449
- repr_running.add(key)
450
- try:
451
- result = user_function(self)
452
- finally:
453
- repr_running.discard(key)
454
- return result
455
-
456
- # Can't use functools.wraps() here because of bootstrap issues
457
- wrapper.__module__ = getattr(user_function, '__module__')
458
- wrapper.__doc__ = getattr(user_function, '__doc__')
459
- wrapper.__name__ = getattr(user_function, '__name__')
460
- wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
461
- return wrapper
462
-
463
- return decorating_function
464
-
465
- class ChainMap(MutableMapping):
466
- ''' A ChainMap groups multiple dicts (or other mappings) together
467
- to create a single, updateable view.
468
-
469
- The underlying mappings are stored in a list. That list is public and can
470
- accessed or updated using the *maps* attribute. There is no other state.
471
-
472
- Lookups search the underlying mappings successively until a key is found.
473
- In contrast, writes, updates, and deletions only operate on the first
474
- mapping.
475
-
476
- '''
477
-
478
- def __init__(self, *maps):
479
- '''Initialize a ChainMap by setting *maps* to the given mappings.
480
- If no mappings are provided, a single empty dictionary is used.
481
-
482
- '''
483
- self.maps = list(maps) or [{}] # always at least one map
484
-
485
- def __missing__(self, key):
486
- raise KeyError(key)
487
-
488
- def __getitem__(self, key):
489
- for mapping in self.maps:
490
- try:
491
- return mapping[key] # can't use 'key in mapping' with defaultdict
492
- except KeyError:
493
- pass
494
- return self.__missing__(key) # support subclasses that define __missing__
495
-
496
- def get(self, key, default=None):
497
- return self[key] if key in self else default
498
-
499
- def __len__(self):
500
- return len(set().union(*self.maps)) # reuses stored hash values if possible
501
-
502
- def __iter__(self):
503
- return iter(set().union(*self.maps))
504
-
505
- def __contains__(self, key):
506
- return any(key in m for m in self.maps)
507
-
508
- def __bool__(self):
509
- return any(self.maps)
510
-
511
- @_recursive_repr()
512
- def __repr__(self):
513
- return '{0.__class__.__name__}({1})'.format(
514
- self, ', '.join(map(repr, self.maps)))
515
-
516
- @classmethod
517
- def fromkeys(cls, iterable, *args):
518
- 'Create a ChainMap with a single dict created from the iterable.'
519
- return cls(dict.fromkeys(iterable, *args))
520
-
521
- def copy(self):
522
- 'New ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]'
523
- return self.__class__(self.maps[0].copy(), *self.maps[1:])
524
-
525
- __copy__ = copy
526
-
527
- def new_child(self): # like Django's Context.push()
528
- 'New ChainMap with a new dict followed by all previous maps.'
529
- return self.__class__({}, *self.maps)
530
-
531
- @property
532
- def parents(self): # like Django's Context.pop()
533
- 'New ChainMap from maps[1:].'
534
- return self.__class__(*self.maps[1:])
535
-
536
- def __setitem__(self, key, value):
537
- self.maps[0][key] = value
538
-
539
- def __delitem__(self, key):
540
- try:
541
- del self.maps[0][key]
542
- except KeyError:
543
- raise KeyError('Key not found in the first mapping: {!r}'.format(key))
544
-
545
- def popitem(self):
546
- 'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.'
547
- try:
548
- return self.maps[0].popitem()
549
- except KeyError:
550
- raise KeyError('No keys found in the first mapping.')
551
-
552
- def pop(self, key, *args):
553
- 'Remove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].'
554
- try:
555
- return self.maps[0].pop(key, *args)
556
- except KeyError:
557
- raise KeyError('Key not found in the first mapping: {!r}'.format(key))
558
-
559
- def clear(self):
560
- 'Clear maps[0], leaving maps[1:] intact.'
561
- self.maps[0].clear()
562
-
563
- try:
564
- from imp import cache_from_source
565
- except ImportError: # pragma: no cover
566
- def cache_from_source(path, debug_override=None):
567
- assert path.endswith('.py')
568
- if debug_override is None:
569
- debug_override = __debug__
570
- if debug_override:
571
- suffix = 'c'
572
- else:
573
- suffix = 'o'
574
- return path + suffix
575
-
576
- try:
577
- from collections import OrderedDict
578
- except ImportError: # pragma: no cover
579
- ## {{{ http://code.activestate.com/recipes/576693/ (r9)
580
- # Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy.
581
- # Passes Python2.7's test suite and incorporates all the latest updates.
582
- try:
583
- from thread import get_ident as _get_ident
584
- except ImportError:
585
- from dummy_thread import get_ident as _get_ident
586
-
587
- try:
588
- from _abcoll import KeysView, ValuesView, ItemsView
589
- except ImportError:
590
- pass
591
-
592
-
593
- class OrderedDict(dict):
594
- 'Dictionary that remembers insertion order'
595
- # An inherited dict maps keys to values.
596
- # The inherited dict provides __getitem__, __len__, __contains__, and get.
597
- # The remaining methods are order-aware.
598
- # Big-O running times for all methods are the same as for regular dictionaries.
599
-
600
- # The internal self.__map dictionary maps keys to links in a doubly linked list.
601
- # The circular doubly linked list starts and ends with a sentinel element.
602
- # The sentinel element never gets deleted (this simplifies the algorithm).
603
- # Each link is stored as a list of length three: [PREV, NEXT, KEY].
604
-
605
- def __init__(self, *args, **kwds):
606
- '''Initialize an ordered dictionary. Signature is the same as for
607
- regular dictionaries, but keyword arguments are not recommended
608
- because their insertion order is arbitrary.
609
-
610
- '''
611
- if len(args) > 1:
612
- raise TypeError('expected at most 1 arguments, got %d' % len(args))
613
- try:
614
- self.__root
615
- except AttributeError:
616
- self.__root = root = [] # sentinel node
617
- root[:] = [root, root, None]
618
- self.__map = {}
619
- self.__update(*args, **kwds)
620
-
621
- def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
622
- 'od.__setitem__(i, y) <==> od[i]=y'
623
- # Setting a new item creates a new link which goes at the end of the linked
624
- # list, and the inherited dictionary is updated with the new key/value pair.
625
- if key not in self:
626
- root = self.__root
627
- last = root[0]
628
- last[1] = root[0] = self.__map[key] = [last, root, key]
629
- dict_setitem(self, key, value)
630
-
631
- def __delitem__(self, key, dict_delitem=dict.__delitem__):
632
- 'od.__delitem__(y) <==> del od[y]'
633
- # Deleting an existing item uses self.__map to find the link which is
634
- # then removed by updating the links in the predecessor and successor nodes.
635
- dict_delitem(self, key)
636
- link_prev, link_next, key = self.__map.pop(key)
637
- link_prev[1] = link_next
638
- link_next[0] = link_prev
639
-
640
- def __iter__(self):
641
- 'od.__iter__() <==> iter(od)'
642
- root = self.__root
643
- curr = root[1]
644
- while curr is not root:
645
- yield curr[2]
646
- curr = curr[1]
647
-
648
- def __reversed__(self):
649
- 'od.__reversed__() <==> reversed(od)'
650
- root = self.__root
651
- curr = root[0]
652
- while curr is not root:
653
- yield curr[2]
654
- curr = curr[0]
655
-
656
- def clear(self):
657
- 'od.clear() -> None. Remove all items from od.'
658
- try:
659
- for node in self.__map.itervalues():
660
- del node[:]
661
- root = self.__root
662
- root[:] = [root, root, None]
663
- self.__map.clear()
664
- except AttributeError:
665
- pass
666
- dict.clear(self)
667
-
668
- def popitem(self, last=True):
669
- '''od.popitem() -> (k, v), return and remove a (key, value) pair.
670
- Pairs are returned in LIFO order if last is true or FIFO order if false.
671
-
672
- '''
673
- if not self:
674
- raise KeyError('dictionary is empty')
675
- root = self.__root
676
- if last:
677
- link = root[0]
678
- link_prev = link[0]
679
- link_prev[1] = root
680
- root[0] = link_prev
681
- else:
682
- link = root[1]
683
- link_next = link[1]
684
- root[1] = link_next
685
- link_next[0] = root
686
- key = link[2]
687
- del self.__map[key]
688
- value = dict.pop(self, key)
689
- return key, value
690
-
691
- # -- the following methods do not depend on the internal structure --
692
-
693
- def keys(self):
694
- 'od.keys() -> list of keys in od'
695
- return list(self)
696
-
697
- def values(self):
698
- 'od.values() -> list of values in od'
699
- return [self[key] for key in self]
700
-
701
- def items(self):
702
- 'od.items() -> list of (key, value) pairs in od'
703
- return [(key, self[key]) for key in self]
704
-
705
- def iterkeys(self):
706
- 'od.iterkeys() -> an iterator over the keys in od'
707
- return iter(self)
708
-
709
- def itervalues(self):
710
- 'od.itervalues -> an iterator over the values in od'
711
- for k in self:
712
- yield self[k]
713
-
714
- def iteritems(self):
715
- 'od.iteritems -> an iterator over the (key, value) items in od'
716
- for k in self:
717
- yield (k, self[k])
718
-
719
- def update(*args, **kwds):
720
- '''od.update(E, **F) -> None. Update od from dict/iterable E and F.
721
-
722
- If E is a dict instance, does: for k in E: od[k] = E[k]
723
- If E has a .keys() method, does: for k in E.keys(): od[k] = E[k]
724
- Or if E is an iterable of items, does: for k, v in E: od[k] = v
725
- In either case, this is followed by: for k, v in F.items(): od[k] = v
726
-
727
- '''
728
- if len(args) > 2:
729
- raise TypeError('update() takes at most 2 positional '
730
- 'arguments (%d given)' % (len(args),))
731
- elif not args:
732
- raise TypeError('update() takes at least 1 argument (0 given)')
733
- self = args[0]
734
- # Make progressively weaker assumptions about "other"
735
- other = ()
736
- if len(args) == 2:
737
- other = args[1]
738
- if isinstance(other, dict):
739
- for key in other:
740
- self[key] = other[key]
741
- elif hasattr(other, 'keys'):
742
- for key in other.keys():
743
- self[key] = other[key]
744
- else:
745
- for key, value in other:
746
- self[key] = value
747
- for key, value in kwds.items():
748
- self[key] = value
749
-
750
- __update = update # let subclasses override update without breaking __init__
751
-
752
- __marker = object()
753
-
754
- def pop(self, key, default=__marker):
755
- '''od.pop(k[,d]) -> v, remove specified key and return the corresponding value.
756
- If key is not found, d is returned if given, otherwise KeyError is raised.
757
-
758
- '''
759
- if key in self:
760
- result = self[key]
761
- del self[key]
762
- return result
763
- if default is self.__marker:
764
- raise KeyError(key)
765
- return default
766
-
767
- def setdefault(self, key, default=None):
768
- 'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
769
- if key in self:
770
- return self[key]
771
- self[key] = default
772
- return default
773
-
774
- def __repr__(self, _repr_running=None):
775
- 'od.__repr__() <==> repr(od)'
776
- if not _repr_running: _repr_running = {}
777
- call_key = id(self), _get_ident()
778
- if call_key in _repr_running:
779
- return '...'
780
- _repr_running[call_key] = 1
781
- try:
782
- if not self:
783
- return '%s()' % (self.__class__.__name__,)
784
- return '%s(%r)' % (self.__class__.__name__, self.items())
785
- finally:
786
- del _repr_running[call_key]
787
-
788
- def __reduce__(self):
789
- 'Return state information for pickling'
790
- items = [[k, self[k]] for k in self]
791
- inst_dict = vars(self).copy()
792
- for k in vars(OrderedDict()):
793
- inst_dict.pop(k, None)
794
- if inst_dict:
795
- return (self.__class__, (items,), inst_dict)
796
- return self.__class__, (items,)
797
-
798
- def copy(self):
799
- 'od.copy() -> a shallow copy of od'
800
- return self.__class__(self)
801
-
802
- @classmethod
803
- def fromkeys(cls, iterable, value=None):
804
- '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
805
- and values equal to v (which defaults to None).
806
-
807
- '''
808
- d = cls()
809
- for key in iterable:
810
- d[key] = value
811
- return d
812
-
813
- def __eq__(self, other):
814
- '''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive
815
- while comparison to a regular mapping is order-insensitive.
816
-
817
- '''
818
- if isinstance(other, OrderedDict):
819
- return len(self)==len(other) and self.items() == other.items()
820
- return dict.__eq__(self, other)
821
-
822
- def __ne__(self, other):
823
- return not self == other
824
-
825
- # -- the following methods are only used in Python 2.7 --
826
-
827
- def viewkeys(self):
828
- "od.viewkeys() -> a set-like object providing a view on od's keys"
829
- return KeysView(self)
830
-
831
- def viewvalues(self):
832
- "od.viewvalues() -> an object providing a view on od's values"
833
- return ValuesView(self)
834
-
835
- def viewitems(self):
836
- "od.viewitems() -> a set-like object providing a view on od's items"
837
- return ItemsView(self)
838
-
839
- try:
840
- from logging.config import BaseConfigurator, valid_ident
841
- except ImportError: # pragma: no cover
842
- IDENTIFIER = re.compile('^[a-z_][a-z0-9_]*$', re.I)
843
-
844
-
845
- def valid_ident(s):
846
- m = IDENTIFIER.match(s)
847
- if not m:
848
- raise ValueError('Not a valid Python identifier: %r' % s)
849
- return True
850
-
851
-
852
- # The ConvertingXXX classes are wrappers around standard Python containers,
853
- # and they serve to convert any suitable values in the container. The
854
- # conversion converts base dicts, lists and tuples to their wrapped
855
- # equivalents, whereas strings which match a conversion format are converted
856
- # appropriately.
857
- #
858
- # Each wrapper should have a configurator attribute holding the actual
859
- # configurator to use for conversion.
860
-
861
- class ConvertingDict(dict):
862
- """A converting dictionary wrapper."""
863
-
864
- def __getitem__(self, key):
865
- value = dict.__getitem__(self, key)
866
- result = self.configurator.convert(value)
867
- #If the converted value is different, save for next time
868
- if value is not result:
869
- self[key] = result
870
- if type(result) in (ConvertingDict, ConvertingList,
871
- ConvertingTuple):
872
- result.parent = self
873
- result.key = key
874
- return result
875
-
876
- def get(self, key, default=None):
877
- value = dict.get(self, key, default)
878
- result = self.configurator.convert(value)
879
- #If the converted value is different, save for next time
880
- if value is not result:
881
- self[key] = result
882
- if type(result) in (ConvertingDict, ConvertingList,
883
- ConvertingTuple):
884
- result.parent = self
885
- result.key = key
886
- return result
887
-
888
- def pop(self, key, default=None):
889
- value = dict.pop(self, key, default)
890
- result = self.configurator.convert(value)
891
- if value is not result:
892
- if type(result) in (ConvertingDict, ConvertingList,
893
- ConvertingTuple):
894
- result.parent = self
895
- result.key = key
896
- return result
897
-
898
- class ConvertingList(list):
899
- """A converting list wrapper."""
900
- def __getitem__(self, key):
901
- value = list.__getitem__(self, key)
902
- result = self.configurator.convert(value)
903
- #If the converted value is different, save for next time
904
- if value is not result:
905
- self[key] = result
906
- if type(result) in (ConvertingDict, ConvertingList,
907
- ConvertingTuple):
908
- result.parent = self
909
- result.key = key
910
- return result
911
-
912
- def pop(self, idx=-1):
913
- value = list.pop(self, idx)
914
- result = self.configurator.convert(value)
915
- if value is not result:
916
- if type(result) in (ConvertingDict, ConvertingList,
917
- ConvertingTuple):
918
- result.parent = self
919
- return result
920
-
921
- class ConvertingTuple(tuple):
922
- """A converting tuple wrapper."""
923
- def __getitem__(self, key):
924
- value = tuple.__getitem__(self, key)
925
- result = self.configurator.convert(value)
926
- if value is not result:
927
- if type(result) in (ConvertingDict, ConvertingList,
928
- ConvertingTuple):
929
- result.parent = self
930
- result.key = key
931
- return result
932
-
933
- class BaseConfigurator(object):
934
- """
935
- The configurator base class which defines some useful defaults.
936
- """
937
-
938
- CONVERT_PATTERN = re.compile(r'^(?P<prefix>[a-z]+)://(?P<suffix>.*)$')
939
-
940
- WORD_PATTERN = re.compile(r'^\s*(\w+)\s*')
941
- DOT_PATTERN = re.compile(r'^\.\s*(\w+)\s*')
942
- INDEX_PATTERN = re.compile(r'^\[\s*(\w+)\s*\]\s*')
943
- DIGIT_PATTERN = re.compile(r'^\d+$')
944
-
945
- value_converters = {
946
- 'ext' : 'ext_convert',
947
- 'cfg' : 'cfg_convert',
948
- }
949
-
950
- # We might want to use a different one, e.g. importlib
951
- importer = staticmethod(__import__)
952
-
953
- def __init__(self, config):
954
- self.config = ConvertingDict(config)
955
- self.config.configurator = self
956
-
957
- def resolve(self, s):
958
- """
959
- Resolve strings to objects using standard import and attribute
960
- syntax.
961
- """
962
- name = s.split('.')
963
- used = name.pop(0)
964
- try:
965
- found = self.importer(used)
966
- for frag in name:
967
- used += '.' + frag
968
- try:
969
- found = getattr(found, frag)
970
- except AttributeError:
971
- self.importer(used)
972
- found = getattr(found, frag)
973
- return found
974
- except ImportError:
975
- e, tb = sys.exc_info()[1:]
976
- v = ValueError('Cannot resolve %r: %s' % (s, e))
977
- v.__cause__, v.__traceback__ = e, tb
978
- raise v
979
-
980
- def ext_convert(self, value):
981
- """Default converter for the ext:// protocol."""
982
- return self.resolve(value)
983
-
984
- def cfg_convert(self, value):
985
- """Default converter for the cfg:// protocol."""
986
- rest = value
987
- m = self.WORD_PATTERN.match(rest)
988
- if m is None:
989
- raise ValueError("Unable to convert %r" % value)
990
- else:
991
- rest = rest[m.end():]
992
- d = self.config[m.groups()[0]]
993
- #print d, rest
994
- while rest:
995
- m = self.DOT_PATTERN.match(rest)
996
- if m:
997
- d = d[m.groups()[0]]
998
- else:
999
- m = self.INDEX_PATTERN.match(rest)
1000
- if m:
1001
- idx = m.groups()[0]
1002
- if not self.DIGIT_PATTERN.match(idx):
1003
- d = d[idx]
1004
- else:
1005
- try:
1006
- n = int(idx) # try as number first (most likely)
1007
- d = d[n]
1008
- except TypeError:
1009
- d = d[idx]
1010
- if m:
1011
- rest = rest[m.end():]
1012
- else:
1013
- raise ValueError('Unable to convert '
1014
- '%r at %r' % (value, rest))
1015
- #rest should be empty
1016
- return d
1017
-
1018
- def convert(self, value):
1019
- """
1020
- Convert values to an appropriate type. dicts, lists and tuples are
1021
- replaced by their converting alternatives. Strings are checked to
1022
- see if they have a conversion format and are converted if they do.
1023
- """
1024
- if not isinstance(value, ConvertingDict) and isinstance(value, dict):
1025
- value = ConvertingDict(value)
1026
- value.configurator = self
1027
- elif not isinstance(value, ConvertingList) and isinstance(value, list):
1028
- value = ConvertingList(value)
1029
- value.configurator = self
1030
- elif not isinstance(value, ConvertingTuple) and\
1031
- isinstance(value, tuple):
1032
- value = ConvertingTuple(value)
1033
- value.configurator = self
1034
- elif isinstance(value, string_types):
1035
- m = self.CONVERT_PATTERN.match(value)
1036
- if m:
1037
- d = m.groupdict()
1038
- prefix = d['prefix']
1039
- converter = self.value_converters.get(prefix, None)
1040
- if converter:
1041
- suffix = d['suffix']
1042
- converter = getattr(self, converter)
1043
- value = converter(suffix)
1044
- return value
1045
-
1046
- def configure_custom(self, config):
1047
- """Configure an object with a user-supplied factory."""
1048
- c = config.pop('()')
1049
- if not callable(c):
1050
- c = self.resolve(c)
1051
- props = config.pop('.', None)
1052
- # Check for valid identifiers
1053
- kwargs = dict([(k, config[k]) for k in config if valid_ident(k)])
1054
- result = c(**kwargs)
1055
- if props:
1056
- for name, value in props.items():
1057
- setattr(result, name, value)
1058
- return result
1059
-
1060
- def as_tuple(self, value):
1061
- """Utility function which converts lists to tuples."""
1062
- if isinstance(value, list):
1063
- value = tuple(value)
1064
- return value
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013-2017 Vinay Sajip.
4
+ # Licensed to the Python Software Foundation under a contributor agreement.
5
+ # See LICENSE.txt and CONTRIBUTORS.txt.
6
+ #
7
+ from __future__ import absolute_import
8
+
9
+ import os
10
+ import re
11
+ import sys
12
+
13
+ try:
14
+ import ssl
15
+ except ImportError: # pragma: no cover
16
+ ssl = None
17
+
18
+ if sys.version_info[0] < 3: # pragma: no cover
19
+ from StringIO import StringIO
20
+ string_types = basestring,
21
+ text_type = unicode
22
+ from types import FileType as file_type
23
+ import __builtin__ as builtins
24
+ import ConfigParser as configparser
25
+ from ._backport import shutil
26
+ from urlparse import urlparse, urlunparse, urljoin, urlsplit, urlunsplit
27
+ from urllib import (urlretrieve, quote as _quote, unquote, url2pathname,
28
+ pathname2url, ContentTooShortError, splittype)
29
+
30
+ def quote(s):
31
+ if isinstance(s, unicode):
32
+ s = s.encode('utf-8')
33
+ return _quote(s)
34
+
35
+ import urllib2
36
+ from urllib2 import (Request, urlopen, URLError, HTTPError,
37
+ HTTPBasicAuthHandler, HTTPPasswordMgr,
38
+ HTTPHandler, HTTPRedirectHandler,
39
+ build_opener)
40
+ if ssl:
41
+ from urllib2 import HTTPSHandler
42
+ import httplib
43
+ import xmlrpclib
44
+ import Queue as queue
45
+ from HTMLParser import HTMLParser
46
+ import htmlentitydefs
47
+ raw_input = raw_input
48
+ from itertools import ifilter as filter
49
+ from itertools import ifilterfalse as filterfalse
50
+
51
+ _userprog = None
52
+ def splituser(host):
53
+ """splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'."""
54
+ global _userprog
55
+ if _userprog is None:
56
+ import re
57
+ _userprog = re.compile('^(.*)@(.*)$')
58
+
59
+ match = _userprog.match(host)
60
+ if match: return match.group(1, 2)
61
+ return None, host
62
+
63
+ else: # pragma: no cover
64
+ from io import StringIO
65
+ string_types = str,
66
+ text_type = str
67
+ from io import TextIOWrapper as file_type
68
+ import builtins
69
+ import configparser
70
+ import shutil
71
+ from urllib.parse import (urlparse, urlunparse, urljoin, splituser, quote,
72
+ unquote, urlsplit, urlunsplit, splittype)
73
+ from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
74
+ pathname2url,
75
+ HTTPBasicAuthHandler, HTTPPasswordMgr,
76
+ HTTPHandler, HTTPRedirectHandler,
77
+ build_opener)
78
+ if ssl:
79
+ from urllib.request import HTTPSHandler
80
+ from urllib.error import HTTPError, URLError, ContentTooShortError
81
+ import http.client as httplib
82
+ import urllib.request as urllib2
83
+ import xmlrpc.client as xmlrpclib
84
+ import queue
85
+ from html.parser import HTMLParser
86
+ import html.entities as htmlentitydefs
87
+ raw_input = input
88
+ from itertools import filterfalse
89
+ filter = filter
90
+
91
+ try:
92
+ from ssl import match_hostname, CertificateError
93
+ except ImportError: # pragma: no cover
94
+ class CertificateError(ValueError):
95
+ pass
96
+
97
+
98
+ def _dnsname_match(dn, hostname, max_wildcards=1):
99
+ """Matching according to RFC 6125, section 6.4.3
100
+
101
+ http://tools.ietf.org/html/rfc6125#section-6.4.3
102
+ """
103
+ pats = []
104
+ if not dn:
105
+ return False
106
+
107
+ parts = dn.split('.')
108
+ leftmost, remainder = parts[0], parts[1:]
109
+
110
+ wildcards = leftmost.count('*')
111
+ if wildcards > max_wildcards:
112
+ # Issue #17980: avoid denials of service by refusing more
113
+ # than one wildcard per fragment. A survey of established
114
+ # policy among SSL implementations showed it to be a
115
+ # reasonable choice.
116
+ raise CertificateError(
117
+ "too many wildcards in certificate DNS name: " + repr(dn))
118
+
119
+ # speed up common case w/o wildcards
120
+ if not wildcards:
121
+ return dn.lower() == hostname.lower()
122
+
123
+ # RFC 6125, section 6.4.3, subitem 1.
124
+ # The client SHOULD NOT attempt to match a presented identifier in which
125
+ # the wildcard character comprises a label other than the left-most label.
126
+ if leftmost == '*':
127
+ # When '*' is a fragment by itself, it matches a non-empty dotless
128
+ # fragment.
129
+ pats.append('[^.]+')
130
+ elif leftmost.startswith('xn--') or hostname.startswith('xn--'):
131
+ # RFC 6125, section 6.4.3, subitem 3.
132
+ # The client SHOULD NOT attempt to match a presented identifier
133
+ # where the wildcard character is embedded within an A-label or
134
+ # U-label of an internationalized domain name.
135
+ pats.append(re.escape(leftmost))
136
+ else:
137
+ # Otherwise, '*' matches any dotless string, e.g. www*
138
+ pats.append(re.escape(leftmost).replace(r'\*', '[^.]*'))
139
+
140
+ # add the remaining fragments, ignore any wildcards
141
+ for frag in remainder:
142
+ pats.append(re.escape(frag))
143
+
144
+ pat = re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
145
+ return pat.match(hostname)
146
+
147
+
148
+ def match_hostname(cert, hostname):
149
+ """Verify that *cert* (in decoded format as returned by
150
+ SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125
151
+ rules are followed, but IP addresses are not accepted for *hostname*.
152
+
153
+ CertificateError is raised on failure. On success, the function
154
+ returns nothing.
155
+ """
156
+ if not cert:
157
+ raise ValueError("empty or no certificate, match_hostname needs a "
158
+ "SSL socket or SSL context with either "
159
+ "CERT_OPTIONAL or CERT_REQUIRED")
160
+ dnsnames = []
161
+ san = cert.get('subjectAltName', ())
162
+ for key, value in san:
163
+ if key == 'DNS':
164
+ if _dnsname_match(value, hostname):
165
+ return
166
+ dnsnames.append(value)
167
+ if not dnsnames:
168
+ # The subject is only checked when there is no dNSName entry
169
+ # in subjectAltName
170
+ for sub in cert.get('subject', ()):
171
+ for key, value in sub:
172
+ # XXX according to RFC 2818, the most specific Common Name
173
+ # must be used.
174
+ if key == 'commonName':
175
+ if _dnsname_match(value, hostname):
176
+ return
177
+ dnsnames.append(value)
178
+ if len(dnsnames) > 1:
179
+ raise CertificateError("hostname %r "
180
+ "doesn't match either of %s"
181
+ % (hostname, ', '.join(map(repr, dnsnames))))
182
+ elif len(dnsnames) == 1:
183
+ raise CertificateError("hostname %r "
184
+ "doesn't match %r"
185
+ % (hostname, dnsnames[0]))
186
+ else:
187
+ raise CertificateError("no appropriate commonName or "
188
+ "subjectAltName fields were found")
189
+
190
+
191
+ try:
192
+ from types import SimpleNamespace as Container
193
+ except ImportError: # pragma: no cover
194
+ class Container(object):
195
+ """
196
+ A generic container for when multiple values need to be returned
197
+ """
198
+ def __init__(self, **kwargs):
199
+ self.__dict__.update(kwargs)
200
+
201
+
202
+ try:
203
+ from shutil import which
204
+ except ImportError: # pragma: no cover
205
+ # Implementation from Python 3.3
206
+ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
207
+ """Given a command, mode, and a PATH string, return the path which
208
+ conforms to the given mode on the PATH, or None if there is no such
209
+ file.
210
+
211
+ `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
212
+ of os.environ.get("PATH"), or can be overridden with a custom search
213
+ path.
214
+
215
+ """
216
+ # Check that a given file can be accessed with the correct mode.
217
+ # Additionally check that `file` is not a directory, as on Windows
218
+ # directories pass the os.access check.
219
+ def _access_check(fn, mode):
220
+ return (os.path.exists(fn) and os.access(fn, mode)
221
+ and not os.path.isdir(fn))
222
+
223
+ # If we're given a path with a directory part, look it up directly rather
224
+ # than referring to PATH directories. This includes checking relative to the
225
+ # current directory, e.g. ./script
226
+ if os.path.dirname(cmd):
227
+ if _access_check(cmd, mode):
228
+ return cmd
229
+ return None
230
+
231
+ if path is None:
232
+ path = os.environ.get("PATH", os.defpath)
233
+ if not path:
234
+ return None
235
+ path = path.split(os.pathsep)
236
+
237
+ if sys.platform == "win32":
238
+ # The current directory takes precedence on Windows.
239
+ if not os.curdir in path:
240
+ path.insert(0, os.curdir)
241
+
242
+ # PATHEXT is necessary to check on Windows.
243
+ pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
244
+ # See if the given file matches any of the expected path extensions.
245
+ # This will allow us to short circuit when given "python.exe".
246
+ # If it does match, only test that one, otherwise we have to try
247
+ # others.
248
+ if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
249
+ files = [cmd]
250
+ else:
251
+ files = [cmd + ext for ext in pathext]
252
+ else:
253
+ # On other platforms you don't have things like PATHEXT to tell you
254
+ # what file suffixes are executable, so just pass on cmd as-is.
255
+ files = [cmd]
256
+
257
+ seen = set()
258
+ for dir in path:
259
+ normdir = os.path.normcase(dir)
260
+ if not normdir in seen:
261
+ seen.add(normdir)
262
+ for thefile in files:
263
+ name = os.path.join(dir, thefile)
264
+ if _access_check(name, mode):
265
+ return name
266
+ return None
267
+
268
+
269
+ # ZipFile is a context manager in 2.7, but not in 2.6
270
+
271
+ from zipfile import ZipFile as BaseZipFile
272
+
273
+ if hasattr(BaseZipFile, '__enter__'): # pragma: no cover
274
+ ZipFile = BaseZipFile
275
+ else: # pragma: no cover
276
+ from zipfile import ZipExtFile as BaseZipExtFile
277
+
278
+ class ZipExtFile(BaseZipExtFile):
279
+ def __init__(self, base):
280
+ self.__dict__.update(base.__dict__)
281
+
282
+ def __enter__(self):
283
+ return self
284
+
285
+ def __exit__(self, *exc_info):
286
+ self.close()
287
+ # return None, so if an exception occurred, it will propagate
288
+
289
+ class ZipFile(BaseZipFile):
290
+ def __enter__(self):
291
+ return self
292
+
293
+ def __exit__(self, *exc_info):
294
+ self.close()
295
+ # return None, so if an exception occurred, it will propagate
296
+
297
+ def open(self, *args, **kwargs):
298
+ base = BaseZipFile.open(self, *args, **kwargs)
299
+ return ZipExtFile(base)
300
+
301
+ try:
302
+ from platform import python_implementation
303
+ except ImportError: # pragma: no cover
304
+ def python_implementation():
305
+ """Return a string identifying the Python implementation."""
306
+ if 'PyPy' in sys.version:
307
+ return 'PyPy'
308
+ if os.name == 'java':
309
+ return 'Jython'
310
+ if sys.version.startswith('IronPython'):
311
+ return 'IronPython'
312
+ return 'CPython'
313
+
314
+ try:
315
+ import sysconfig
316
+ except ImportError: # pragma: no cover
317
+ from ._backport import sysconfig
318
+
319
+ try:
320
+ callable = callable
321
+ except NameError: # pragma: no cover
322
+ from collections import Callable
323
+
324
+ def callable(obj):
325
+ return isinstance(obj, Callable)
326
+
327
+
328
+ try:
329
+ fsencode = os.fsencode
330
+ fsdecode = os.fsdecode
331
+ except AttributeError: # pragma: no cover
332
+ # Issue #99: on some systems (e.g. containerised),
333
+ # sys.getfilesystemencoding() returns None, and we need a real value,
334
+ # so fall back to utf-8. From the CPython 2.7 docs relating to Unix and
335
+ # sys.getfilesystemencoding(): the return value is "the user’s preference
336
+ # according to the result of nl_langinfo(CODESET), or None if the
337
+ # nl_langinfo(CODESET) failed."
338
+ _fsencoding = sys.getfilesystemencoding() or 'utf-8'
339
+ if _fsencoding == 'mbcs':
340
+ _fserrors = 'strict'
341
+ else:
342
+ _fserrors = 'surrogateescape'
343
+
344
+ def fsencode(filename):
345
+ if isinstance(filename, bytes):
346
+ return filename
347
+ elif isinstance(filename, text_type):
348
+ return filename.encode(_fsencoding, _fserrors)
349
+ else:
350
+ raise TypeError("expect bytes or str, not %s" %
351
+ type(filename).__name__)
352
+
353
+ def fsdecode(filename):
354
+ if isinstance(filename, text_type):
355
+ return filename
356
+ elif isinstance(filename, bytes):
357
+ return filename.decode(_fsencoding, _fserrors)
358
+ else:
359
+ raise TypeError("expect bytes or str, not %s" %
360
+ type(filename).__name__)
361
+
362
+ try:
363
+ from tokenize import detect_encoding
364
+ except ImportError: # pragma: no cover
365
+ from codecs import BOM_UTF8, lookup
366
+ import re
367
+
368
+ cookie_re = re.compile(r"coding[:=]\s*([-\w.]+)")
369
+
370
+ def _get_normal_name(orig_enc):
371
+ """Imitates get_normal_name in tokenizer.c."""
372
+ # Only care about the first 12 characters.
373
+ enc = orig_enc[:12].lower().replace("_", "-")
374
+ if enc == "utf-8" or enc.startswith("utf-8-"):
375
+ return "utf-8"
376
+ if enc in ("latin-1", "iso-8859-1", "iso-latin-1") or \
377
+ enc.startswith(("latin-1-", "iso-8859-1-", "iso-latin-1-")):
378
+ return "iso-8859-1"
379
+ return orig_enc
380
+
381
+ def detect_encoding(readline):
382
+ """
383
+ The detect_encoding() function is used to detect the encoding that should
384
+ be used to decode a Python source file. It requires one argument, readline,
385
+ in the same way as the tokenize() generator.
386
+
387
+ It will call readline a maximum of twice, and return the encoding used
388
+ (as a string) and a list of any lines (left as bytes) it has read in.
389
+
390
+ It detects the encoding from the presence of a utf-8 bom or an encoding
391
+ cookie as specified in pep-0263. If both a bom and a cookie are present,
392
+ but disagree, a SyntaxError will be raised. If the encoding cookie is an
393
+ invalid charset, raise a SyntaxError. Note that if a utf-8 bom is found,
394
+ 'utf-8-sig' is returned.
395
+
396
+ If no encoding is specified, then the default of 'utf-8' will be returned.
397
+ """
398
+ try:
399
+ filename = readline.__self__.name
400
+ except AttributeError:
401
+ filename = None
402
+ bom_found = False
403
+ encoding = None
404
+ default = 'utf-8'
405
+ def read_or_stop():
406
+ try:
407
+ return readline()
408
+ except StopIteration:
409
+ return b''
410
+
411
+ def find_cookie(line):
412
+ try:
413
+ # Decode as UTF-8. Either the line is an encoding declaration,
414
+ # in which case it should be pure ASCII, or it must be UTF-8
415
+ # per default encoding.
416
+ line_string = line.decode('utf-8')
417
+ except UnicodeDecodeError:
418
+ msg = "invalid or missing encoding declaration"
419
+ if filename is not None:
420
+ msg = '{} for {!r}'.format(msg, filename)
421
+ raise SyntaxError(msg)
422
+
423
+ matches = cookie_re.findall(line_string)
424
+ if not matches:
425
+ return None
426
+ encoding = _get_normal_name(matches[0])
427
+ try:
428
+ codec = lookup(encoding)
429
+ except LookupError:
430
+ # This behaviour mimics the Python interpreter
431
+ if filename is None:
432
+ msg = "unknown encoding: " + encoding
433
+ else:
434
+ msg = "unknown encoding for {!r}: {}".format(filename,
435
+ encoding)
436
+ raise SyntaxError(msg)
437
+
438
+ if bom_found:
439
+ if codec.name != 'utf-8':
440
+ # This behaviour mimics the Python interpreter
441
+ if filename is None:
442
+ msg = 'encoding problem: utf-8'
443
+ else:
444
+ msg = 'encoding problem for {!r}: utf-8'.format(filename)
445
+ raise SyntaxError(msg)
446
+ encoding += '-sig'
447
+ return encoding
448
+
449
+ first = read_or_stop()
450
+ if first.startswith(BOM_UTF8):
451
+ bom_found = True
452
+ first = first[3:]
453
+ default = 'utf-8-sig'
454
+ if not first:
455
+ return default, []
456
+
457
+ encoding = find_cookie(first)
458
+ if encoding:
459
+ return encoding, [first]
460
+
461
+ second = read_or_stop()
462
+ if not second:
463
+ return default, [first]
464
+
465
+ encoding = find_cookie(second)
466
+ if encoding:
467
+ return encoding, [first, second]
468
+
469
+ return default, [first, second]
470
+
471
+ # For converting & <-> &amp; etc.
472
+ try:
473
+ from html import escape
474
+ except ImportError:
475
+ from cgi import escape
476
+ if sys.version_info[:2] < (3, 4):
477
+ unescape = HTMLParser().unescape
478
+ else:
479
+ from html import unescape
480
+
481
+ try:
482
+ from collections import ChainMap
483
+ except ImportError: # pragma: no cover
484
+ from collections import MutableMapping
485
+
486
+ try:
487
+ from reprlib import recursive_repr as _recursive_repr
488
+ except ImportError:
489
+ def _recursive_repr(fillvalue='...'):
490
+ '''
491
+ Decorator to make a repr function return fillvalue for a recursive
492
+ call
493
+ '''
494
+
495
+ def decorating_function(user_function):
496
+ repr_running = set()
497
+
498
+ def wrapper(self):
499
+ key = id(self), get_ident()
500
+ if key in repr_running:
501
+ return fillvalue
502
+ repr_running.add(key)
503
+ try:
504
+ result = user_function(self)
505
+ finally:
506
+ repr_running.discard(key)
507
+ return result
508
+
509
+ # Can't use functools.wraps() here because of bootstrap issues
510
+ wrapper.__module__ = getattr(user_function, '__module__')
511
+ wrapper.__doc__ = getattr(user_function, '__doc__')
512
+ wrapper.__name__ = getattr(user_function, '__name__')
513
+ wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
514
+ return wrapper
515
+
516
+ return decorating_function
517
+
518
+ class ChainMap(MutableMapping):
519
+ ''' A ChainMap groups multiple dicts (or other mappings) together
520
+ to create a single, updateable view.
521
+
522
+ The underlying mappings are stored in a list. That list is public and can
523
+ accessed or updated using the *maps* attribute. There is no other state.
524
+
525
+ Lookups search the underlying mappings successively until a key is found.
526
+ In contrast, writes, updates, and deletions only operate on the first
527
+ mapping.
528
+
529
+ '''
530
+
531
+ def __init__(self, *maps):
532
+ '''Initialize a ChainMap by setting *maps* to the given mappings.
533
+ If no mappings are provided, a single empty dictionary is used.
534
+
535
+ '''
536
+ self.maps = list(maps) or [{}] # always at least one map
537
+
538
+ def __missing__(self, key):
539
+ raise KeyError(key)
540
+
541
+ def __getitem__(self, key):
542
+ for mapping in self.maps:
543
+ try:
544
+ return mapping[key] # can't use 'key in mapping' with defaultdict
545
+ except KeyError:
546
+ pass
547
+ return self.__missing__(key) # support subclasses that define __missing__
548
+
549
+ def get(self, key, default=None):
550
+ return self[key] if key in self else default
551
+
552
+ def __len__(self):
553
+ return len(set().union(*self.maps)) # reuses stored hash values if possible
554
+
555
+ def __iter__(self):
556
+ return iter(set().union(*self.maps))
557
+
558
+ def __contains__(self, key):
559
+ return any(key in m for m in self.maps)
560
+
561
+ def __bool__(self):
562
+ return any(self.maps)
563
+
564
+ @_recursive_repr()
565
+ def __repr__(self):
566
+ return '{0.__class__.__name__}({1})'.format(
567
+ self, ', '.join(map(repr, self.maps)))
568
+
569
+ @classmethod
570
+ def fromkeys(cls, iterable, *args):
571
+ 'Create a ChainMap with a single dict created from the iterable.'
572
+ return cls(dict.fromkeys(iterable, *args))
573
+
574
+ def copy(self):
575
+ 'New ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]'
576
+ return self.__class__(self.maps[0].copy(), *self.maps[1:])
577
+
578
+ __copy__ = copy
579
+
580
+ def new_child(self): # like Django's Context.push()
581
+ 'New ChainMap with a new dict followed by all previous maps.'
582
+ return self.__class__({}, *self.maps)
583
+
584
+ @property
585
+ def parents(self): # like Django's Context.pop()
586
+ 'New ChainMap from maps[1:].'
587
+ return self.__class__(*self.maps[1:])
588
+
589
+ def __setitem__(self, key, value):
590
+ self.maps[0][key] = value
591
+
592
+ def __delitem__(self, key):
593
+ try:
594
+ del self.maps[0][key]
595
+ except KeyError:
596
+ raise KeyError('Key not found in the first mapping: {!r}'.format(key))
597
+
598
+ def popitem(self):
599
+ 'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.'
600
+ try:
601
+ return self.maps[0].popitem()
602
+ except KeyError:
603
+ raise KeyError('No keys found in the first mapping.')
604
+
605
+ def pop(self, key, *args):
606
+ 'Remove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].'
607
+ try:
608
+ return self.maps[0].pop(key, *args)
609
+ except KeyError:
610
+ raise KeyError('Key not found in the first mapping: {!r}'.format(key))
611
+
612
+ def clear(self):
613
+ 'Clear maps[0], leaving maps[1:] intact.'
614
+ self.maps[0].clear()
615
+
616
+ try:
617
+ from imp import cache_from_source
618
+ except ImportError: # pragma: no cover
619
+ def cache_from_source(path, debug_override=None):
620
+ assert path.endswith('.py')
621
+ if debug_override is None:
622
+ debug_override = __debug__
623
+ if debug_override:
624
+ suffix = 'c'
625
+ else:
626
+ suffix = 'o'
627
+ return path + suffix
628
+
629
+ try:
630
+ from collections import OrderedDict
631
+ except ImportError: # pragma: no cover
632
+ ## {{{ http://code.activestate.com/recipes/576693/ (r9)
633
+ # Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy.
634
+ # Passes Python2.7's test suite and incorporates all the latest updates.
635
+ try:
636
+ from thread import get_ident as _get_ident
637
+ except ImportError:
638
+ from dummy_thread import get_ident as _get_ident
639
+
640
+ try:
641
+ from _abcoll import KeysView, ValuesView, ItemsView
642
+ except ImportError:
643
+ pass
644
+
645
+
646
+ class OrderedDict(dict):
647
+ 'Dictionary that remembers insertion order'
648
+ # An inherited dict maps keys to values.
649
+ # The inherited dict provides __getitem__, __len__, __contains__, and get.
650
+ # The remaining methods are order-aware.
651
+ # Big-O running times for all methods are the same as for regular dictionaries.
652
+
653
+ # The internal self.__map dictionary maps keys to links in a doubly linked list.
654
+ # The circular doubly linked list starts and ends with a sentinel element.
655
+ # The sentinel element never gets deleted (this simplifies the algorithm).
656
+ # Each link is stored as a list of length three: [PREV, NEXT, KEY].
657
+
658
+ def __init__(self, *args, **kwds):
659
+ '''Initialize an ordered dictionary. Signature is the same as for
660
+ regular dictionaries, but keyword arguments are not recommended
661
+ because their insertion order is arbitrary.
662
+
663
+ '''
664
+ if len(args) > 1:
665
+ raise TypeError('expected at most 1 arguments, got %d' % len(args))
666
+ try:
667
+ self.__root
668
+ except AttributeError:
669
+ self.__root = root = [] # sentinel node
670
+ root[:] = [root, root, None]
671
+ self.__map = {}
672
+ self.__update(*args, **kwds)
673
+
674
+ def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
675
+ 'od.__setitem__(i, y) <==> od[i]=y'
676
+ # Setting a new item creates a new link which goes at the end of the linked
677
+ # list, and the inherited dictionary is updated with the new key/value pair.
678
+ if key not in self:
679
+ root = self.__root
680
+ last = root[0]
681
+ last[1] = root[0] = self.__map[key] = [last, root, key]
682
+ dict_setitem(self, key, value)
683
+
684
+ def __delitem__(self, key, dict_delitem=dict.__delitem__):
685
+ 'od.__delitem__(y) <==> del od[y]'
686
+ # Deleting an existing item uses self.__map to find the link which is
687
+ # then removed by updating the links in the predecessor and successor nodes.
688
+ dict_delitem(self, key)
689
+ link_prev, link_next, key = self.__map.pop(key)
690
+ link_prev[1] = link_next
691
+ link_next[0] = link_prev
692
+
693
+ def __iter__(self):
694
+ 'od.__iter__() <==> iter(od)'
695
+ root = self.__root
696
+ curr = root[1]
697
+ while curr is not root:
698
+ yield curr[2]
699
+ curr = curr[1]
700
+
701
+ def __reversed__(self):
702
+ 'od.__reversed__() <==> reversed(od)'
703
+ root = self.__root
704
+ curr = root[0]
705
+ while curr is not root:
706
+ yield curr[2]
707
+ curr = curr[0]
708
+
709
+ def clear(self):
710
+ 'od.clear() -> None. Remove all items from od.'
711
+ try:
712
+ for node in self.__map.itervalues():
713
+ del node[:]
714
+ root = self.__root
715
+ root[:] = [root, root, None]
716
+ self.__map.clear()
717
+ except AttributeError:
718
+ pass
719
+ dict.clear(self)
720
+
721
+ def popitem(self, last=True):
722
+ '''od.popitem() -> (k, v), return and remove a (key, value) pair.
723
+ Pairs are returned in LIFO order if last is true or FIFO order if false.
724
+
725
+ '''
726
+ if not self:
727
+ raise KeyError('dictionary is empty')
728
+ root = self.__root
729
+ if last:
730
+ link = root[0]
731
+ link_prev = link[0]
732
+ link_prev[1] = root
733
+ root[0] = link_prev
734
+ else:
735
+ link = root[1]
736
+ link_next = link[1]
737
+ root[1] = link_next
738
+ link_next[0] = root
739
+ key = link[2]
740
+ del self.__map[key]
741
+ value = dict.pop(self, key)
742
+ return key, value
743
+
744
+ # -- the following methods do not depend on the internal structure --
745
+
746
+ def keys(self):
747
+ 'od.keys() -> list of keys in od'
748
+ return list(self)
749
+
750
+ def values(self):
751
+ 'od.values() -> list of values in od'
752
+ return [self[key] for key in self]
753
+
754
+ def items(self):
755
+ 'od.items() -> list of (key, value) pairs in od'
756
+ return [(key, self[key]) for key in self]
757
+
758
+ def iterkeys(self):
759
+ 'od.iterkeys() -> an iterator over the keys in od'
760
+ return iter(self)
761
+
762
+ def itervalues(self):
763
+ 'od.itervalues -> an iterator over the values in od'
764
+ for k in self:
765
+ yield self[k]
766
+
767
+ def iteritems(self):
768
+ 'od.iteritems -> an iterator over the (key, value) items in od'
769
+ for k in self:
770
+ yield (k, self[k])
771
+
772
+ def update(*args, **kwds):
773
+ '''od.update(E, **F) -> None. Update od from dict/iterable E and F.
774
+
775
+ If E is a dict instance, does: for k in E: od[k] = E[k]
776
+ If E has a .keys() method, does: for k in E.keys(): od[k] = E[k]
777
+ Or if E is an iterable of items, does: for k, v in E: od[k] = v
778
+ In either case, this is followed by: for k, v in F.items(): od[k] = v
779
+
780
+ '''
781
+ if len(args) > 2:
782
+ raise TypeError('update() takes at most 2 positional '
783
+ 'arguments (%d given)' % (len(args),))
784
+ elif not args:
785
+ raise TypeError('update() takes at least 1 argument (0 given)')
786
+ self = args[0]
787
+ # Make progressively weaker assumptions about "other"
788
+ other = ()
789
+ if len(args) == 2:
790
+ other = args[1]
791
+ if isinstance(other, dict):
792
+ for key in other:
793
+ self[key] = other[key]
794
+ elif hasattr(other, 'keys'):
795
+ for key in other.keys():
796
+ self[key] = other[key]
797
+ else:
798
+ for key, value in other:
799
+ self[key] = value
800
+ for key, value in kwds.items():
801
+ self[key] = value
802
+
803
+ __update = update # let subclasses override update without breaking __init__
804
+
805
+ __marker = object()
806
+
807
+ def pop(self, key, default=__marker):
808
+ '''od.pop(k[,d]) -> v, remove specified key and return the corresponding value.
809
+ If key is not found, d is returned if given, otherwise KeyError is raised.
810
+
811
+ '''
812
+ if key in self:
813
+ result = self[key]
814
+ del self[key]
815
+ return result
816
+ if default is self.__marker:
817
+ raise KeyError(key)
818
+ return default
819
+
820
+ def setdefault(self, key, default=None):
821
+ 'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
822
+ if key in self:
823
+ return self[key]
824
+ self[key] = default
825
+ return default
826
+
827
+ def __repr__(self, _repr_running=None):
828
+ 'od.__repr__() <==> repr(od)'
829
+ if not _repr_running: _repr_running = {}
830
+ call_key = id(self), _get_ident()
831
+ if call_key in _repr_running:
832
+ return '...'
833
+ _repr_running[call_key] = 1
834
+ try:
835
+ if not self:
836
+ return '%s()' % (self.__class__.__name__,)
837
+ return '%s(%r)' % (self.__class__.__name__, self.items())
838
+ finally:
839
+ del _repr_running[call_key]
840
+
841
+ def __reduce__(self):
842
+ 'Return state information for pickling'
843
+ items = [[k, self[k]] for k in self]
844
+ inst_dict = vars(self).copy()
845
+ for k in vars(OrderedDict()):
846
+ inst_dict.pop(k, None)
847
+ if inst_dict:
848
+ return (self.__class__, (items,), inst_dict)
849
+ return self.__class__, (items,)
850
+
851
+ def copy(self):
852
+ 'od.copy() -> a shallow copy of od'
853
+ return self.__class__(self)
854
+
855
+ @classmethod
856
+ def fromkeys(cls, iterable, value=None):
857
+ '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
858
+ and values equal to v (which defaults to None).
859
+
860
+ '''
861
+ d = cls()
862
+ for key in iterable:
863
+ d[key] = value
864
+ return d
865
+
866
+ def __eq__(self, other):
867
+ '''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive
868
+ while comparison to a regular mapping is order-insensitive.
869
+
870
+ '''
871
+ if isinstance(other, OrderedDict):
872
+ return len(self)==len(other) and self.items() == other.items()
873
+ return dict.__eq__(self, other)
874
+
875
+ def __ne__(self, other):
876
+ return not self == other
877
+
878
+ # -- the following methods are only used in Python 2.7 --
879
+
880
+ def viewkeys(self):
881
+ "od.viewkeys() -> a set-like object providing a view on od's keys"
882
+ return KeysView(self)
883
+
884
+ def viewvalues(self):
885
+ "od.viewvalues() -> an object providing a view on od's values"
886
+ return ValuesView(self)
887
+
888
+ def viewitems(self):
889
+ "od.viewitems() -> a set-like object providing a view on od's items"
890
+ return ItemsView(self)
891
+
892
+ try:
893
+ from logging.config import BaseConfigurator, valid_ident
894
+ except ImportError: # pragma: no cover
895
+ IDENTIFIER = re.compile('^[a-z_][a-z0-9_]*$', re.I)
896
+
897
+
898
+ def valid_ident(s):
899
+ m = IDENTIFIER.match(s)
900
+ if not m:
901
+ raise ValueError('Not a valid Python identifier: %r' % s)
902
+ return True
903
+
904
+
905
+ # The ConvertingXXX classes are wrappers around standard Python containers,
906
+ # and they serve to convert any suitable values in the container. The
907
+ # conversion converts base dicts, lists and tuples to their wrapped
908
+ # equivalents, whereas strings which match a conversion format are converted
909
+ # appropriately.
910
+ #
911
+ # Each wrapper should have a configurator attribute holding the actual
912
+ # configurator to use for conversion.
913
+
914
+ class ConvertingDict(dict):
915
+ """A converting dictionary wrapper."""
916
+
917
+ def __getitem__(self, key):
918
+ value = dict.__getitem__(self, key)
919
+ result = self.configurator.convert(value)
920
+ #If the converted value is different, save for next time
921
+ if value is not result:
922
+ self[key] = result
923
+ if type(result) in (ConvertingDict, ConvertingList,
924
+ ConvertingTuple):
925
+ result.parent = self
926
+ result.key = key
927
+ return result
928
+
929
+ def get(self, key, default=None):
930
+ value = dict.get(self, key, default)
931
+ result = self.configurator.convert(value)
932
+ #If the converted value is different, save for next time
933
+ if value is not result:
934
+ self[key] = result
935
+ if type(result) in (ConvertingDict, ConvertingList,
936
+ ConvertingTuple):
937
+ result.parent = self
938
+ result.key = key
939
+ return result
940
+
941
+ def pop(self, key, default=None):
942
+ value = dict.pop(self, key, default)
943
+ result = self.configurator.convert(value)
944
+ if value is not result:
945
+ if type(result) in (ConvertingDict, ConvertingList,
946
+ ConvertingTuple):
947
+ result.parent = self
948
+ result.key = key
949
+ return result
950
+
951
+ class ConvertingList(list):
952
+ """A converting list wrapper."""
953
+ def __getitem__(self, key):
954
+ value = list.__getitem__(self, key)
955
+ result = self.configurator.convert(value)
956
+ #If the converted value is different, save for next time
957
+ if value is not result:
958
+ self[key] = result
959
+ if type(result) in (ConvertingDict, ConvertingList,
960
+ ConvertingTuple):
961
+ result.parent = self
962
+ result.key = key
963
+ return result
964
+
965
+ def pop(self, idx=-1):
966
+ value = list.pop(self, idx)
967
+ result = self.configurator.convert(value)
968
+ if value is not result:
969
+ if type(result) in (ConvertingDict, ConvertingList,
970
+ ConvertingTuple):
971
+ result.parent = self
972
+ return result
973
+
974
+ class ConvertingTuple(tuple):
975
+ """A converting tuple wrapper."""
976
+ def __getitem__(self, key):
977
+ value = tuple.__getitem__(self, key)
978
+ result = self.configurator.convert(value)
979
+ if value is not result:
980
+ if type(result) in (ConvertingDict, ConvertingList,
981
+ ConvertingTuple):
982
+ result.parent = self
983
+ result.key = key
984
+ return result
985
+
986
+ class BaseConfigurator(object):
987
+ """
988
+ The configurator base class which defines some useful defaults.
989
+ """
990
+
991
+ CONVERT_PATTERN = re.compile(r'^(?P<prefix>[a-z]+)://(?P<suffix>.*)$')
992
+
993
+ WORD_PATTERN = re.compile(r'^\s*(\w+)\s*')
994
+ DOT_PATTERN = re.compile(r'^\.\s*(\w+)\s*')
995
+ INDEX_PATTERN = re.compile(r'^\[\s*(\w+)\s*\]\s*')
996
+ DIGIT_PATTERN = re.compile(r'^\d+$')
997
+
998
+ value_converters = {
999
+ 'ext' : 'ext_convert',
1000
+ 'cfg' : 'cfg_convert',
1001
+ }
1002
+
1003
+ # We might want to use a different one, e.g. importlib
1004
+ importer = staticmethod(__import__)
1005
+
1006
+ def __init__(self, config):
1007
+ self.config = ConvertingDict(config)
1008
+ self.config.configurator = self
1009
+
1010
+ def resolve(self, s):
1011
+ """
1012
+ Resolve strings to objects using standard import and attribute
1013
+ syntax.
1014
+ """
1015
+ name = s.split('.')
1016
+ used = name.pop(0)
1017
+ try:
1018
+ found = self.importer(used)
1019
+ for frag in name:
1020
+ used += '.' + frag
1021
+ try:
1022
+ found = getattr(found, frag)
1023
+ except AttributeError:
1024
+ self.importer(used)
1025
+ found = getattr(found, frag)
1026
+ return found
1027
+ except ImportError:
1028
+ e, tb = sys.exc_info()[1:]
1029
+ v = ValueError('Cannot resolve %r: %s' % (s, e))
1030
+ v.__cause__, v.__traceback__ = e, tb
1031
+ raise v
1032
+
1033
+ def ext_convert(self, value):
1034
+ """Default converter for the ext:// protocol."""
1035
+ return self.resolve(value)
1036
+
1037
+ def cfg_convert(self, value):
1038
+ """Default converter for the cfg:// protocol."""
1039
+ rest = value
1040
+ m = self.WORD_PATTERN.match(rest)
1041
+ if m is None:
1042
+ raise ValueError("Unable to convert %r" % value)
1043
+ else:
1044
+ rest = rest[m.end():]
1045
+ d = self.config[m.groups()[0]]
1046
+ #print d, rest
1047
+ while rest:
1048
+ m = self.DOT_PATTERN.match(rest)
1049
+ if m:
1050
+ d = d[m.groups()[0]]
1051
+ else:
1052
+ m = self.INDEX_PATTERN.match(rest)
1053
+ if m:
1054
+ idx = m.groups()[0]
1055
+ if not self.DIGIT_PATTERN.match(idx):
1056
+ d = d[idx]
1057
+ else:
1058
+ try:
1059
+ n = int(idx) # try as number first (most likely)
1060
+ d = d[n]
1061
+ except TypeError:
1062
+ d = d[idx]
1063
+ if m:
1064
+ rest = rest[m.end():]
1065
+ else:
1066
+ raise ValueError('Unable to convert '
1067
+ '%r at %r' % (value, rest))
1068
+ #rest should be empty
1069
+ return d
1070
+
1071
+ def convert(self, value):
1072
+ """
1073
+ Convert values to an appropriate type. dicts, lists and tuples are
1074
+ replaced by their converting alternatives. Strings are checked to
1075
+ see if they have a conversion format and are converted if they do.
1076
+ """
1077
+ if not isinstance(value, ConvertingDict) and isinstance(value, dict):
1078
+ value = ConvertingDict(value)
1079
+ value.configurator = self
1080
+ elif not isinstance(value, ConvertingList) and isinstance(value, list):
1081
+ value = ConvertingList(value)
1082
+ value.configurator = self
1083
+ elif not isinstance(value, ConvertingTuple) and\
1084
+ isinstance(value, tuple):
1085
+ value = ConvertingTuple(value)
1086
+ value.configurator = self
1087
+ elif isinstance(value, string_types):
1088
+ m = self.CONVERT_PATTERN.match(value)
1089
+ if m:
1090
+ d = m.groupdict()
1091
+ prefix = d['prefix']
1092
+ converter = self.value_converters.get(prefix, None)
1093
+ if converter:
1094
+ suffix = d['suffix']
1095
+ converter = getattr(self, converter)
1096
+ value = converter(suffix)
1097
+ return value
1098
+
1099
+ def configure_custom(self, config):
1100
+ """Configure an object with a user-supplied factory."""
1101
+ c = config.pop('()')
1102
+ if not callable(c):
1103
+ c = self.resolve(c)
1104
+ props = config.pop('.', None)
1105
+ # Check for valid identifiers
1106
+ kwargs = dict([(k, config[k]) for k in config if valid_ident(k)])
1107
+ result = c(**kwargs)
1108
+ if props:
1109
+ for name, value in props.items():
1110
+ setattr(result, name, value)
1111
+ return result
1112
+
1113
+ def as_tuple(self, value):
1114
+ """Utility function which converts lists to tuples."""
1115
+ if isinstance(value, list):
1116
+ value = tuple(value)
1117
+ return value