quarchpy 2.1.14.dev3__py2.py3-none-any.whl → 2.1.14.dev5__py2.py3-none-any.whl

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 (701) hide show
  1. quarchpy/.idea/.name +1 -0
  2. quarchpy/.idea/workspace.xml +70 -11
  3. quarchpy/__pycache__/_version.cpython-311.pyc +0 -0
  4. quarchpy/__pycache__/run.cpython-311.pyc +0 -0
  5. quarchpy/_version.py +1 -1
  6. quarchpy/_version.py.bak +1 -0
  7. quarchpy/connection_specific/__pycache__/connection_QIS.cpython-311.pyc +0 -0
  8. quarchpy/connection_specific/connection_QIS.py +22 -9
  9. quarchpy/connection_specific/connection_QIS.py.bak +35 -17
  10. quarchpy/connection_specific/connection_ReST.py +26 -16
  11. quarchpy/debug/__pycache__/module_debug.cpython-311.pyc +0 -0
  12. quarchpy/debug/__pycache__/simple_terminal.cpython-311.pyc +0 -0
  13. quarchpy/debug/__pycache__/upgrade_quarchpy.cpython-311.pyc +0 -0
  14. quarchpy/device/__pycache__/scanDevices.cpython-311.pyc +0 -0
  15. quarchpy/device/scanDevices.py +2 -4
  16. quarchpy/device/scanDevices.py.bak +657 -0
  17. quarchpy/qis/qisFuncs.py +25 -42
  18. quarchpy/qis/qisFuncs.py.bak +213 -0
  19. quarchpy/qps/__pycache__/qpsFuncs.cpython-311.pyc +0 -0
  20. quarchpy/qps/qpsFuncs.py +18 -22
  21. quarchpy/qps/qpsFuncs.py.bak +224 -0
  22. quarchpy/venv/.gitignore +2 -0
  23. quarchpy/venv/Include/Python-ast.h +535 -0
  24. quarchpy/venv/Include/Python.h +181 -0
  25. quarchpy/venv/Include/abstract.h +1396 -0
  26. quarchpy/venv/Include/asdl.h +45 -0
  27. quarchpy/venv/Include/ast.h +13 -0
  28. quarchpy/venv/Include/bitset.h +32 -0
  29. quarchpy/venv/Include/boolobject.h +36 -0
  30. quarchpy/venv/Include/bufferobject.h +33 -0
  31. quarchpy/venv/Include/bytearrayobject.h +57 -0
  32. quarchpy/venv/Include/bytes_methods.h +75 -0
  33. quarchpy/venv/Include/bytesobject.h +27 -0
  34. quarchpy/venv/Include/cStringIO.h +73 -0
  35. quarchpy/venv/Include/cellobject.h +28 -0
  36. quarchpy/venv/Include/ceval.h +154 -0
  37. quarchpy/venv/Include/classobject.h +83 -0
  38. quarchpy/venv/Include/cobject.h +89 -0
  39. quarchpy/venv/Include/code.h +116 -0
  40. quarchpy/venv/Include/codecs.h +212 -0
  41. quarchpy/venv/Include/compile.h +40 -0
  42. quarchpy/venv/Include/complexobject.h +66 -0
  43. quarchpy/venv/Include/datetime.h +239 -0
  44. quarchpy/venv/Include/descrobject.h +94 -0
  45. quarchpy/venv/Include/dictobject.h +160 -0
  46. quarchpy/venv/Include/dtoa.h +15 -0
  47. quarchpy/venv/Include/enumobject.h +17 -0
  48. quarchpy/venv/Include/errcode.h +37 -0
  49. quarchpy/venv/Include/eval.h +25 -0
  50. quarchpy/venv/Include/fileobject.h +97 -0
  51. quarchpy/venv/Include/floatobject.h +140 -0
  52. quarchpy/venv/Include/frameobject.h +89 -0
  53. quarchpy/venv/Include/funcobject.h +76 -0
  54. quarchpy/venv/Include/genobject.h +40 -0
  55. quarchpy/venv/Include/graminit.h +87 -0
  56. quarchpy/venv/Include/grammar.h +94 -0
  57. quarchpy/venv/Include/import.h +71 -0
  58. quarchpy/venv/Include/intobject.h +84 -0
  59. quarchpy/venv/Include/intrcheck.h +15 -0
  60. quarchpy/venv/Include/iterobject.h +23 -0
  61. quarchpy/venv/Include/listobject.h +68 -0
  62. quarchpy/venv/Include/longintrepr.h +103 -0
  63. quarchpy/venv/Include/longobject.h +135 -0
  64. quarchpy/venv/Include/marshal.h +25 -0
  65. quarchpy/venv/Include/memoryobject.h +74 -0
  66. quarchpy/venv/Include/metagrammar.h +18 -0
  67. quarchpy/venv/Include/methodobject.h +93 -0
  68. quarchpy/venv/Include/modsupport.h +134 -0
  69. quarchpy/venv/Include/moduleobject.h +24 -0
  70. quarchpy/venv/Include/node.h +41 -0
  71. quarchpy/venv/Include/object.h +1046 -0
  72. quarchpy/venv/Include/objimpl.h +369 -0
  73. quarchpy/venv/Include/opcode.h +171 -0
  74. quarchpy/venv/Include/osdefs.h +63 -0
  75. quarchpy/venv/Include/parsetok.h +64 -0
  76. quarchpy/venv/Include/patchlevel.h +43 -0
  77. quarchpy/venv/Include/pgen.h +18 -0
  78. quarchpy/venv/Include/pgenheaders.h +43 -0
  79. quarchpy/venv/Include/py_curses.h +177 -0
  80. quarchpy/venv/Include/pyarena.h +62 -0
  81. quarchpy/venv/Include/pycapsule.h +56 -0
  82. quarchpy/venv/Include/pyconfig.h +770 -0
  83. quarchpy/venv/Include/pyctype.h +31 -0
  84. quarchpy/venv/Include/pydebug.h +41 -0
  85. quarchpy/venv/Include/pyerrors.h +329 -0
  86. quarchpy/venv/Include/pyexpat.h +50 -0
  87. quarchpy/venv/Include/pyfpe.h +176 -0
  88. quarchpy/venv/Include/pygetopt.h +18 -0
  89. quarchpy/venv/Include/pymacconfig.h +102 -0
  90. quarchpy/venv/Include/pymactoolbox.h +232 -0
  91. quarchpy/venv/Include/pymath.h +214 -0
  92. quarchpy/venv/Include/pymem.h +122 -0
  93. quarchpy/venv/Include/pyport.h +950 -0
  94. quarchpy/venv/Include/pystate.h +200 -0
  95. quarchpy/venv/Include/pystrcmp.h +23 -0
  96. quarchpy/venv/Include/pystrtod.h +45 -0
  97. quarchpy/venv/Include/pythonrun.h +181 -0
  98. quarchpy/venv/Include/pythread.h +41 -0
  99. quarchpy/venv/Include/rangeobject.h +28 -0
  100. quarchpy/venv/Include/setobject.h +99 -0
  101. quarchpy/venv/Include/sliceobject.h +50 -0
  102. quarchpy/venv/Include/stringobject.h +210 -0
  103. quarchpy/venv/Include/structmember.h +99 -0
  104. quarchpy/venv/Include/structseq.h +41 -0
  105. quarchpy/venv/Include/symtable.h +98 -0
  106. quarchpy/venv/Include/sysmodule.h +31 -0
  107. quarchpy/venv/Include/timefuncs.h +26 -0
  108. quarchpy/venv/Include/token.h +85 -0
  109. quarchpy/venv/Include/traceback.h +31 -0
  110. quarchpy/venv/Include/tupleobject.h +61 -0
  111. quarchpy/venv/Include/ucnhash.h +33 -0
  112. quarchpy/venv/Include/unicodeobject.h +1413 -0
  113. quarchpy/venv/Include/warnings.h +23 -0
  114. quarchpy/venv/Include/weakrefobject.h +82 -0
  115. quarchpy/venv/Lib/os.py +742 -0
  116. quarchpy/venv/Lib/os.pyc +0 -0
  117. quarchpy/venv/Lib/site-packages/_virtualenv.pth +1 -0
  118. quarchpy/venv/Lib/site-packages/_virtualenv.py +130 -0
  119. quarchpy/venv/Lib/site-packages/_virtualenv.pyc +0 -0
  120. quarchpy/venv/Lib/site-packages/easy_install.py +5 -0
  121. quarchpy/venv/Lib/site-packages/pip/__init__.py +18 -0
  122. quarchpy/venv/Lib/site-packages/pip/__main__.py +26 -0
  123. quarchpy/venv/Lib/site-packages/pip/_internal/__init__.py +17 -0
  124. quarchpy/venv/Lib/site-packages/pip/_internal/build_env.py +242 -0
  125. quarchpy/venv/Lib/site-packages/pip/_internal/cache.py +346 -0
  126. quarchpy/venv/Lib/site-packages/pip/_internal/cli/__init__.py +4 -0
  127. quarchpy/venv/Lib/site-packages/pip/_internal/cli/autocompletion.py +164 -0
  128. quarchpy/venv/Lib/site-packages/pip/_internal/cli/base_command.py +260 -0
  129. quarchpy/venv/Lib/site-packages/pip/_internal/cli/cmdoptions.py +971 -0
  130. quarchpy/venv/Lib/site-packages/pip/_internal/cli/command_context.py +36 -0
  131. quarchpy/venv/Lib/site-packages/pip/_internal/cli/main.py +75 -0
  132. quarchpy/venv/Lib/site-packages/pip/_internal/cli/main_parser.py +96 -0
  133. quarchpy/venv/Lib/site-packages/pip/_internal/cli/parser.py +285 -0
  134. quarchpy/venv/Lib/site-packages/pip/_internal/cli/progress_bars.py +280 -0
  135. quarchpy/venv/Lib/site-packages/pip/_internal/cli/req_command.py +436 -0
  136. quarchpy/venv/Lib/site-packages/pip/_internal/cli/spinners.py +173 -0
  137. quarchpy/venv/Lib/site-packages/pip/_internal/cli/status_codes.py +8 -0
  138. quarchpy/venv/Lib/site-packages/pip/_internal/commands/__init__.py +123 -0
  139. quarchpy/venv/Lib/site-packages/pip/_internal/commands/cache.py +234 -0
  140. quarchpy/venv/Lib/site-packages/pip/_internal/commands/check.py +51 -0
  141. quarchpy/venv/Lib/site-packages/pip/_internal/commands/completion.py +98 -0
  142. quarchpy/venv/Lib/site-packages/pip/_internal/commands/configuration.py +280 -0
  143. quarchpy/venv/Lib/site-packages/pip/_internal/commands/debug.py +230 -0
  144. quarchpy/venv/Lib/site-packages/pip/_internal/commands/download.py +143 -0
  145. quarchpy/venv/Lib/site-packages/pip/_internal/commands/freeze.py +116 -0
  146. quarchpy/venv/Lib/site-packages/pip/_internal/commands/hash.py +63 -0
  147. quarchpy/venv/Lib/site-packages/pip/_internal/commands/help.py +46 -0
  148. quarchpy/venv/Lib/site-packages/pip/_internal/commands/install.py +737 -0
  149. quarchpy/venv/Lib/site-packages/pip/_internal/commands/list.py +327 -0
  150. quarchpy/venv/Lib/site-packages/pip/_internal/commands/search.py +169 -0
  151. quarchpy/venv/Lib/site-packages/pip/_internal/commands/show.py +186 -0
  152. quarchpy/venv/Lib/site-packages/pip/_internal/commands/uninstall.py +95 -0
  153. quarchpy/venv/Lib/site-packages/pip/_internal/commands/wheel.py +198 -0
  154. quarchpy/venv/Lib/site-packages/pip/_internal/configuration.py +407 -0
  155. quarchpy/venv/Lib/site-packages/pip/_internal/distributions/__init__.py +24 -0
  156. quarchpy/venv/Lib/site-packages/pip/_internal/distributions/base.py +46 -0
  157. quarchpy/venv/Lib/site-packages/pip/_internal/distributions/installed.py +25 -0
  158. quarchpy/venv/Lib/site-packages/pip/_internal/distributions/sdist.py +105 -0
  159. quarchpy/venv/Lib/site-packages/pip/_internal/distributions/wheel.py +37 -0
  160. quarchpy/venv/Lib/site-packages/pip/_internal/exceptions.py +391 -0
  161. quarchpy/venv/Lib/site-packages/pip/_internal/index/__init__.py +2 -0
  162. quarchpy/venv/Lib/site-packages/pip/_internal/index/collector.py +667 -0
  163. quarchpy/venv/Lib/site-packages/pip/_internal/index/package_finder.py +1015 -0
  164. quarchpy/venv/Lib/site-packages/pip/_internal/locations.py +193 -0
  165. quarchpy/venv/Lib/site-packages/pip/_internal/main.py +16 -0
  166. quarchpy/venv/Lib/site-packages/pip/_internal/models/__init__.py +2 -0
  167. quarchpy/venv/Lib/site-packages/pip/_internal/models/candidate.py +39 -0
  168. quarchpy/venv/Lib/site-packages/pip/_internal/models/direct_url.py +243 -0
  169. quarchpy/venv/Lib/site-packages/pip/_internal/models/format_control.py +92 -0
  170. quarchpy/venv/Lib/site-packages/pip/_internal/models/index.py +34 -0
  171. quarchpy/venv/Lib/site-packages/pip/_internal/models/link.py +246 -0
  172. quarchpy/venv/Lib/site-packages/pip/_internal/models/scheme.py +31 -0
  173. quarchpy/venv/Lib/site-packages/pip/_internal/models/search_scope.py +135 -0
  174. quarchpy/venv/Lib/site-packages/pip/_internal/models/selection_prefs.py +50 -0
  175. quarchpy/venv/Lib/site-packages/pip/_internal/models/target_python.py +117 -0
  176. quarchpy/venv/Lib/site-packages/pip/_internal/models/wheel.py +78 -0
  177. quarchpy/venv/Lib/site-packages/pip/_internal/network/__init__.py +2 -0
  178. quarchpy/venv/Lib/site-packages/pip/_internal/network/auth.py +310 -0
  179. quarchpy/venv/Lib/site-packages/pip/_internal/network/cache.py +79 -0
  180. quarchpy/venv/Lib/site-packages/pip/_internal/network/download.py +202 -0
  181. quarchpy/venv/Lib/site-packages/pip/_internal/network/lazy_wheel.py +231 -0
  182. quarchpy/venv/Lib/site-packages/pip/_internal/network/session.py +428 -0
  183. quarchpy/venv/Lib/site-packages/pip/_internal/network/utils.py +97 -0
  184. quarchpy/venv/Lib/site-packages/pip/_internal/network/xmlrpc.py +53 -0
  185. quarchpy/venv/Lib/site-packages/pip/_internal/operations/__init__.py +0 -0
  186. quarchpy/venv/Lib/site-packages/pip/_internal/operations/build/__init__.py +0 -0
  187. quarchpy/venv/Lib/site-packages/pip/_internal/operations/build/metadata.py +38 -0
  188. quarchpy/venv/Lib/site-packages/pip/_internal/operations/build/metadata_legacy.py +77 -0
  189. quarchpy/venv/Lib/site-packages/pip/_internal/operations/build/wheel.py +47 -0
  190. quarchpy/venv/Lib/site-packages/pip/_internal/operations/build/wheel_legacy.py +113 -0
  191. quarchpy/venv/Lib/site-packages/pip/_internal/operations/check.py +155 -0
  192. quarchpy/venv/Lib/site-packages/pip/_internal/operations/freeze.py +277 -0
  193. quarchpy/venv/Lib/site-packages/pip/_internal/operations/install/__init__.py +2 -0
  194. quarchpy/venv/Lib/site-packages/pip/_internal/operations/install/editable_legacy.py +52 -0
  195. quarchpy/venv/Lib/site-packages/pip/_internal/operations/install/legacy.py +130 -0
  196. quarchpy/venv/Lib/site-packages/pip/_internal/operations/install/wheel.py +846 -0
  197. quarchpy/venv/Lib/site-packages/pip/_internal/operations/prepare.py +608 -0
  198. quarchpy/venv/Lib/site-packages/pip/_internal/pyproject.py +196 -0
  199. quarchpy/venv/Lib/site-packages/pip/_internal/req/__init__.py +103 -0
  200. quarchpy/venv/Lib/site-packages/pip/_internal/req/constructors.py +476 -0
  201. quarchpy/venv/Lib/site-packages/pip/_internal/req/req_file.py +574 -0
  202. quarchpy/venv/Lib/site-packages/pip/_internal/req/req_install.py +907 -0
  203. quarchpy/venv/Lib/site-packages/pip/_internal/req/req_set.py +204 -0
  204. quarchpy/venv/Lib/site-packages/pip/_internal/req/req_tracker.py +151 -0
  205. quarchpy/venv/Lib/site-packages/pip/_internal/req/req_uninstall.py +657 -0
  206. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/__init__.py +0 -0
  207. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/base.py +21 -0
  208. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/legacy/__init__.py +0 -0
  209. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/legacy/resolver.py +473 -0
  210. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/resolvelib/__init__.py +0 -0
  211. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/resolvelib/base.py +156 -0
  212. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/resolvelib/candidates.py +604 -0
  213. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/resolvelib/factory.py +504 -0
  214. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py +101 -0
  215. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/resolvelib/provider.py +174 -0
  216. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/resolvelib/reporter.py +84 -0
  217. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/resolvelib/requirements.py +201 -0
  218. quarchpy/venv/Lib/site-packages/pip/_internal/resolution/resolvelib/resolver.py +296 -0
  219. quarchpy/venv/Lib/site-packages/pip/_internal/self_outdated_check.py +197 -0
  220. quarchpy/venv/Lib/site-packages/pip/_internal/utils/__init__.py +0 -0
  221. quarchpy/venv/Lib/site-packages/pip/_internal/utils/appdirs.py +44 -0
  222. quarchpy/venv/Lib/site-packages/pip/_internal/utils/compat.py +293 -0
  223. quarchpy/venv/Lib/site-packages/pip/_internal/utils/compatibility_tags.py +178 -0
  224. quarchpy/venv/Lib/site-packages/pip/_internal/utils/datetime.py +14 -0
  225. quarchpy/venv/Lib/site-packages/pip/_internal/utils/deprecation.py +104 -0
  226. quarchpy/venv/Lib/site-packages/pip/_internal/utils/direct_url_helpers.py +126 -0
  227. quarchpy/venv/Lib/site-packages/pip/_internal/utils/distutils_args.py +48 -0
  228. quarchpy/venv/Lib/site-packages/pip/_internal/utils/encoding.py +41 -0
  229. quarchpy/venv/Lib/site-packages/pip/_internal/utils/entrypoints.py +31 -0
  230. quarchpy/venv/Lib/site-packages/pip/_internal/utils/filesystem.py +224 -0
  231. quarchpy/venv/Lib/site-packages/pip/_internal/utils/filetypes.py +26 -0
  232. quarchpy/venv/Lib/site-packages/pip/_internal/utils/glibc.py +98 -0
  233. quarchpy/venv/Lib/site-packages/pip/_internal/utils/hashes.py +169 -0
  234. quarchpy/venv/Lib/site-packages/pip/_internal/utils/inject_securetransport.py +36 -0
  235. quarchpy/venv/Lib/site-packages/pip/_internal/utils/logging.py +399 -0
  236. quarchpy/venv/Lib/site-packages/pip/_internal/utils/misc.py +962 -0
  237. quarchpy/venv/Lib/site-packages/pip/_internal/utils/models.py +44 -0
  238. quarchpy/venv/Lib/site-packages/pip/_internal/utils/packaging.py +95 -0
  239. quarchpy/venv/Lib/site-packages/pip/_internal/utils/parallel.py +107 -0
  240. quarchpy/venv/Lib/site-packages/pip/_internal/utils/pkg_resources.py +44 -0
  241. quarchpy/venv/Lib/site-packages/pip/_internal/utils/setuptools_build.py +181 -0
  242. quarchpy/venv/Lib/site-packages/pip/_internal/utils/subprocess.py +299 -0
  243. quarchpy/venv/Lib/site-packages/pip/_internal/utils/temp_dir.py +284 -0
  244. quarchpy/venv/Lib/site-packages/pip/_internal/utils/typing.py +38 -0
  245. quarchpy/venv/Lib/site-packages/pip/_internal/utils/unpacking.py +281 -0
  246. quarchpy/venv/Lib/site-packages/pip/_internal/utils/urls.py +55 -0
  247. quarchpy/venv/Lib/site-packages/pip/_internal/utils/virtualenv.py +119 -0
  248. quarchpy/venv/Lib/site-packages/pip/_internal/utils/wheel.py +225 -0
  249. quarchpy/venv/Lib/site-packages/pip/_internal/vcs/__init__.py +15 -0
  250. quarchpy/venv/Lib/site-packages/pip/_internal/vcs/bazaar.py +123 -0
  251. quarchpy/venv/Lib/site-packages/pip/_internal/vcs/git.py +454 -0
  252. quarchpy/venv/Lib/site-packages/pip/_internal/vcs/mercurial.py +172 -0
  253. quarchpy/venv/Lib/site-packages/pip/_internal/vcs/subversion.py +340 -0
  254. quarchpy/venv/Lib/site-packages/pip/_internal/vcs/versioncontrol.py +735 -0
  255. quarchpy/venv/Lib/site-packages/pip/_internal/wheel_builder.py +362 -0
  256. quarchpy/venv/Lib/site-packages/pip/_vendor/__init__.py +114 -0
  257. quarchpy/venv/Lib/site-packages/pip/_vendor/appdirs.py +633 -0
  258. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/__init__.py +11 -0
  259. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/_cmd.py +57 -0
  260. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/adapter.py +133 -0
  261. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/cache.py +39 -0
  262. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/caches/__init__.py +2 -0
  263. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/caches/file_cache.py +146 -0
  264. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/caches/redis_cache.py +33 -0
  265. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/compat.py +29 -0
  266. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/controller.py +376 -0
  267. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/filewrapper.py +80 -0
  268. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/heuristics.py +135 -0
  269. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/serialize.py +188 -0
  270. quarchpy/venv/Lib/site-packages/pip/_vendor/cachecontrol/wrapper.py +29 -0
  271. quarchpy/venv/Lib/site-packages/pip/_vendor/certifi/__init__.py +3 -0
  272. quarchpy/venv/Lib/site-packages/pip/_vendor/certifi/__main__.py +12 -0
  273. quarchpy/venv/Lib/site-packages/pip/_vendor/certifi/cacert.pem +4606 -0
  274. quarchpy/venv/Lib/site-packages/pip/_vendor/certifi/core.py +60 -0
  275. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/__init__.py +39 -0
  276. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/big5freq.py +386 -0
  277. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/big5prober.py +47 -0
  278. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/chardistribution.py +233 -0
  279. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/charsetgroupprober.py +106 -0
  280. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/charsetprober.py +145 -0
  281. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/cli/__init__.py +1 -0
  282. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/cli/chardetect.py +85 -0
  283. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/codingstatemachine.py +88 -0
  284. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/compat.py +34 -0
  285. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/cp949prober.py +49 -0
  286. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/enums.py +76 -0
  287. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/escprober.py +101 -0
  288. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/escsm.py +246 -0
  289. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/eucjpprober.py +92 -0
  290. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/euckrfreq.py +195 -0
  291. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/euckrprober.py +47 -0
  292. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/euctwfreq.py +387 -0
  293. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/euctwprober.py +46 -0
  294. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/gb2312freq.py +283 -0
  295. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/gb2312prober.py +46 -0
  296. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/hebrewprober.py +292 -0
  297. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/jisfreq.py +325 -0
  298. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/jpcntx.py +233 -0
  299. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/langbulgarianmodel.py +228 -0
  300. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/langcyrillicmodel.py +333 -0
  301. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/langgreekmodel.py +225 -0
  302. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/langhebrewmodel.py +200 -0
  303. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/langhungarianmodel.py +225 -0
  304. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/langthaimodel.py +199 -0
  305. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/langturkishmodel.py +193 -0
  306. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/latin1prober.py +145 -0
  307. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/mbcharsetprober.py +91 -0
  308. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/mbcsgroupprober.py +54 -0
  309. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/mbcssm.py +572 -0
  310. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/sbcharsetprober.py +132 -0
  311. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/sbcsgroupprober.py +73 -0
  312. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/sjisprober.py +92 -0
  313. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/universaldetector.py +286 -0
  314. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/utf8prober.py +82 -0
  315. quarchpy/venv/Lib/site-packages/pip/_vendor/chardet/version.py +9 -0
  316. quarchpy/venv/Lib/site-packages/pip/_vendor/colorama/__init__.py +6 -0
  317. quarchpy/venv/Lib/site-packages/pip/_vendor/colorama/ansi.py +102 -0
  318. quarchpy/venv/Lib/site-packages/pip/_vendor/colorama/ansitowin32.py +258 -0
  319. quarchpy/venv/Lib/site-packages/pip/_vendor/colorama/initialise.py +80 -0
  320. quarchpy/venv/Lib/site-packages/pip/_vendor/colorama/win32.py +152 -0
  321. quarchpy/venv/Lib/site-packages/pip/_vendor/colorama/winterm.py +169 -0
  322. quarchpy/venv/Lib/site-packages/pip/_vendor/contextlib2.py +518 -0
  323. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/__init__.py +23 -0
  324. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/_backport/__init__.py +6 -0
  325. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/_backport/misc.py +41 -0
  326. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/_backport/shutil.py +764 -0
  327. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/_backport/sysconfig.cfg +84 -0
  328. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/_backport/sysconfig.py +786 -0
  329. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/_backport/tarfile.py +2607 -0
  330. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/compat.py +1120 -0
  331. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/database.py +1339 -0
  332. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/index.py +516 -0
  333. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/locators.py +1302 -0
  334. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/manifest.py +393 -0
  335. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/markers.py +131 -0
  336. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/metadata.py +1056 -0
  337. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/resources.py +355 -0
  338. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/scripts.py +419 -0
  339. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/t32.exe +0 -0
  340. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/t64.exe +0 -0
  341. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/util.py +1761 -0
  342. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/version.py +736 -0
  343. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/w32.exe +0 -0
  344. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/w64.exe +0 -0
  345. quarchpy/venv/Lib/site-packages/pip/_vendor/distlib/wheel.py +1018 -0
  346. quarchpy/venv/Lib/site-packages/pip/_vendor/distro.py +1230 -0
  347. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/__init__.py +35 -0
  348. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/_ihatexml.py +289 -0
  349. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/_inputstream.py +918 -0
  350. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/_tokenizer.py +1735 -0
  351. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/_trie/__init__.py +5 -0
  352. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/_trie/_base.py +40 -0
  353. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/_trie/py.py +67 -0
  354. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/_utils.py +159 -0
  355. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/constants.py +2946 -0
  356. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/filters/__init__.py +0 -0
  357. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/filters/alphabeticalattributes.py +29 -0
  358. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/filters/base.py +12 -0
  359. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/filters/inject_meta_charset.py +73 -0
  360. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/filters/lint.py +93 -0
  361. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/filters/optionaltags.py +207 -0
  362. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/filters/sanitizer.py +916 -0
  363. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/filters/whitespace.py +38 -0
  364. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/html5parser.py +2795 -0
  365. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/serializer.py +409 -0
  366. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treeadapters/__init__.py +30 -0
  367. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treeadapters/genshi.py +54 -0
  368. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treeadapters/sax.py +50 -0
  369. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treebuilders/__init__.py +88 -0
  370. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treebuilders/base.py +417 -0
  371. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treebuilders/dom.py +239 -0
  372. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treebuilders/etree.py +343 -0
  373. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.py +392 -0
  374. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treewalkers/__init__.py +154 -0
  375. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treewalkers/base.py +252 -0
  376. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treewalkers/dom.py +43 -0
  377. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treewalkers/etree.py +131 -0
  378. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treewalkers/etree_lxml.py +215 -0
  379. quarchpy/venv/Lib/site-packages/pip/_vendor/html5lib/treewalkers/genshi.py +69 -0
  380. quarchpy/venv/Lib/site-packages/pip/_vendor/idna/__init__.py +2 -0
  381. quarchpy/venv/Lib/site-packages/pip/_vendor/idna/codec.py +118 -0
  382. quarchpy/venv/Lib/site-packages/pip/_vendor/idna/compat.py +12 -0
  383. quarchpy/venv/Lib/site-packages/pip/_vendor/idna/core.py +400 -0
  384. quarchpy/venv/Lib/site-packages/pip/_vendor/idna/idnadata.py +2050 -0
  385. quarchpy/venv/Lib/site-packages/pip/_vendor/idna/intranges.py +53 -0
  386. quarchpy/venv/Lib/site-packages/pip/_vendor/idna/package_data.py +2 -0
  387. quarchpy/venv/Lib/site-packages/pip/_vendor/idna/uts46data.py +8357 -0
  388. quarchpy/venv/Lib/site-packages/pip/_vendor/ipaddress.py +2420 -0
  389. quarchpy/venv/Lib/site-packages/pip/_vendor/msgpack/__init__.py +54 -0
  390. quarchpy/venv/Lib/site-packages/pip/_vendor/msgpack/_version.py +1 -0
  391. quarchpy/venv/Lib/site-packages/pip/_vendor/msgpack/exceptions.py +48 -0
  392. quarchpy/venv/Lib/site-packages/pip/_vendor/msgpack/ext.py +191 -0
  393. quarchpy/venv/Lib/site-packages/pip/_vendor/msgpack/fallback.py +1063 -0
  394. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/__about__.py +27 -0
  395. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/__init__.py +26 -0
  396. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/_compat.py +38 -0
  397. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/_structures.py +86 -0
  398. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/_typing.py +48 -0
  399. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/markers.py +328 -0
  400. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/requirements.py +151 -0
  401. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/specifiers.py +864 -0
  402. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/tags.py +852 -0
  403. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/utils.py +67 -0
  404. quarchpy/venv/Lib/site-packages/pip/_vendor/packaging/version.py +556 -0
  405. quarchpy/venv/Lib/site-packages/pip/_vendor/pep517/__init__.py +6 -0
  406. quarchpy/venv/Lib/site-packages/pip/_vendor/pep517/_in_process.py +280 -0
  407. quarchpy/venv/Lib/site-packages/pip/_vendor/pep517/build.py +124 -0
  408. quarchpy/venv/Lib/site-packages/pip/_vendor/pep517/check.py +203 -0
  409. quarchpy/venv/Lib/site-packages/pip/_vendor/pep517/colorlog.py +115 -0
  410. quarchpy/venv/Lib/site-packages/pip/_vendor/pep517/compat.py +34 -0
  411. quarchpy/venv/Lib/site-packages/pip/_vendor/pep517/dirtools.py +44 -0
  412. quarchpy/venv/Lib/site-packages/pip/_vendor/pep517/envbuild.py +167 -0
  413. quarchpy/venv/Lib/site-packages/pip/_vendor/pep517/meta.py +92 -0
  414. quarchpy/venv/Lib/site-packages/pip/_vendor/pep517/wrappers.py +327 -0
  415. quarchpy/venv/Lib/site-packages/pip/_vendor/pkg_resources/__init__.py +3296 -0
  416. quarchpy/venv/Lib/site-packages/pip/_vendor/pkg_resources/py31compat.py +23 -0
  417. quarchpy/venv/Lib/site-packages/pip/_vendor/progress/__init__.py +177 -0
  418. quarchpy/venv/Lib/site-packages/pip/_vendor/progress/bar.py +91 -0
  419. quarchpy/venv/Lib/site-packages/pip/_vendor/progress/counter.py +41 -0
  420. quarchpy/venv/Lib/site-packages/pip/_vendor/progress/spinner.py +43 -0
  421. quarchpy/venv/Lib/site-packages/pip/_vendor/pyparsing.py +7107 -0
  422. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/__init__.py +144 -0
  423. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/__version__.py +14 -0
  424. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/_internal_utils.py +42 -0
  425. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/adapters.py +533 -0
  426. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/api.py +161 -0
  427. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/auth.py +305 -0
  428. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/certs.py +18 -0
  429. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/compat.py +76 -0
  430. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/cookies.py +549 -0
  431. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/exceptions.py +123 -0
  432. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/help.py +119 -0
  433. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/hooks.py +34 -0
  434. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/models.py +956 -0
  435. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/packages.py +16 -0
  436. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/sessions.py +781 -0
  437. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/status_codes.py +123 -0
  438. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/structures.py +105 -0
  439. quarchpy/venv/Lib/site-packages/pip/_vendor/requests/utils.py +988 -0
  440. quarchpy/venv/Lib/site-packages/pip/_vendor/resolvelib/__init__.py +26 -0
  441. quarchpy/venv/Lib/site-packages/pip/_vendor/resolvelib/compat/__init__.py +0 -0
  442. quarchpy/venv/Lib/site-packages/pip/_vendor/resolvelib/compat/collections_abc.py +6 -0
  443. quarchpy/venv/Lib/site-packages/pip/_vendor/resolvelib/providers.py +119 -0
  444. quarchpy/venv/Lib/site-packages/pip/_vendor/resolvelib/reporters.py +37 -0
  445. quarchpy/venv/Lib/site-packages/pip/_vendor/resolvelib/resolvers.py +454 -0
  446. quarchpy/venv/Lib/site-packages/pip/_vendor/resolvelib/structs.py +149 -0
  447. quarchpy/venv/Lib/site-packages/pip/_vendor/retrying.py +267 -0
  448. quarchpy/venv/Lib/site-packages/pip/_vendor/six.py +982 -0
  449. quarchpy/venv/Lib/site-packages/pip/_vendor/toml/__init__.py +25 -0
  450. quarchpy/venv/Lib/site-packages/pip/_vendor/toml/decoder.py +1057 -0
  451. quarchpy/venv/Lib/site-packages/pip/_vendor/toml/encoder.py +304 -0
  452. quarchpy/venv/Lib/site-packages/pip/_vendor/toml/ordered.py +15 -0
  453. quarchpy/venv/Lib/site-packages/pip/_vendor/toml/tz.py +24 -0
  454. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/__init__.py +85 -0
  455. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/_collections.py +337 -0
  456. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/_version.py +2 -0
  457. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/connection.py +535 -0
  458. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/connectionpool.py +1067 -0
  459. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/contrib/__init__.py +0 -0
  460. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/contrib/_appengine_environ.py +36 -0
  461. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/contrib/_securetransport/__init__.py +0 -0
  462. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/contrib/_securetransport/bindings.py +519 -0
  463. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.py +396 -0
  464. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/contrib/appengine.py +314 -0
  465. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/contrib/ntlmpool.py +121 -0
  466. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.py +509 -0
  467. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/contrib/securetransport.py +920 -0
  468. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/contrib/socks.py +216 -0
  469. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/exceptions.py +313 -0
  470. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/fields.py +274 -0
  471. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/filepost.py +98 -0
  472. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/packages/__init__.py +5 -0
  473. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/packages/backports/__init__.py +0 -0
  474. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/packages/backports/makefile.py +51 -0
  475. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/packages/six.py +1021 -0
  476. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/packages/ssl_match_hostname/__init__.py +22 -0
  477. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/packages/ssl_match_hostname/_implementation.py +160 -0
  478. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/poolmanager.py +536 -0
  479. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/request.py +170 -0
  480. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/response.py +821 -0
  481. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/__init__.py +49 -0
  482. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/connection.py +150 -0
  483. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/proxy.py +56 -0
  484. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/queue.py +22 -0
  485. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/request.py +143 -0
  486. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/response.py +107 -0
  487. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/retry.py +601 -0
  488. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/ssl_.py +474 -0
  489. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/ssltransport.py +221 -0
  490. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/timeout.py +268 -0
  491. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/url.py +430 -0
  492. quarchpy/venv/Lib/site-packages/pip/_vendor/urllib3/util/wait.py +153 -0
  493. quarchpy/venv/Lib/site-packages/pip/_vendor/vendor.txt +24 -0
  494. quarchpy/venv/Lib/site-packages/pip/_vendor/webencodings/__init__.py +342 -0
  495. quarchpy/venv/Lib/site-packages/pip/_vendor/webencodings/labels.py +231 -0
  496. quarchpy/venv/Lib/site-packages/pip/_vendor/webencodings/mklabels.py +59 -0
  497. quarchpy/venv/Lib/site-packages/pip/_vendor/webencodings/tests.py +153 -0
  498. quarchpy/venv/Lib/site-packages/pip/_vendor/webencodings/x_user_defined.py +325 -0
  499. quarchpy/venv/Lib/site-packages/pip-20.3.4.dist-info/INSTALLER +1 -0
  500. quarchpy/venv/Lib/site-packages/pip-20.3.4.dist-info/LICENSE.txt +20 -0
  501. quarchpy/venv/Lib/site-packages/pip-20.3.4.dist-info/METADATA +94 -0
  502. quarchpy/venv/Lib/site-packages/pip-20.3.4.dist-info/RECORD +812 -0
  503. quarchpy/venv/Lib/site-packages/pip-20.3.4.dist-info/WHEEL +6 -0
  504. quarchpy/venv/Lib/site-packages/pip-20.3.4.dist-info/entry_points.txt +5 -0
  505. quarchpy/venv/Lib/site-packages/pip-20.3.4.dist-info/top_level.txt +1 -0
  506. quarchpy/venv/Lib/site-packages/pip-20.3.4.virtualenv +0 -0
  507. quarchpy/venv/Lib/site-packages/pkg_resources/__init__.py +3296 -0
  508. quarchpy/venv/Lib/site-packages/pkg_resources/__init__.pyc +0 -0
  509. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/__init__.py +0 -0
  510. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/__init__.pyc +0 -0
  511. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/appdirs.py +608 -0
  512. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/appdirs.pyc +0 -0
  513. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/__about__.py +21 -0
  514. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/__about__.pyc +0 -0
  515. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/__init__.py +14 -0
  516. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/__init__.pyc +0 -0
  517. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/_compat.py +30 -0
  518. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/_compat.pyc +0 -0
  519. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/_structures.py +68 -0
  520. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/_structures.pyc +0 -0
  521. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/markers.py +301 -0
  522. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/markers.pyc +0 -0
  523. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/requirements.py +127 -0
  524. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/requirements.pyc +0 -0
  525. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/specifiers.py +774 -0
  526. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/specifiers.pyc +0 -0
  527. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/utils.py +14 -0
  528. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/version.py +393 -0
  529. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/packaging/version.pyc +0 -0
  530. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/pyparsing.py +5742 -0
  531. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/pyparsing.pyc +0 -0
  532. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/six.py +868 -0
  533. quarchpy/venv/Lib/site-packages/pkg_resources/_vendor/six.pyc +0 -0
  534. quarchpy/venv/Lib/site-packages/pkg_resources/extern/__init__.py +73 -0
  535. quarchpy/venv/Lib/site-packages/pkg_resources/extern/__init__.pyc +0 -0
  536. quarchpy/venv/Lib/site-packages/pkg_resources/py31compat.py +23 -0
  537. quarchpy/venv/Lib/site-packages/pkg_resources/py31compat.pyc +0 -0
  538. quarchpy/venv/Lib/site-packages/setuptools/__init__.py +245 -0
  539. quarchpy/venv/Lib/site-packages/setuptools/_deprecation_warning.py +7 -0
  540. quarchpy/venv/Lib/site-packages/setuptools/_imp.py +73 -0
  541. quarchpy/venv/Lib/site-packages/setuptools/_vendor/__init__.py +0 -0
  542. quarchpy/venv/Lib/site-packages/setuptools/_vendor/ordered_set.py +488 -0
  543. quarchpy/venv/Lib/site-packages/setuptools/_vendor/packaging/__about__.py +27 -0
  544. quarchpy/venv/Lib/site-packages/setuptools/_vendor/packaging/__init__.py +26 -0
  545. quarchpy/venv/Lib/site-packages/setuptools/_vendor/packaging/_compat.py +31 -0
  546. quarchpy/venv/Lib/site-packages/setuptools/_vendor/packaging/_structures.py +68 -0
  547. quarchpy/venv/Lib/site-packages/setuptools/_vendor/packaging/markers.py +296 -0
  548. quarchpy/venv/Lib/site-packages/setuptools/_vendor/packaging/requirements.py +138 -0
  549. quarchpy/venv/Lib/site-packages/setuptools/_vendor/packaging/specifiers.py +749 -0
  550. quarchpy/venv/Lib/site-packages/setuptools/_vendor/packaging/tags.py +404 -0
  551. quarchpy/venv/Lib/site-packages/setuptools/_vendor/packaging/utils.py +57 -0
  552. quarchpy/venv/Lib/site-packages/setuptools/_vendor/packaging/version.py +420 -0
  553. quarchpy/venv/Lib/site-packages/setuptools/_vendor/pyparsing.py +5742 -0
  554. quarchpy/venv/Lib/site-packages/setuptools/_vendor/six.py +868 -0
  555. quarchpy/venv/Lib/site-packages/setuptools/archive_util.py +173 -0
  556. quarchpy/venv/Lib/site-packages/setuptools/build_meta.py +264 -0
  557. quarchpy/venv/Lib/site-packages/setuptools/cli-32.exe +0 -0
  558. quarchpy/venv/Lib/site-packages/setuptools/cli-64.exe +0 -0
  559. quarchpy/venv/Lib/site-packages/setuptools/cli.exe +0 -0
  560. quarchpy/venv/Lib/site-packages/setuptools/command/__init__.py +17 -0
  561. quarchpy/venv/Lib/site-packages/setuptools/command/alias.py +80 -0
  562. quarchpy/venv/Lib/site-packages/setuptools/command/bdist_egg.py +502 -0
  563. quarchpy/venv/Lib/site-packages/setuptools/command/bdist_rpm.py +43 -0
  564. quarchpy/venv/Lib/site-packages/setuptools/command/bdist_wininst.py +21 -0
  565. quarchpy/venv/Lib/site-packages/setuptools/command/build_clib.py +98 -0
  566. quarchpy/venv/Lib/site-packages/setuptools/command/build_ext.py +327 -0
  567. quarchpy/venv/Lib/site-packages/setuptools/command/build_py.py +270 -0
  568. quarchpy/venv/Lib/site-packages/setuptools/command/develop.py +221 -0
  569. quarchpy/venv/Lib/site-packages/setuptools/command/dist_info.py +36 -0
  570. quarchpy/venv/Lib/site-packages/setuptools/command/easy_install.py +2347 -0
  571. quarchpy/venv/Lib/site-packages/setuptools/command/egg_info.py +717 -0
  572. quarchpy/venv/Lib/site-packages/setuptools/command/install.py +125 -0
  573. quarchpy/venv/Lib/site-packages/setuptools/command/install_egg_info.py +62 -0
  574. quarchpy/venv/Lib/site-packages/setuptools/command/install_lib.py +121 -0
  575. quarchpy/venv/Lib/site-packages/setuptools/command/install_scripts.py +65 -0
  576. quarchpy/venv/Lib/site-packages/setuptools/command/launcher manifest.xml +15 -0
  577. quarchpy/venv/Lib/site-packages/setuptools/command/py36compat.py +136 -0
  578. quarchpy/venv/Lib/site-packages/setuptools/command/register.py +18 -0
  579. quarchpy/venv/Lib/site-packages/setuptools/command/rotate.py +66 -0
  580. quarchpy/venv/Lib/site-packages/setuptools/command/saveopts.py +22 -0
  581. quarchpy/venv/Lib/site-packages/setuptools/command/sdist.py +252 -0
  582. quarchpy/venv/Lib/site-packages/setuptools/command/setopt.py +149 -0
  583. quarchpy/venv/Lib/site-packages/setuptools/command/test.py +279 -0
  584. quarchpy/venv/Lib/site-packages/setuptools/command/upload.py +17 -0
  585. quarchpy/venv/Lib/site-packages/setuptools/command/upload_docs.py +206 -0
  586. quarchpy/venv/Lib/site-packages/setuptools/config.py +659 -0
  587. quarchpy/venv/Lib/site-packages/setuptools/dep_util.py +23 -0
  588. quarchpy/venv/Lib/site-packages/setuptools/depends.py +176 -0
  589. quarchpy/venv/Lib/site-packages/setuptools/dist.py +1274 -0
  590. quarchpy/venv/Lib/site-packages/setuptools/errors.py +16 -0
  591. quarchpy/venv/Lib/site-packages/setuptools/extension.py +57 -0
  592. quarchpy/venv/Lib/site-packages/setuptools/extern/__init__.py +73 -0
  593. quarchpy/venv/Lib/site-packages/setuptools/glob.py +174 -0
  594. quarchpy/venv/Lib/site-packages/setuptools/gui-32.exe +0 -0
  595. quarchpy/venv/Lib/site-packages/setuptools/gui-64.exe +0 -0
  596. quarchpy/venv/Lib/site-packages/setuptools/gui.exe +0 -0
  597. quarchpy/venv/Lib/site-packages/setuptools/installer.py +150 -0
  598. quarchpy/venv/Lib/site-packages/setuptools/launch.py +35 -0
  599. quarchpy/venv/Lib/site-packages/setuptools/lib2to3_ex.py +62 -0
  600. quarchpy/venv/Lib/site-packages/setuptools/monkey.py +179 -0
  601. quarchpy/venv/Lib/site-packages/setuptools/msvc.py +1679 -0
  602. quarchpy/venv/Lib/site-packages/setuptools/namespaces.py +107 -0
  603. quarchpy/venv/Lib/site-packages/setuptools/package_index.py +1136 -0
  604. quarchpy/venv/Lib/site-packages/setuptools/py27compat.py +60 -0
  605. quarchpy/venv/Lib/site-packages/setuptools/py31compat.py +32 -0
  606. quarchpy/venv/Lib/site-packages/setuptools/py33compat.py +59 -0
  607. quarchpy/venv/Lib/site-packages/setuptools/py34compat.py +13 -0
  608. quarchpy/venv/Lib/site-packages/setuptools/sandbox.py +491 -0
  609. quarchpy/venv/Lib/site-packages/setuptools/script (dev).tmpl +6 -0
  610. quarchpy/venv/Lib/site-packages/setuptools/script.tmpl +3 -0
  611. quarchpy/venv/Lib/site-packages/setuptools/site-patch.py +74 -0
  612. quarchpy/venv/Lib/site-packages/setuptools/ssl_support.py +260 -0
  613. quarchpy/venv/Lib/site-packages/setuptools/unicode_utils.py +44 -0
  614. quarchpy/venv/Lib/site-packages/setuptools/version.py +6 -0
  615. quarchpy/venv/Lib/site-packages/setuptools/wheel.py +220 -0
  616. quarchpy/venv/Lib/site-packages/setuptools/windows_support.py +29 -0
  617. quarchpy/venv/Lib/site-packages/setuptools-44.1.1.dist-info/INSTALLER +1 -0
  618. quarchpy/venv/Lib/site-packages/setuptools-44.1.1.dist-info/LICENSE +19 -0
  619. quarchpy/venv/Lib/site-packages/setuptools-44.1.1.dist-info/METADATA +86 -0
  620. quarchpy/venv/Lib/site-packages/setuptools-44.1.1.dist-info/RECORD +207 -0
  621. quarchpy/venv/Lib/site-packages/setuptools-44.1.1.dist-info/WHEEL +6 -0
  622. quarchpy/venv/Lib/site-packages/setuptools-44.1.1.dist-info/dependency_links.txt +2 -0
  623. quarchpy/venv/Lib/site-packages/setuptools-44.1.1.dist-info/entry_points.txt +69 -0
  624. quarchpy/venv/Lib/site-packages/setuptools-44.1.1.dist-info/top_level.txt +3 -0
  625. quarchpy/venv/Lib/site-packages/setuptools-44.1.1.dist-info/zip-safe +1 -0
  626. quarchpy/venv/Lib/site-packages/setuptools-44.1.1.virtualenv +0 -0
  627. quarchpy/venv/Lib/site-packages/wheel/__init__.py +1 -0
  628. quarchpy/venv/Lib/site-packages/wheel/__main__.py +19 -0
  629. quarchpy/venv/Lib/site-packages/wheel/bdist_wheel.py +492 -0
  630. quarchpy/venv/Lib/site-packages/wheel/cli/__init__.py +88 -0
  631. quarchpy/venv/Lib/site-packages/wheel/cli/convert.py +269 -0
  632. quarchpy/venv/Lib/site-packages/wheel/cli/pack.py +82 -0
  633. quarchpy/venv/Lib/site-packages/wheel/cli/unpack.py +25 -0
  634. quarchpy/venv/Lib/site-packages/wheel/macosx_libfile.py +428 -0
  635. quarchpy/venv/Lib/site-packages/wheel/metadata.py +133 -0
  636. quarchpy/venv/Lib/site-packages/wheel/pkginfo.py +43 -0
  637. quarchpy/venv/Lib/site-packages/wheel/util.py +46 -0
  638. quarchpy/venv/Lib/site-packages/wheel/vendored/__init__.py +0 -0
  639. quarchpy/venv/Lib/site-packages/wheel/vendored/packaging/__init__.py +0 -0
  640. quarchpy/venv/Lib/site-packages/wheel/vendored/packaging/_typing.py +48 -0
  641. quarchpy/venv/Lib/site-packages/wheel/vendored/packaging/tags.py +866 -0
  642. quarchpy/venv/Lib/site-packages/wheel/wheelfile.py +181 -0
  643. quarchpy/venv/Lib/site-packages/wheel-0.37.1.dist-info/INSTALLER +1 -0
  644. quarchpy/venv/Lib/site-packages/wheel-0.37.1.dist-info/LICENSE.txt +22 -0
  645. quarchpy/venv/Lib/site-packages/wheel-0.37.1.dist-info/METADATA +69 -0
  646. quarchpy/venv/Lib/site-packages/wheel-0.37.1.dist-info/RECORD +49 -0
  647. quarchpy/venv/Lib/site-packages/wheel-0.37.1.dist-info/WHEEL +6 -0
  648. quarchpy/venv/Lib/site-packages/wheel-0.37.1.dist-info/entry_points.txt +6 -0
  649. quarchpy/venv/Lib/site-packages/wheel-0.37.1.dist-info/top_level.txt +1 -0
  650. quarchpy/venv/Lib/site-packages/wheel-0.37.1.virtualenv +0 -0
  651. quarchpy/venv/Lib/site.py +190 -0
  652. quarchpy/venv/Lib/site.pyc +0 -0
  653. quarchpy/venv/Scripts/activate +83 -0
  654. quarchpy/venv/Scripts/activate.bat +39 -0
  655. quarchpy/venv/Scripts/activate.fish +100 -0
  656. quarchpy/venv/Scripts/activate.nu +41 -0
  657. quarchpy/venv/Scripts/activate.ps1 +60 -0
  658. quarchpy/venv/Scripts/activate_this.py +32 -0
  659. quarchpy/venv/Scripts/deactivate.bat +19 -0
  660. quarchpy/venv/Scripts/deactivate.nu +11 -0
  661. quarchpy/venv/Scripts/easy_install-2.7.exe +0 -0
  662. quarchpy/venv/Scripts/easy_install.exe +0 -0
  663. quarchpy/venv/Scripts/easy_install2.7.exe +0 -0
  664. quarchpy/venv/Scripts/easy_install2.exe +0 -0
  665. quarchpy/venv/Scripts/pip-2.7.exe +0 -0
  666. quarchpy/venv/Scripts/pip.exe +0 -0
  667. quarchpy/venv/Scripts/pip2.7.exe +0 -0
  668. quarchpy/venv/Scripts/pip2.exe +0 -0
  669. quarchpy/venv/Scripts/pydoc.bat +1 -0
  670. quarchpy/venv/Scripts/python.exe +0 -0
  671. quarchpy/venv/Scripts/python27.dll +0 -0
  672. quarchpy/venv/Scripts/pythonw.exe +0 -0
  673. quarchpy/venv/Scripts/wheel-2.7.exe +0 -0
  674. quarchpy/venv/Scripts/wheel.exe +0 -0
  675. quarchpy/venv/Scripts/wheel2.7.exe +0 -0
  676. quarchpy/venv/Scripts/wheel2.exe +0 -0
  677. quarchpy/venv/libs/_bsddb.lib +0 -0
  678. quarchpy/venv/libs/_ctypes.lib +0 -0
  679. quarchpy/venv/libs/_ctypes_test.lib +0 -0
  680. quarchpy/venv/libs/_elementtree.lib +0 -0
  681. quarchpy/venv/libs/_hashlib.lib +0 -0
  682. quarchpy/venv/libs/_msi.lib +0 -0
  683. quarchpy/venv/libs/_multiprocessing.lib +0 -0
  684. quarchpy/venv/libs/_socket.lib +0 -0
  685. quarchpy/venv/libs/_sqlite3.lib +0 -0
  686. quarchpy/venv/libs/_ssl.lib +0 -0
  687. quarchpy/venv/libs/_testcapi.lib +0 -0
  688. quarchpy/venv/libs/_tkinter.lib +0 -0
  689. quarchpy/venv/libs/bz2.lib +0 -0
  690. quarchpy/venv/libs/libpython27.a +0 -0
  691. quarchpy/venv/libs/pyexpat.lib +0 -0
  692. quarchpy/venv/libs/python27.lib +0 -0
  693. quarchpy/venv/libs/select.lib +0 -0
  694. quarchpy/venv/libs/unicodedata.lib +0 -0
  695. quarchpy/venv/libs/winsound.lib +0 -0
  696. quarchpy/venv/pyvenv.cfg +8 -0
  697. {quarchpy-2.1.14.dev3.dist-info → quarchpy-2.1.14.dev5.dist-info}/METADATA +1 -1
  698. quarchpy-2.1.14.dev5.dist-info/RECORD +1219 -0
  699. quarchpy-2.1.14.dev3.dist-info/RECORD +0 -535
  700. {quarchpy-2.1.14.dev3.dist-info → quarchpy-2.1.14.dev5.dist-info}/WHEEL +0 -0
  701. {quarchpy-2.1.14.dev3.dist-info → quarchpy-2.1.14.dev5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,2607 @@
1
+ #-------------------------------------------------------------------
2
+ # tarfile.py
3
+ #-------------------------------------------------------------------
4
+ # Copyright (C) 2002 Lars Gustaebel <lars@gustaebel.de>
5
+ # All rights reserved.
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person
8
+ # obtaining a copy of this software and associated documentation
9
+ # files (the "Software"), to deal in the Software without
10
+ # restriction, including without limitation the rights to use,
11
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the
13
+ # Software is furnished to do so, subject to the following
14
+ # conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be
17
+ # included in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26
+ # OTHER DEALINGS IN THE SOFTWARE.
27
+ #
28
+ from __future__ import print_function
29
+
30
+ """Read from and write to tar format archives.
31
+ """
32
+
33
+ __version__ = "$Revision$"
34
+
35
+ version = "0.9.0"
36
+ __author__ = "Lars Gust\u00e4bel (lars@gustaebel.de)"
37
+ __date__ = "$Date: 2011-02-25 17:42:01 +0200 (Fri, 25 Feb 2011) $"
38
+ __cvsid__ = "$Id: tarfile.py 88586 2011-02-25 15:42:01Z marc-andre.lemburg $"
39
+ __credits__ = "Gustavo Niemeyer, Niels Gust\u00e4bel, Richard Townsend."
40
+
41
+ #---------
42
+ # Imports
43
+ #---------
44
+ import sys
45
+ import os
46
+ import stat
47
+ import errno
48
+ import time
49
+ import struct
50
+ import copy
51
+ import re
52
+
53
+ try:
54
+ import grp, pwd
55
+ except ImportError:
56
+ grp = pwd = None
57
+
58
+ # os.symlink on Windows prior to 6.0 raises NotImplementedError
59
+ symlink_exception = (AttributeError, NotImplementedError)
60
+ try:
61
+ # WindowsError (1314) will be raised if the caller does not hold the
62
+ # SeCreateSymbolicLinkPrivilege privilege
63
+ symlink_exception += (WindowsError,)
64
+ except NameError:
65
+ pass
66
+
67
+ # from tarfile import *
68
+ __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]
69
+
70
+ if sys.version_info[0] < 3:
71
+ import __builtin__ as builtins
72
+ else:
73
+ import builtins
74
+
75
+ _open = builtins.open # Since 'open' is TarFile.open
76
+
77
+ #---------------------------------------------------------
78
+ # tar constants
79
+ #---------------------------------------------------------
80
+ NUL = b"\0" # the null character
81
+ BLOCKSIZE = 512 # length of processing blocks
82
+ RECORDSIZE = BLOCKSIZE * 20 # length of records
83
+ GNU_MAGIC = b"ustar \0" # magic gnu tar string
84
+ POSIX_MAGIC = b"ustar\x0000" # magic posix tar string
85
+
86
+ LENGTH_NAME = 100 # maximum length of a filename
87
+ LENGTH_LINK = 100 # maximum length of a linkname
88
+ LENGTH_PREFIX = 155 # maximum length of the prefix field
89
+
90
+ REGTYPE = b"0" # regular file
91
+ AREGTYPE = b"\0" # regular file
92
+ LNKTYPE = b"1" # link (inside tarfile)
93
+ SYMTYPE = b"2" # symbolic link
94
+ CHRTYPE = b"3" # character special device
95
+ BLKTYPE = b"4" # block special device
96
+ DIRTYPE = b"5" # directory
97
+ FIFOTYPE = b"6" # fifo special device
98
+ CONTTYPE = b"7" # contiguous file
99
+
100
+ GNUTYPE_LONGNAME = b"L" # GNU tar longname
101
+ GNUTYPE_LONGLINK = b"K" # GNU tar longlink
102
+ GNUTYPE_SPARSE = b"S" # GNU tar sparse file
103
+
104
+ XHDTYPE = b"x" # POSIX.1-2001 extended header
105
+ XGLTYPE = b"g" # POSIX.1-2001 global header
106
+ SOLARIS_XHDTYPE = b"X" # Solaris extended header
107
+
108
+ USTAR_FORMAT = 0 # POSIX.1-1988 (ustar) format
109
+ GNU_FORMAT = 1 # GNU tar format
110
+ PAX_FORMAT = 2 # POSIX.1-2001 (pax) format
111
+ DEFAULT_FORMAT = GNU_FORMAT
112
+
113
+ #---------------------------------------------------------
114
+ # tarfile constants
115
+ #---------------------------------------------------------
116
+ # File types that tarfile supports:
117
+ SUPPORTED_TYPES = (REGTYPE, AREGTYPE, LNKTYPE,
118
+ SYMTYPE, DIRTYPE, FIFOTYPE,
119
+ CONTTYPE, CHRTYPE, BLKTYPE,
120
+ GNUTYPE_LONGNAME, GNUTYPE_LONGLINK,
121
+ GNUTYPE_SPARSE)
122
+
123
+ # File types that will be treated as a regular file.
124
+ REGULAR_TYPES = (REGTYPE, AREGTYPE,
125
+ CONTTYPE, GNUTYPE_SPARSE)
126
+
127
+ # File types that are part of the GNU tar format.
128
+ GNU_TYPES = (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK,
129
+ GNUTYPE_SPARSE)
130
+
131
+ # Fields from a pax header that override a TarInfo attribute.
132
+ PAX_FIELDS = ("path", "linkpath", "size", "mtime",
133
+ "uid", "gid", "uname", "gname")
134
+
135
+ # Fields from a pax header that are affected by hdrcharset.
136
+ PAX_NAME_FIELDS = set(("path", "linkpath", "uname", "gname"))
137
+
138
+ # Fields in a pax header that are numbers, all other fields
139
+ # are treated as strings.
140
+ PAX_NUMBER_FIELDS = {
141
+ "atime": float,
142
+ "ctime": float,
143
+ "mtime": float,
144
+ "uid": int,
145
+ "gid": int,
146
+ "size": int
147
+ }
148
+
149
+ #---------------------------------------------------------
150
+ # Bits used in the mode field, values in octal.
151
+ #---------------------------------------------------------
152
+ S_IFLNK = 0o120000 # symbolic link
153
+ S_IFREG = 0o100000 # regular file
154
+ S_IFBLK = 0o060000 # block device
155
+ S_IFDIR = 0o040000 # directory
156
+ S_IFCHR = 0o020000 # character device
157
+ S_IFIFO = 0o010000 # fifo
158
+
159
+ TSUID = 0o4000 # set UID on execution
160
+ TSGID = 0o2000 # set GID on execution
161
+ TSVTX = 0o1000 # reserved
162
+
163
+ TUREAD = 0o400 # read by owner
164
+ TUWRITE = 0o200 # write by owner
165
+ TUEXEC = 0o100 # execute/search by owner
166
+ TGREAD = 0o040 # read by group
167
+ TGWRITE = 0o020 # write by group
168
+ TGEXEC = 0o010 # execute/search by group
169
+ TOREAD = 0o004 # read by other
170
+ TOWRITE = 0o002 # write by other
171
+ TOEXEC = 0o001 # execute/search by other
172
+
173
+ #---------------------------------------------------------
174
+ # initialization
175
+ #---------------------------------------------------------
176
+ if os.name in ("nt", "ce"):
177
+ ENCODING = "utf-8"
178
+ else:
179
+ ENCODING = sys.getfilesystemencoding()
180
+
181
+ #---------------------------------------------------------
182
+ # Some useful functions
183
+ #---------------------------------------------------------
184
+
185
+ def stn(s, length, encoding, errors):
186
+ """Convert a string to a null-terminated bytes object.
187
+ """
188
+ s = s.encode(encoding, errors)
189
+ return s[:length] + (length - len(s)) * NUL
190
+
191
+ def nts(s, encoding, errors):
192
+ """Convert a null-terminated bytes object to a string.
193
+ """
194
+ p = s.find(b"\0")
195
+ if p != -1:
196
+ s = s[:p]
197
+ return s.decode(encoding, errors)
198
+
199
+ def nti(s):
200
+ """Convert a number field to a python number.
201
+ """
202
+ # There are two possible encodings for a number field, see
203
+ # itn() below.
204
+ if s[0] != chr(0o200):
205
+ try:
206
+ n = int(nts(s, "ascii", "strict") or "0", 8)
207
+ except ValueError:
208
+ raise InvalidHeaderError("invalid header")
209
+ else:
210
+ n = 0
211
+ for i in range(len(s) - 1):
212
+ n <<= 8
213
+ n += ord(s[i + 1])
214
+ return n
215
+
216
+ def itn(n, digits=8, format=DEFAULT_FORMAT):
217
+ """Convert a python number to a number field.
218
+ """
219
+ # POSIX 1003.1-1988 requires numbers to be encoded as a string of
220
+ # octal digits followed by a null-byte, this allows values up to
221
+ # (8**(digits-1))-1. GNU tar allows storing numbers greater than
222
+ # that if necessary. A leading 0o200 byte indicates this particular
223
+ # encoding, the following digits-1 bytes are a big-endian
224
+ # representation. This allows values up to (256**(digits-1))-1.
225
+ if 0 <= n < 8 ** (digits - 1):
226
+ s = ("%0*o" % (digits - 1, n)).encode("ascii") + NUL
227
+ else:
228
+ if format != GNU_FORMAT or n >= 256 ** (digits - 1):
229
+ raise ValueError("overflow in number field")
230
+
231
+ if n < 0:
232
+ # XXX We mimic GNU tar's behaviour with negative numbers,
233
+ # this could raise OverflowError.
234
+ n = struct.unpack("L", struct.pack("l", n))[0]
235
+
236
+ s = bytearray()
237
+ for i in range(digits - 1):
238
+ s.insert(0, n & 0o377)
239
+ n >>= 8
240
+ s.insert(0, 0o200)
241
+ return s
242
+
243
+ def calc_chksums(buf):
244
+ """Calculate the checksum for a member's header by summing up all
245
+ characters except for the chksum field which is treated as if
246
+ it was filled with spaces. According to the GNU tar sources,
247
+ some tars (Sun and NeXT) calculate chksum with signed char,
248
+ which will be different if there are chars in the buffer with
249
+ the high bit set. So we calculate two checksums, unsigned and
250
+ signed.
251
+ """
252
+ unsigned_chksum = 256 + sum(struct.unpack("148B", buf[:148]) + struct.unpack("356B", buf[156:512]))
253
+ signed_chksum = 256 + sum(struct.unpack("148b", buf[:148]) + struct.unpack("356b", buf[156:512]))
254
+ return unsigned_chksum, signed_chksum
255
+
256
+ def copyfileobj(src, dst, length=None):
257
+ """Copy length bytes from fileobj src to fileobj dst.
258
+ If length is None, copy the entire content.
259
+ """
260
+ if length == 0:
261
+ return
262
+ if length is None:
263
+ while True:
264
+ buf = src.read(16*1024)
265
+ if not buf:
266
+ break
267
+ dst.write(buf)
268
+ return
269
+
270
+ BUFSIZE = 16 * 1024
271
+ blocks, remainder = divmod(length, BUFSIZE)
272
+ for b in range(blocks):
273
+ buf = src.read(BUFSIZE)
274
+ if len(buf) < BUFSIZE:
275
+ raise IOError("end of file reached")
276
+ dst.write(buf)
277
+
278
+ if remainder != 0:
279
+ buf = src.read(remainder)
280
+ if len(buf) < remainder:
281
+ raise IOError("end of file reached")
282
+ dst.write(buf)
283
+ return
284
+
285
+ filemode_table = (
286
+ ((S_IFLNK, "l"),
287
+ (S_IFREG, "-"),
288
+ (S_IFBLK, "b"),
289
+ (S_IFDIR, "d"),
290
+ (S_IFCHR, "c"),
291
+ (S_IFIFO, "p")),
292
+
293
+ ((TUREAD, "r"),),
294
+ ((TUWRITE, "w"),),
295
+ ((TUEXEC|TSUID, "s"),
296
+ (TSUID, "S"),
297
+ (TUEXEC, "x")),
298
+
299
+ ((TGREAD, "r"),),
300
+ ((TGWRITE, "w"),),
301
+ ((TGEXEC|TSGID, "s"),
302
+ (TSGID, "S"),
303
+ (TGEXEC, "x")),
304
+
305
+ ((TOREAD, "r"),),
306
+ ((TOWRITE, "w"),),
307
+ ((TOEXEC|TSVTX, "t"),
308
+ (TSVTX, "T"),
309
+ (TOEXEC, "x"))
310
+ )
311
+
312
+ def filemode(mode):
313
+ """Convert a file's mode to a string of the form
314
+ -rwxrwxrwx.
315
+ Used by TarFile.list()
316
+ """
317
+ perm = []
318
+ for table in filemode_table:
319
+ for bit, char in table:
320
+ if mode & bit == bit:
321
+ perm.append(char)
322
+ break
323
+ else:
324
+ perm.append("-")
325
+ return "".join(perm)
326
+
327
+ class TarError(Exception):
328
+ """Base exception."""
329
+ pass
330
+ class ExtractError(TarError):
331
+ """General exception for extract errors."""
332
+ pass
333
+ class ReadError(TarError):
334
+ """Exception for unreadable tar archives."""
335
+ pass
336
+ class CompressionError(TarError):
337
+ """Exception for unavailable compression methods."""
338
+ pass
339
+ class StreamError(TarError):
340
+ """Exception for unsupported operations on stream-like TarFiles."""
341
+ pass
342
+ class HeaderError(TarError):
343
+ """Base exception for header errors."""
344
+ pass
345
+ class EmptyHeaderError(HeaderError):
346
+ """Exception for empty headers."""
347
+ pass
348
+ class TruncatedHeaderError(HeaderError):
349
+ """Exception for truncated headers."""
350
+ pass
351
+ class EOFHeaderError(HeaderError):
352
+ """Exception for end of file headers."""
353
+ pass
354
+ class InvalidHeaderError(HeaderError):
355
+ """Exception for invalid headers."""
356
+ pass
357
+ class SubsequentHeaderError(HeaderError):
358
+ """Exception for missing and invalid extended headers."""
359
+ pass
360
+
361
+ #---------------------------
362
+ # internal stream interface
363
+ #---------------------------
364
+ class _LowLevelFile(object):
365
+ """Low-level file object. Supports reading and writing.
366
+ It is used instead of a regular file object for streaming
367
+ access.
368
+ """
369
+
370
+ def __init__(self, name, mode):
371
+ mode = {
372
+ "r": os.O_RDONLY,
373
+ "w": os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
374
+ }[mode]
375
+ if hasattr(os, "O_BINARY"):
376
+ mode |= os.O_BINARY
377
+ self.fd = os.open(name, mode, 0o666)
378
+
379
+ def close(self):
380
+ os.close(self.fd)
381
+
382
+ def read(self, size):
383
+ return os.read(self.fd, size)
384
+
385
+ def write(self, s):
386
+ os.write(self.fd, s)
387
+
388
+ class _Stream(object):
389
+ """Class that serves as an adapter between TarFile and
390
+ a stream-like object. The stream-like object only
391
+ needs to have a read() or write() method and is accessed
392
+ blockwise. Use of gzip or bzip2 compression is possible.
393
+ A stream-like object could be for example: sys.stdin,
394
+ sys.stdout, a socket, a tape device etc.
395
+
396
+ _Stream is intended to be used only internally.
397
+ """
398
+
399
+ def __init__(self, name, mode, comptype, fileobj, bufsize):
400
+ """Construct a _Stream object.
401
+ """
402
+ self._extfileobj = True
403
+ if fileobj is None:
404
+ fileobj = _LowLevelFile(name, mode)
405
+ self._extfileobj = False
406
+
407
+ if comptype == '*':
408
+ # Enable transparent compression detection for the
409
+ # stream interface
410
+ fileobj = _StreamProxy(fileobj)
411
+ comptype = fileobj.getcomptype()
412
+
413
+ self.name = name or ""
414
+ self.mode = mode
415
+ self.comptype = comptype
416
+ self.fileobj = fileobj
417
+ self.bufsize = bufsize
418
+ self.buf = b""
419
+ self.pos = 0
420
+ self.closed = False
421
+
422
+ try:
423
+ if comptype == "gz":
424
+ try:
425
+ import zlib
426
+ except ImportError:
427
+ raise CompressionError("zlib module is not available")
428
+ self.zlib = zlib
429
+ self.crc = zlib.crc32(b"")
430
+ if mode == "r":
431
+ self._init_read_gz()
432
+ else:
433
+ self._init_write_gz()
434
+
435
+ if comptype == "bz2":
436
+ try:
437
+ import bz2
438
+ except ImportError:
439
+ raise CompressionError("bz2 module is not available")
440
+ if mode == "r":
441
+ self.dbuf = b""
442
+ self.cmp = bz2.BZ2Decompressor()
443
+ else:
444
+ self.cmp = bz2.BZ2Compressor()
445
+ except:
446
+ if not self._extfileobj:
447
+ self.fileobj.close()
448
+ self.closed = True
449
+ raise
450
+
451
+ def __del__(self):
452
+ if hasattr(self, "closed") and not self.closed:
453
+ self.close()
454
+
455
+ def _init_write_gz(self):
456
+ """Initialize for writing with gzip compression.
457
+ """
458
+ self.cmp = self.zlib.compressobj(9, self.zlib.DEFLATED,
459
+ -self.zlib.MAX_WBITS,
460
+ self.zlib.DEF_MEM_LEVEL,
461
+ 0)
462
+ timestamp = struct.pack("<L", int(time.time()))
463
+ self.__write(b"\037\213\010\010" + timestamp + b"\002\377")
464
+ if self.name.endswith(".gz"):
465
+ self.name = self.name[:-3]
466
+ # RFC1952 says we must use ISO-8859-1 for the FNAME field.
467
+ self.__write(self.name.encode("iso-8859-1", "replace") + NUL)
468
+
469
+ def write(self, s):
470
+ """Write string s to the stream.
471
+ """
472
+ if self.comptype == "gz":
473
+ self.crc = self.zlib.crc32(s, self.crc)
474
+ self.pos += len(s)
475
+ if self.comptype != "tar":
476
+ s = self.cmp.compress(s)
477
+ self.__write(s)
478
+
479
+ def __write(self, s):
480
+ """Write string s to the stream if a whole new block
481
+ is ready to be written.
482
+ """
483
+ self.buf += s
484
+ while len(self.buf) > self.bufsize:
485
+ self.fileobj.write(self.buf[:self.bufsize])
486
+ self.buf = self.buf[self.bufsize:]
487
+
488
+ def close(self):
489
+ """Close the _Stream object. No operation should be
490
+ done on it afterwards.
491
+ """
492
+ if self.closed:
493
+ return
494
+
495
+ if self.mode == "w" and self.comptype != "tar":
496
+ self.buf += self.cmp.flush()
497
+
498
+ if self.mode == "w" and self.buf:
499
+ self.fileobj.write(self.buf)
500
+ self.buf = b""
501
+ if self.comptype == "gz":
502
+ # The native zlib crc is an unsigned 32-bit integer, but
503
+ # the Python wrapper implicitly casts that to a signed C
504
+ # long. So, on a 32-bit box self.crc may "look negative",
505
+ # while the same crc on a 64-bit box may "look positive".
506
+ # To avoid irksome warnings from the `struct` module, force
507
+ # it to look positive on all boxes.
508
+ self.fileobj.write(struct.pack("<L", self.crc & 0xffffffff))
509
+ self.fileobj.write(struct.pack("<L", self.pos & 0xffffFFFF))
510
+
511
+ if not self._extfileobj:
512
+ self.fileobj.close()
513
+
514
+ self.closed = True
515
+
516
+ def _init_read_gz(self):
517
+ """Initialize for reading a gzip compressed fileobj.
518
+ """
519
+ self.cmp = self.zlib.decompressobj(-self.zlib.MAX_WBITS)
520
+ self.dbuf = b""
521
+
522
+ # taken from gzip.GzipFile with some alterations
523
+ if self.__read(2) != b"\037\213":
524
+ raise ReadError("not a gzip file")
525
+ if self.__read(1) != b"\010":
526
+ raise CompressionError("unsupported compression method")
527
+
528
+ flag = ord(self.__read(1))
529
+ self.__read(6)
530
+
531
+ if flag & 4:
532
+ xlen = ord(self.__read(1)) + 256 * ord(self.__read(1))
533
+ self.read(xlen)
534
+ if flag & 8:
535
+ while True:
536
+ s = self.__read(1)
537
+ if not s or s == NUL:
538
+ break
539
+ if flag & 16:
540
+ while True:
541
+ s = self.__read(1)
542
+ if not s or s == NUL:
543
+ break
544
+ if flag & 2:
545
+ self.__read(2)
546
+
547
+ def tell(self):
548
+ """Return the stream's file pointer position.
549
+ """
550
+ return self.pos
551
+
552
+ def seek(self, pos=0):
553
+ """Set the stream's file pointer to pos. Negative seeking
554
+ is forbidden.
555
+ """
556
+ if pos - self.pos >= 0:
557
+ blocks, remainder = divmod(pos - self.pos, self.bufsize)
558
+ for i in range(blocks):
559
+ self.read(self.bufsize)
560
+ self.read(remainder)
561
+ else:
562
+ raise StreamError("seeking backwards is not allowed")
563
+ return self.pos
564
+
565
+ def read(self, size=None):
566
+ """Return the next size number of bytes from the stream.
567
+ If size is not defined, return all bytes of the stream
568
+ up to EOF.
569
+ """
570
+ if size is None:
571
+ t = []
572
+ while True:
573
+ buf = self._read(self.bufsize)
574
+ if not buf:
575
+ break
576
+ t.append(buf)
577
+ buf = "".join(t)
578
+ else:
579
+ buf = self._read(size)
580
+ self.pos += len(buf)
581
+ return buf
582
+
583
+ def _read(self, size):
584
+ """Return size bytes from the stream.
585
+ """
586
+ if self.comptype == "tar":
587
+ return self.__read(size)
588
+
589
+ c = len(self.dbuf)
590
+ while c < size:
591
+ buf = self.__read(self.bufsize)
592
+ if not buf:
593
+ break
594
+ try:
595
+ buf = self.cmp.decompress(buf)
596
+ except IOError:
597
+ raise ReadError("invalid compressed data")
598
+ self.dbuf += buf
599
+ c += len(buf)
600
+ buf = self.dbuf[:size]
601
+ self.dbuf = self.dbuf[size:]
602
+ return buf
603
+
604
+ def __read(self, size):
605
+ """Return size bytes from stream. If internal buffer is empty,
606
+ read another block from the stream.
607
+ """
608
+ c = len(self.buf)
609
+ while c < size:
610
+ buf = self.fileobj.read(self.bufsize)
611
+ if not buf:
612
+ break
613
+ self.buf += buf
614
+ c += len(buf)
615
+ buf = self.buf[:size]
616
+ self.buf = self.buf[size:]
617
+ return buf
618
+ # class _Stream
619
+
620
+ class _StreamProxy(object):
621
+ """Small proxy class that enables transparent compression
622
+ detection for the Stream interface (mode 'r|*').
623
+ """
624
+
625
+ def __init__(self, fileobj):
626
+ self.fileobj = fileobj
627
+ self.buf = self.fileobj.read(BLOCKSIZE)
628
+
629
+ def read(self, size):
630
+ self.read = self.fileobj.read
631
+ return self.buf
632
+
633
+ def getcomptype(self):
634
+ if self.buf.startswith(b"\037\213\010"):
635
+ return "gz"
636
+ if self.buf.startswith(b"BZh91"):
637
+ return "bz2"
638
+ return "tar"
639
+
640
+ def close(self):
641
+ self.fileobj.close()
642
+ # class StreamProxy
643
+
644
+ class _BZ2Proxy(object):
645
+ """Small proxy class that enables external file object
646
+ support for "r:bz2" and "w:bz2" modes. This is actually
647
+ a workaround for a limitation in bz2 module's BZ2File
648
+ class which (unlike gzip.GzipFile) has no support for
649
+ a file object argument.
650
+ """
651
+
652
+ blocksize = 16 * 1024
653
+
654
+ def __init__(self, fileobj, mode):
655
+ self.fileobj = fileobj
656
+ self.mode = mode
657
+ self.name = getattr(self.fileobj, "name", None)
658
+ self.init()
659
+
660
+ def init(self):
661
+ import bz2
662
+ self.pos = 0
663
+ if self.mode == "r":
664
+ self.bz2obj = bz2.BZ2Decompressor()
665
+ self.fileobj.seek(0)
666
+ self.buf = b""
667
+ else:
668
+ self.bz2obj = bz2.BZ2Compressor()
669
+
670
+ def read(self, size):
671
+ x = len(self.buf)
672
+ while x < size:
673
+ raw = self.fileobj.read(self.blocksize)
674
+ if not raw:
675
+ break
676
+ data = self.bz2obj.decompress(raw)
677
+ self.buf += data
678
+ x += len(data)
679
+
680
+ buf = self.buf[:size]
681
+ self.buf = self.buf[size:]
682
+ self.pos += len(buf)
683
+ return buf
684
+
685
+ def seek(self, pos):
686
+ if pos < self.pos:
687
+ self.init()
688
+ self.read(pos - self.pos)
689
+
690
+ def tell(self):
691
+ return self.pos
692
+
693
+ def write(self, data):
694
+ self.pos += len(data)
695
+ raw = self.bz2obj.compress(data)
696
+ self.fileobj.write(raw)
697
+
698
+ def close(self):
699
+ if self.mode == "w":
700
+ raw = self.bz2obj.flush()
701
+ self.fileobj.write(raw)
702
+ # class _BZ2Proxy
703
+
704
+ #------------------------
705
+ # Extraction file object
706
+ #------------------------
707
+ class _FileInFile(object):
708
+ """A thin wrapper around an existing file object that
709
+ provides a part of its data as an individual file
710
+ object.
711
+ """
712
+
713
+ def __init__(self, fileobj, offset, size, blockinfo=None):
714
+ self.fileobj = fileobj
715
+ self.offset = offset
716
+ self.size = size
717
+ self.position = 0
718
+
719
+ if blockinfo is None:
720
+ blockinfo = [(0, size)]
721
+
722
+ # Construct a map with data and zero blocks.
723
+ self.map_index = 0
724
+ self.map = []
725
+ lastpos = 0
726
+ realpos = self.offset
727
+ for offset, size in blockinfo:
728
+ if offset > lastpos:
729
+ self.map.append((False, lastpos, offset, None))
730
+ self.map.append((True, offset, offset + size, realpos))
731
+ realpos += size
732
+ lastpos = offset + size
733
+ if lastpos < self.size:
734
+ self.map.append((False, lastpos, self.size, None))
735
+
736
+ def seekable(self):
737
+ if not hasattr(self.fileobj, "seekable"):
738
+ # XXX gzip.GzipFile and bz2.BZ2File
739
+ return True
740
+ return self.fileobj.seekable()
741
+
742
+ def tell(self):
743
+ """Return the current file position.
744
+ """
745
+ return self.position
746
+
747
+ def seek(self, position):
748
+ """Seek to a position in the file.
749
+ """
750
+ self.position = position
751
+
752
+ def read(self, size=None):
753
+ """Read data from the file.
754
+ """
755
+ if size is None:
756
+ size = self.size - self.position
757
+ else:
758
+ size = min(size, self.size - self.position)
759
+
760
+ buf = b""
761
+ while size > 0:
762
+ while True:
763
+ data, start, stop, offset = self.map[self.map_index]
764
+ if start <= self.position < stop:
765
+ break
766
+ else:
767
+ self.map_index += 1
768
+ if self.map_index == len(self.map):
769
+ self.map_index = 0
770
+ length = min(size, stop - self.position)
771
+ if data:
772
+ self.fileobj.seek(offset + (self.position - start))
773
+ buf += self.fileobj.read(length)
774
+ else:
775
+ buf += NUL * length
776
+ size -= length
777
+ self.position += length
778
+ return buf
779
+ #class _FileInFile
780
+
781
+
782
+ class ExFileObject(object):
783
+ """File-like object for reading an archive member.
784
+ Is returned by TarFile.extractfile().
785
+ """
786
+ blocksize = 1024
787
+
788
+ def __init__(self, tarfile, tarinfo):
789
+ self.fileobj = _FileInFile(tarfile.fileobj,
790
+ tarinfo.offset_data,
791
+ tarinfo.size,
792
+ tarinfo.sparse)
793
+ self.name = tarinfo.name
794
+ self.mode = "r"
795
+ self.closed = False
796
+ self.size = tarinfo.size
797
+
798
+ self.position = 0
799
+ self.buffer = b""
800
+
801
+ def readable(self):
802
+ return True
803
+
804
+ def writable(self):
805
+ return False
806
+
807
+ def seekable(self):
808
+ return self.fileobj.seekable()
809
+
810
+ def read(self, size=None):
811
+ """Read at most size bytes from the file. If size is not
812
+ present or None, read all data until EOF is reached.
813
+ """
814
+ if self.closed:
815
+ raise ValueError("I/O operation on closed file")
816
+
817
+ buf = b""
818
+ if self.buffer:
819
+ if size is None:
820
+ buf = self.buffer
821
+ self.buffer = b""
822
+ else:
823
+ buf = self.buffer[:size]
824
+ self.buffer = self.buffer[size:]
825
+
826
+ if size is None:
827
+ buf += self.fileobj.read()
828
+ else:
829
+ buf += self.fileobj.read(size - len(buf))
830
+
831
+ self.position += len(buf)
832
+ return buf
833
+
834
+ # XXX TextIOWrapper uses the read1() method.
835
+ read1 = read
836
+
837
+ def readline(self, size=-1):
838
+ """Read one entire line from the file. If size is present
839
+ and non-negative, return a string with at most that
840
+ size, which may be an incomplete line.
841
+ """
842
+ if self.closed:
843
+ raise ValueError("I/O operation on closed file")
844
+
845
+ pos = self.buffer.find(b"\n") + 1
846
+ if pos == 0:
847
+ # no newline found.
848
+ while True:
849
+ buf = self.fileobj.read(self.blocksize)
850
+ self.buffer += buf
851
+ if not buf or b"\n" in buf:
852
+ pos = self.buffer.find(b"\n") + 1
853
+ if pos == 0:
854
+ # no newline found.
855
+ pos = len(self.buffer)
856
+ break
857
+
858
+ if size != -1:
859
+ pos = min(size, pos)
860
+
861
+ buf = self.buffer[:pos]
862
+ self.buffer = self.buffer[pos:]
863
+ self.position += len(buf)
864
+ return buf
865
+
866
+ def readlines(self):
867
+ """Return a list with all remaining lines.
868
+ """
869
+ result = []
870
+ while True:
871
+ line = self.readline()
872
+ if not line: break
873
+ result.append(line)
874
+ return result
875
+
876
+ def tell(self):
877
+ """Return the current file position.
878
+ """
879
+ if self.closed:
880
+ raise ValueError("I/O operation on closed file")
881
+
882
+ return self.position
883
+
884
+ def seek(self, pos, whence=os.SEEK_SET):
885
+ """Seek to a position in the file.
886
+ """
887
+ if self.closed:
888
+ raise ValueError("I/O operation on closed file")
889
+
890
+ if whence == os.SEEK_SET:
891
+ self.position = min(max(pos, 0), self.size)
892
+ elif whence == os.SEEK_CUR:
893
+ if pos < 0:
894
+ self.position = max(self.position + pos, 0)
895
+ else:
896
+ self.position = min(self.position + pos, self.size)
897
+ elif whence == os.SEEK_END:
898
+ self.position = max(min(self.size + pos, self.size), 0)
899
+ else:
900
+ raise ValueError("Invalid argument")
901
+
902
+ self.buffer = b""
903
+ self.fileobj.seek(self.position)
904
+
905
+ def close(self):
906
+ """Close the file object.
907
+ """
908
+ self.closed = True
909
+
910
+ def __iter__(self):
911
+ """Get an iterator over the file's lines.
912
+ """
913
+ while True:
914
+ line = self.readline()
915
+ if not line:
916
+ break
917
+ yield line
918
+ #class ExFileObject
919
+
920
+ #------------------
921
+ # Exported Classes
922
+ #------------------
923
+ class TarInfo(object):
924
+ """Informational class which holds the details about an
925
+ archive member given by a tar header block.
926
+ TarInfo objects are returned by TarFile.getmember(),
927
+ TarFile.getmembers() and TarFile.gettarinfo() and are
928
+ usually created internally.
929
+ """
930
+
931
+ __slots__ = ("name", "mode", "uid", "gid", "size", "mtime",
932
+ "chksum", "type", "linkname", "uname", "gname",
933
+ "devmajor", "devminor",
934
+ "offset", "offset_data", "pax_headers", "sparse",
935
+ "tarfile", "_sparse_structs", "_link_target")
936
+
937
+ def __init__(self, name=""):
938
+ """Construct a TarInfo object. name is the optional name
939
+ of the member.
940
+ """
941
+ self.name = name # member name
942
+ self.mode = 0o644 # file permissions
943
+ self.uid = 0 # user id
944
+ self.gid = 0 # group id
945
+ self.size = 0 # file size
946
+ self.mtime = 0 # modification time
947
+ self.chksum = 0 # header checksum
948
+ self.type = REGTYPE # member type
949
+ self.linkname = "" # link name
950
+ self.uname = "" # user name
951
+ self.gname = "" # group name
952
+ self.devmajor = 0 # device major number
953
+ self.devminor = 0 # device minor number
954
+
955
+ self.offset = 0 # the tar header starts here
956
+ self.offset_data = 0 # the file's data starts here
957
+
958
+ self.sparse = None # sparse member information
959
+ self.pax_headers = {} # pax header information
960
+
961
+ # In pax headers the "name" and "linkname" field are called
962
+ # "path" and "linkpath".
963
+ def _getpath(self):
964
+ return self.name
965
+ def _setpath(self, name):
966
+ self.name = name
967
+ path = property(_getpath, _setpath)
968
+
969
+ def _getlinkpath(self):
970
+ return self.linkname
971
+ def _setlinkpath(self, linkname):
972
+ self.linkname = linkname
973
+ linkpath = property(_getlinkpath, _setlinkpath)
974
+
975
+ def __repr__(self):
976
+ return "<%s %r at %#x>" % (self.__class__.__name__,self.name,id(self))
977
+
978
+ def get_info(self):
979
+ """Return the TarInfo's attributes as a dictionary.
980
+ """
981
+ info = {
982
+ "name": self.name,
983
+ "mode": self.mode & 0o7777,
984
+ "uid": self.uid,
985
+ "gid": self.gid,
986
+ "size": self.size,
987
+ "mtime": self.mtime,
988
+ "chksum": self.chksum,
989
+ "type": self.type,
990
+ "linkname": self.linkname,
991
+ "uname": self.uname,
992
+ "gname": self.gname,
993
+ "devmajor": self.devmajor,
994
+ "devminor": self.devminor
995
+ }
996
+
997
+ if info["type"] == DIRTYPE and not info["name"].endswith("/"):
998
+ info["name"] += "/"
999
+
1000
+ return info
1001
+
1002
+ def tobuf(self, format=DEFAULT_FORMAT, encoding=ENCODING, errors="surrogateescape"):
1003
+ """Return a tar header as a string of 512 byte blocks.
1004
+ """
1005
+ info = self.get_info()
1006
+
1007
+ if format == USTAR_FORMAT:
1008
+ return self.create_ustar_header(info, encoding, errors)
1009
+ elif format == GNU_FORMAT:
1010
+ return self.create_gnu_header(info, encoding, errors)
1011
+ elif format == PAX_FORMAT:
1012
+ return self.create_pax_header(info, encoding)
1013
+ else:
1014
+ raise ValueError("invalid format")
1015
+
1016
+ def create_ustar_header(self, info, encoding, errors):
1017
+ """Return the object as a ustar header block.
1018
+ """
1019
+ info["magic"] = POSIX_MAGIC
1020
+
1021
+ if len(info["linkname"]) > LENGTH_LINK:
1022
+ raise ValueError("linkname is too long")
1023
+
1024
+ if len(info["name"]) > LENGTH_NAME:
1025
+ info["prefix"], info["name"] = self._posix_split_name(info["name"])
1026
+
1027
+ return self._create_header(info, USTAR_FORMAT, encoding, errors)
1028
+
1029
+ def create_gnu_header(self, info, encoding, errors):
1030
+ """Return the object as a GNU header block sequence.
1031
+ """
1032
+ info["magic"] = GNU_MAGIC
1033
+
1034
+ buf = b""
1035
+ if len(info["linkname"]) > LENGTH_LINK:
1036
+ buf += self._create_gnu_long_header(info["linkname"], GNUTYPE_LONGLINK, encoding, errors)
1037
+
1038
+ if len(info["name"]) > LENGTH_NAME:
1039
+ buf += self._create_gnu_long_header(info["name"], GNUTYPE_LONGNAME, encoding, errors)
1040
+
1041
+ return buf + self._create_header(info, GNU_FORMAT, encoding, errors)
1042
+
1043
+ def create_pax_header(self, info, encoding):
1044
+ """Return the object as a ustar header block. If it cannot be
1045
+ represented this way, prepend a pax extended header sequence
1046
+ with supplement information.
1047
+ """
1048
+ info["magic"] = POSIX_MAGIC
1049
+ pax_headers = self.pax_headers.copy()
1050
+
1051
+ # Test string fields for values that exceed the field length or cannot
1052
+ # be represented in ASCII encoding.
1053
+ for name, hname, length in (
1054
+ ("name", "path", LENGTH_NAME), ("linkname", "linkpath", LENGTH_LINK),
1055
+ ("uname", "uname", 32), ("gname", "gname", 32)):
1056
+
1057
+ if hname in pax_headers:
1058
+ # The pax header has priority.
1059
+ continue
1060
+
1061
+ # Try to encode the string as ASCII.
1062
+ try:
1063
+ info[name].encode("ascii", "strict")
1064
+ except UnicodeEncodeError:
1065
+ pax_headers[hname] = info[name]
1066
+ continue
1067
+
1068
+ if len(info[name]) > length:
1069
+ pax_headers[hname] = info[name]
1070
+
1071
+ # Test number fields for values that exceed the field limit or values
1072
+ # that like to be stored as float.
1073
+ for name, digits in (("uid", 8), ("gid", 8), ("size", 12), ("mtime", 12)):
1074
+ if name in pax_headers:
1075
+ # The pax header has priority. Avoid overflow.
1076
+ info[name] = 0
1077
+ continue
1078
+
1079
+ val = info[name]
1080
+ if not 0 <= val < 8 ** (digits - 1) or isinstance(val, float):
1081
+ pax_headers[name] = str(val)
1082
+ info[name] = 0
1083
+
1084
+ # Create a pax extended header if necessary.
1085
+ if pax_headers:
1086
+ buf = self._create_pax_generic_header(pax_headers, XHDTYPE, encoding)
1087
+ else:
1088
+ buf = b""
1089
+
1090
+ return buf + self._create_header(info, USTAR_FORMAT, "ascii", "replace")
1091
+
1092
+ @classmethod
1093
+ def create_pax_global_header(cls, pax_headers):
1094
+ """Return the object as a pax global header block sequence.
1095
+ """
1096
+ return cls._create_pax_generic_header(pax_headers, XGLTYPE, "utf8")
1097
+
1098
+ def _posix_split_name(self, name):
1099
+ """Split a name longer than 100 chars into a prefix
1100
+ and a name part.
1101
+ """
1102
+ prefix = name[:LENGTH_PREFIX + 1]
1103
+ while prefix and prefix[-1] != "/":
1104
+ prefix = prefix[:-1]
1105
+
1106
+ name = name[len(prefix):]
1107
+ prefix = prefix[:-1]
1108
+
1109
+ if not prefix or len(name) > LENGTH_NAME:
1110
+ raise ValueError("name is too long")
1111
+ return prefix, name
1112
+
1113
+ @staticmethod
1114
+ def _create_header(info, format, encoding, errors):
1115
+ """Return a header block. info is a dictionary with file
1116
+ information, format must be one of the *_FORMAT constants.
1117
+ """
1118
+ parts = [
1119
+ stn(info.get("name", ""), 100, encoding, errors),
1120
+ itn(info.get("mode", 0) & 0o7777, 8, format),
1121
+ itn(info.get("uid", 0), 8, format),
1122
+ itn(info.get("gid", 0), 8, format),
1123
+ itn(info.get("size", 0), 12, format),
1124
+ itn(info.get("mtime", 0), 12, format),
1125
+ b" ", # checksum field
1126
+ info.get("type", REGTYPE),
1127
+ stn(info.get("linkname", ""), 100, encoding, errors),
1128
+ info.get("magic", POSIX_MAGIC),
1129
+ stn(info.get("uname", ""), 32, encoding, errors),
1130
+ stn(info.get("gname", ""), 32, encoding, errors),
1131
+ itn(info.get("devmajor", 0), 8, format),
1132
+ itn(info.get("devminor", 0), 8, format),
1133
+ stn(info.get("prefix", ""), 155, encoding, errors)
1134
+ ]
1135
+
1136
+ buf = struct.pack("%ds" % BLOCKSIZE, b"".join(parts))
1137
+ chksum = calc_chksums(buf[-BLOCKSIZE:])[0]
1138
+ buf = buf[:-364] + ("%06o\0" % chksum).encode("ascii") + buf[-357:]
1139
+ return buf
1140
+
1141
+ @staticmethod
1142
+ def _create_payload(payload):
1143
+ """Return the string payload filled with zero bytes
1144
+ up to the next 512 byte border.
1145
+ """
1146
+ blocks, remainder = divmod(len(payload), BLOCKSIZE)
1147
+ if remainder > 0:
1148
+ payload += (BLOCKSIZE - remainder) * NUL
1149
+ return payload
1150
+
1151
+ @classmethod
1152
+ def _create_gnu_long_header(cls, name, type, encoding, errors):
1153
+ """Return a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence
1154
+ for name.
1155
+ """
1156
+ name = name.encode(encoding, errors) + NUL
1157
+
1158
+ info = {}
1159
+ info["name"] = "././@LongLink"
1160
+ info["type"] = type
1161
+ info["size"] = len(name)
1162
+ info["magic"] = GNU_MAGIC
1163
+
1164
+ # create extended header + name blocks.
1165
+ return cls._create_header(info, USTAR_FORMAT, encoding, errors) + \
1166
+ cls._create_payload(name)
1167
+
1168
+ @classmethod
1169
+ def _create_pax_generic_header(cls, pax_headers, type, encoding):
1170
+ """Return a POSIX.1-2008 extended or global header sequence
1171
+ that contains a list of keyword, value pairs. The values
1172
+ must be strings.
1173
+ """
1174
+ # Check if one of the fields contains surrogate characters and thereby
1175
+ # forces hdrcharset=BINARY, see _proc_pax() for more information.
1176
+ binary = False
1177
+ for keyword, value in pax_headers.items():
1178
+ try:
1179
+ value.encode("utf8", "strict")
1180
+ except UnicodeEncodeError:
1181
+ binary = True
1182
+ break
1183
+
1184
+ records = b""
1185
+ if binary:
1186
+ # Put the hdrcharset field at the beginning of the header.
1187
+ records += b"21 hdrcharset=BINARY\n"
1188
+
1189
+ for keyword, value in pax_headers.items():
1190
+ keyword = keyword.encode("utf8")
1191
+ if binary:
1192
+ # Try to restore the original byte representation of `value'.
1193
+ # Needless to say, that the encoding must match the string.
1194
+ value = value.encode(encoding, "surrogateescape")
1195
+ else:
1196
+ value = value.encode("utf8")
1197
+
1198
+ l = len(keyword) + len(value) + 3 # ' ' + '=' + '\n'
1199
+ n = p = 0
1200
+ while True:
1201
+ n = l + len(str(p))
1202
+ if n == p:
1203
+ break
1204
+ p = n
1205
+ records += bytes(str(p), "ascii") + b" " + keyword + b"=" + value + b"\n"
1206
+
1207
+ # We use a hardcoded "././@PaxHeader" name like star does
1208
+ # instead of the one that POSIX recommends.
1209
+ info = {}
1210
+ info["name"] = "././@PaxHeader"
1211
+ info["type"] = type
1212
+ info["size"] = len(records)
1213
+ info["magic"] = POSIX_MAGIC
1214
+
1215
+ # Create pax header + record blocks.
1216
+ return cls._create_header(info, USTAR_FORMAT, "ascii", "replace") + \
1217
+ cls._create_payload(records)
1218
+
1219
+ @classmethod
1220
+ def frombuf(cls, buf, encoding, errors):
1221
+ """Construct a TarInfo object from a 512 byte bytes object.
1222
+ """
1223
+ if len(buf) == 0:
1224
+ raise EmptyHeaderError("empty header")
1225
+ if len(buf) != BLOCKSIZE:
1226
+ raise TruncatedHeaderError("truncated header")
1227
+ if buf.count(NUL) == BLOCKSIZE:
1228
+ raise EOFHeaderError("end of file header")
1229
+
1230
+ chksum = nti(buf[148:156])
1231
+ if chksum not in calc_chksums(buf):
1232
+ raise InvalidHeaderError("bad checksum")
1233
+
1234
+ obj = cls()
1235
+ obj.name = nts(buf[0:100], encoding, errors)
1236
+ obj.mode = nti(buf[100:108])
1237
+ obj.uid = nti(buf[108:116])
1238
+ obj.gid = nti(buf[116:124])
1239
+ obj.size = nti(buf[124:136])
1240
+ obj.mtime = nti(buf[136:148])
1241
+ obj.chksum = chksum
1242
+ obj.type = buf[156:157]
1243
+ obj.linkname = nts(buf[157:257], encoding, errors)
1244
+ obj.uname = nts(buf[265:297], encoding, errors)
1245
+ obj.gname = nts(buf[297:329], encoding, errors)
1246
+ obj.devmajor = nti(buf[329:337])
1247
+ obj.devminor = nti(buf[337:345])
1248
+ prefix = nts(buf[345:500], encoding, errors)
1249
+
1250
+ # Old V7 tar format represents a directory as a regular
1251
+ # file with a trailing slash.
1252
+ if obj.type == AREGTYPE and obj.name.endswith("/"):
1253
+ obj.type = DIRTYPE
1254
+
1255
+ # The old GNU sparse format occupies some of the unused
1256
+ # space in the buffer for up to 4 sparse structures.
1257
+ # Save the them for later processing in _proc_sparse().
1258
+ if obj.type == GNUTYPE_SPARSE:
1259
+ pos = 386
1260
+ structs = []
1261
+ for i in range(4):
1262
+ try:
1263
+ offset = nti(buf[pos:pos + 12])
1264
+ numbytes = nti(buf[pos + 12:pos + 24])
1265
+ except ValueError:
1266
+ break
1267
+ structs.append((offset, numbytes))
1268
+ pos += 24
1269
+ isextended = bool(buf[482])
1270
+ origsize = nti(buf[483:495])
1271
+ obj._sparse_structs = (structs, isextended, origsize)
1272
+
1273
+ # Remove redundant slashes from directories.
1274
+ if obj.isdir():
1275
+ obj.name = obj.name.rstrip("/")
1276
+
1277
+ # Reconstruct a ustar longname.
1278
+ if prefix and obj.type not in GNU_TYPES:
1279
+ obj.name = prefix + "/" + obj.name
1280
+ return obj
1281
+
1282
+ @classmethod
1283
+ def fromtarfile(cls, tarfile):
1284
+ """Return the next TarInfo object from TarFile object
1285
+ tarfile.
1286
+ """
1287
+ buf = tarfile.fileobj.read(BLOCKSIZE)
1288
+ obj = cls.frombuf(buf, tarfile.encoding, tarfile.errors)
1289
+ obj.offset = tarfile.fileobj.tell() - BLOCKSIZE
1290
+ return obj._proc_member(tarfile)
1291
+
1292
+ #--------------------------------------------------------------------------
1293
+ # The following are methods that are called depending on the type of a
1294
+ # member. The entry point is _proc_member() which can be overridden in a
1295
+ # subclass to add custom _proc_*() methods. A _proc_*() method MUST
1296
+ # implement the following
1297
+ # operations:
1298
+ # 1. Set self.offset_data to the position where the data blocks begin,
1299
+ # if there is data that follows.
1300
+ # 2. Set tarfile.offset to the position where the next member's header will
1301
+ # begin.
1302
+ # 3. Return self or another valid TarInfo object.
1303
+ def _proc_member(self, tarfile):
1304
+ """Choose the right processing method depending on
1305
+ the type and call it.
1306
+ """
1307
+ if self.type in (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK):
1308
+ return self._proc_gnulong(tarfile)
1309
+ elif self.type == GNUTYPE_SPARSE:
1310
+ return self._proc_sparse(tarfile)
1311
+ elif self.type in (XHDTYPE, XGLTYPE, SOLARIS_XHDTYPE):
1312
+ return self._proc_pax(tarfile)
1313
+ else:
1314
+ return self._proc_builtin(tarfile)
1315
+
1316
+ def _proc_builtin(self, tarfile):
1317
+ """Process a builtin type or an unknown type which
1318
+ will be treated as a regular file.
1319
+ """
1320
+ self.offset_data = tarfile.fileobj.tell()
1321
+ offset = self.offset_data
1322
+ if self.isreg() or self.type not in SUPPORTED_TYPES:
1323
+ # Skip the following data blocks.
1324
+ offset += self._block(self.size)
1325
+ tarfile.offset = offset
1326
+
1327
+ # Patch the TarInfo object with saved global
1328
+ # header information.
1329
+ self._apply_pax_info(tarfile.pax_headers, tarfile.encoding, tarfile.errors)
1330
+
1331
+ return self
1332
+
1333
+ def _proc_gnulong(self, tarfile):
1334
+ """Process the blocks that hold a GNU longname
1335
+ or longlink member.
1336
+ """
1337
+ buf = tarfile.fileobj.read(self._block(self.size))
1338
+
1339
+ # Fetch the next header and process it.
1340
+ try:
1341
+ next = self.fromtarfile(tarfile)
1342
+ except HeaderError:
1343
+ raise SubsequentHeaderError("missing or bad subsequent header")
1344
+
1345
+ # Patch the TarInfo object from the next header with
1346
+ # the longname information.
1347
+ next.offset = self.offset
1348
+ if self.type == GNUTYPE_LONGNAME:
1349
+ next.name = nts(buf, tarfile.encoding, tarfile.errors)
1350
+ elif self.type == GNUTYPE_LONGLINK:
1351
+ next.linkname = nts(buf, tarfile.encoding, tarfile.errors)
1352
+
1353
+ return next
1354
+
1355
+ def _proc_sparse(self, tarfile):
1356
+ """Process a GNU sparse header plus extra headers.
1357
+ """
1358
+ # We already collected some sparse structures in frombuf().
1359
+ structs, isextended, origsize = self._sparse_structs
1360
+ del self._sparse_structs
1361
+
1362
+ # Collect sparse structures from extended header blocks.
1363
+ while isextended:
1364
+ buf = tarfile.fileobj.read(BLOCKSIZE)
1365
+ pos = 0
1366
+ for i in range(21):
1367
+ try:
1368
+ offset = nti(buf[pos:pos + 12])
1369
+ numbytes = nti(buf[pos + 12:pos + 24])
1370
+ except ValueError:
1371
+ break
1372
+ if offset and numbytes:
1373
+ structs.append((offset, numbytes))
1374
+ pos += 24
1375
+ isextended = bool(buf[504])
1376
+ self.sparse = structs
1377
+
1378
+ self.offset_data = tarfile.fileobj.tell()
1379
+ tarfile.offset = self.offset_data + self._block(self.size)
1380
+ self.size = origsize
1381
+ return self
1382
+
1383
+ def _proc_pax(self, tarfile):
1384
+ """Process an extended or global header as described in
1385
+ POSIX.1-2008.
1386
+ """
1387
+ # Read the header information.
1388
+ buf = tarfile.fileobj.read(self._block(self.size))
1389
+
1390
+ # A pax header stores supplemental information for either
1391
+ # the following file (extended) or all following files
1392
+ # (global).
1393
+ if self.type == XGLTYPE:
1394
+ pax_headers = tarfile.pax_headers
1395
+ else:
1396
+ pax_headers = tarfile.pax_headers.copy()
1397
+
1398
+ # Check if the pax header contains a hdrcharset field. This tells us
1399
+ # the encoding of the path, linkpath, uname and gname fields. Normally,
1400
+ # these fields are UTF-8 encoded but since POSIX.1-2008 tar
1401
+ # implementations are allowed to store them as raw binary strings if
1402
+ # the translation to UTF-8 fails.
1403
+ match = re.search(br"\d+ hdrcharset=([^\n]+)\n", buf)
1404
+ if match is not None:
1405
+ pax_headers["hdrcharset"] = match.group(1).decode("utf8")
1406
+
1407
+ # For the time being, we don't care about anything other than "BINARY".
1408
+ # The only other value that is currently allowed by the standard is
1409
+ # "ISO-IR 10646 2000 UTF-8" in other words UTF-8.
1410
+ hdrcharset = pax_headers.get("hdrcharset")
1411
+ if hdrcharset == "BINARY":
1412
+ encoding = tarfile.encoding
1413
+ else:
1414
+ encoding = "utf8"
1415
+
1416
+ # Parse pax header information. A record looks like that:
1417
+ # "%d %s=%s\n" % (length, keyword, value). length is the size
1418
+ # of the complete record including the length field itself and
1419
+ # the newline. keyword and value are both UTF-8 encoded strings.
1420
+ regex = re.compile(br"(\d+) ([^=]+)=")
1421
+ pos = 0
1422
+ while True:
1423
+ match = regex.match(buf, pos)
1424
+ if not match:
1425
+ break
1426
+
1427
+ length, keyword = match.groups()
1428
+ length = int(length)
1429
+ value = buf[match.end(2) + 1:match.start(1) + length - 1]
1430
+
1431
+ # Normally, we could just use "utf8" as the encoding and "strict"
1432
+ # as the error handler, but we better not take the risk. For
1433
+ # example, GNU tar <= 1.23 is known to store filenames it cannot
1434
+ # translate to UTF-8 as raw strings (unfortunately without a
1435
+ # hdrcharset=BINARY header).
1436
+ # We first try the strict standard encoding, and if that fails we
1437
+ # fall back on the user's encoding and error handler.
1438
+ keyword = self._decode_pax_field(keyword, "utf8", "utf8",
1439
+ tarfile.errors)
1440
+ if keyword in PAX_NAME_FIELDS:
1441
+ value = self._decode_pax_field(value, encoding, tarfile.encoding,
1442
+ tarfile.errors)
1443
+ else:
1444
+ value = self._decode_pax_field(value, "utf8", "utf8",
1445
+ tarfile.errors)
1446
+
1447
+ pax_headers[keyword] = value
1448
+ pos += length
1449
+
1450
+ # Fetch the next header.
1451
+ try:
1452
+ next = self.fromtarfile(tarfile)
1453
+ except HeaderError:
1454
+ raise SubsequentHeaderError("missing or bad subsequent header")
1455
+
1456
+ # Process GNU sparse information.
1457
+ if "GNU.sparse.map" in pax_headers:
1458
+ # GNU extended sparse format version 0.1.
1459
+ self._proc_gnusparse_01(next, pax_headers)
1460
+
1461
+ elif "GNU.sparse.size" in pax_headers:
1462
+ # GNU extended sparse format version 0.0.
1463
+ self._proc_gnusparse_00(next, pax_headers, buf)
1464
+
1465
+ elif pax_headers.get("GNU.sparse.major") == "1" and pax_headers.get("GNU.sparse.minor") == "0":
1466
+ # GNU extended sparse format version 1.0.
1467
+ self._proc_gnusparse_10(next, pax_headers, tarfile)
1468
+
1469
+ if self.type in (XHDTYPE, SOLARIS_XHDTYPE):
1470
+ # Patch the TarInfo object with the extended header info.
1471
+ next._apply_pax_info(pax_headers, tarfile.encoding, tarfile.errors)
1472
+ next.offset = self.offset
1473
+
1474
+ if "size" in pax_headers:
1475
+ # If the extended header replaces the size field,
1476
+ # we need to recalculate the offset where the next
1477
+ # header starts.
1478
+ offset = next.offset_data
1479
+ if next.isreg() or next.type not in SUPPORTED_TYPES:
1480
+ offset += next._block(next.size)
1481
+ tarfile.offset = offset
1482
+
1483
+ return next
1484
+
1485
+ def _proc_gnusparse_00(self, next, pax_headers, buf):
1486
+ """Process a GNU tar extended sparse header, version 0.0.
1487
+ """
1488
+ offsets = []
1489
+ for match in re.finditer(br"\d+ GNU.sparse.offset=(\d+)\n", buf):
1490
+ offsets.append(int(match.group(1)))
1491
+ numbytes = []
1492
+ for match in re.finditer(br"\d+ GNU.sparse.numbytes=(\d+)\n", buf):
1493
+ numbytes.append(int(match.group(1)))
1494
+ next.sparse = list(zip(offsets, numbytes))
1495
+
1496
+ def _proc_gnusparse_01(self, next, pax_headers):
1497
+ """Process a GNU tar extended sparse header, version 0.1.
1498
+ """
1499
+ sparse = [int(x) for x in pax_headers["GNU.sparse.map"].split(",")]
1500
+ next.sparse = list(zip(sparse[::2], sparse[1::2]))
1501
+
1502
+ def _proc_gnusparse_10(self, next, pax_headers, tarfile):
1503
+ """Process a GNU tar extended sparse header, version 1.0.
1504
+ """
1505
+ fields = None
1506
+ sparse = []
1507
+ buf = tarfile.fileobj.read(BLOCKSIZE)
1508
+ fields, buf = buf.split(b"\n", 1)
1509
+ fields = int(fields)
1510
+ while len(sparse) < fields * 2:
1511
+ if b"\n" not in buf:
1512
+ buf += tarfile.fileobj.read(BLOCKSIZE)
1513
+ number, buf = buf.split(b"\n", 1)
1514
+ sparse.append(int(number))
1515
+ next.offset_data = tarfile.fileobj.tell()
1516
+ next.sparse = list(zip(sparse[::2], sparse[1::2]))
1517
+
1518
+ def _apply_pax_info(self, pax_headers, encoding, errors):
1519
+ """Replace fields with supplemental information from a previous
1520
+ pax extended or global header.
1521
+ """
1522
+ for keyword, value in pax_headers.items():
1523
+ if keyword == "GNU.sparse.name":
1524
+ setattr(self, "path", value)
1525
+ elif keyword == "GNU.sparse.size":
1526
+ setattr(self, "size", int(value))
1527
+ elif keyword == "GNU.sparse.realsize":
1528
+ setattr(self, "size", int(value))
1529
+ elif keyword in PAX_FIELDS:
1530
+ if keyword in PAX_NUMBER_FIELDS:
1531
+ try:
1532
+ value = PAX_NUMBER_FIELDS[keyword](value)
1533
+ except ValueError:
1534
+ value = 0
1535
+ if keyword == "path":
1536
+ value = value.rstrip("/")
1537
+ setattr(self, keyword, value)
1538
+
1539
+ self.pax_headers = pax_headers.copy()
1540
+
1541
+ def _decode_pax_field(self, value, encoding, fallback_encoding, fallback_errors):
1542
+ """Decode a single field from a pax record.
1543
+ """
1544
+ try:
1545
+ return value.decode(encoding, "strict")
1546
+ except UnicodeDecodeError:
1547
+ return value.decode(fallback_encoding, fallback_errors)
1548
+
1549
+ def _block(self, count):
1550
+ """Round up a byte count by BLOCKSIZE and return it,
1551
+ e.g. _block(834) => 1024.
1552
+ """
1553
+ blocks, remainder = divmod(count, BLOCKSIZE)
1554
+ if remainder:
1555
+ blocks += 1
1556
+ return blocks * BLOCKSIZE
1557
+
1558
+ def isreg(self):
1559
+ return self.type in REGULAR_TYPES
1560
+ def isfile(self):
1561
+ return self.isreg()
1562
+ def isdir(self):
1563
+ return self.type == DIRTYPE
1564
+ def issym(self):
1565
+ return self.type == SYMTYPE
1566
+ def islnk(self):
1567
+ return self.type == LNKTYPE
1568
+ def ischr(self):
1569
+ return self.type == CHRTYPE
1570
+ def isblk(self):
1571
+ return self.type == BLKTYPE
1572
+ def isfifo(self):
1573
+ return self.type == FIFOTYPE
1574
+ def issparse(self):
1575
+ return self.sparse is not None
1576
+ def isdev(self):
1577
+ return self.type in (CHRTYPE, BLKTYPE, FIFOTYPE)
1578
+ # class TarInfo
1579
+
1580
+ class TarFile(object):
1581
+ """The TarFile Class provides an interface to tar archives.
1582
+ """
1583
+
1584
+ debug = 0 # May be set from 0 (no msgs) to 3 (all msgs)
1585
+
1586
+ dereference = False # If true, add content of linked file to the
1587
+ # tar file, else the link.
1588
+
1589
+ ignore_zeros = False # If true, skips empty or invalid blocks and
1590
+ # continues processing.
1591
+
1592
+ errorlevel = 1 # If 0, fatal errors only appear in debug
1593
+ # messages (if debug >= 0). If > 0, errors
1594
+ # are passed to the caller as exceptions.
1595
+
1596
+ format = DEFAULT_FORMAT # The format to use when creating an archive.
1597
+
1598
+ encoding = ENCODING # Encoding for 8-bit character strings.
1599
+
1600
+ errors = None # Error handler for unicode conversion.
1601
+
1602
+ tarinfo = TarInfo # The default TarInfo class to use.
1603
+
1604
+ fileobject = ExFileObject # The default ExFileObject class to use.
1605
+
1606
+ def __init__(self, name=None, mode="r", fileobj=None, format=None,
1607
+ tarinfo=None, dereference=None, ignore_zeros=None, encoding=None,
1608
+ errors="surrogateescape", pax_headers=None, debug=None, errorlevel=None):
1609
+ """Open an (uncompressed) tar archive `name'. `mode' is either 'r' to
1610
+ read from an existing archive, 'a' to append data to an existing
1611
+ file or 'w' to create a new file overwriting an existing one. `mode'
1612
+ defaults to 'r'.
1613
+ If `fileobj' is given, it is used for reading or writing data. If it
1614
+ can be determined, `mode' is overridden by `fileobj's mode.
1615
+ `fileobj' is not closed, when TarFile is closed.
1616
+ """
1617
+ if len(mode) > 1 or mode not in "raw":
1618
+ raise ValueError("mode must be 'r', 'a' or 'w'")
1619
+ self.mode = mode
1620
+ self._mode = {"r": "rb", "a": "r+b", "w": "wb"}[mode]
1621
+
1622
+ if not fileobj:
1623
+ if self.mode == "a" and not os.path.exists(name):
1624
+ # Create nonexistent files in append mode.
1625
+ self.mode = "w"
1626
+ self._mode = "wb"
1627
+ fileobj = bltn_open(name, self._mode)
1628
+ self._extfileobj = False
1629
+ else:
1630
+ if name is None and hasattr(fileobj, "name"):
1631
+ name = fileobj.name
1632
+ if hasattr(fileobj, "mode"):
1633
+ self._mode = fileobj.mode
1634
+ self._extfileobj = True
1635
+ self.name = os.path.abspath(name) if name else None
1636
+ self.fileobj = fileobj
1637
+
1638
+ # Init attributes.
1639
+ if format is not None:
1640
+ self.format = format
1641
+ if tarinfo is not None:
1642
+ self.tarinfo = tarinfo
1643
+ if dereference is not None:
1644
+ self.dereference = dereference
1645
+ if ignore_zeros is not None:
1646
+ self.ignore_zeros = ignore_zeros
1647
+ if encoding is not None:
1648
+ self.encoding = encoding
1649
+ self.errors = errors
1650
+
1651
+ if pax_headers is not None and self.format == PAX_FORMAT:
1652
+ self.pax_headers = pax_headers
1653
+ else:
1654
+ self.pax_headers = {}
1655
+
1656
+ if debug is not None:
1657
+ self.debug = debug
1658
+ if errorlevel is not None:
1659
+ self.errorlevel = errorlevel
1660
+
1661
+ # Init datastructures.
1662
+ self.closed = False
1663
+ self.members = [] # list of members as TarInfo objects
1664
+ self._loaded = False # flag if all members have been read
1665
+ self.offset = self.fileobj.tell()
1666
+ # current position in the archive file
1667
+ self.inodes = {} # dictionary caching the inodes of
1668
+ # archive members already added
1669
+
1670
+ try:
1671
+ if self.mode == "r":
1672
+ self.firstmember = None
1673
+ self.firstmember = self.next()
1674
+
1675
+ if self.mode == "a":
1676
+ # Move to the end of the archive,
1677
+ # before the first empty block.
1678
+ while True:
1679
+ self.fileobj.seek(self.offset)
1680
+ try:
1681
+ tarinfo = self.tarinfo.fromtarfile(self)
1682
+ self.members.append(tarinfo)
1683
+ except EOFHeaderError:
1684
+ self.fileobj.seek(self.offset)
1685
+ break
1686
+ except HeaderError as e:
1687
+ raise ReadError(str(e))
1688
+
1689
+ if self.mode in "aw":
1690
+ self._loaded = True
1691
+
1692
+ if self.pax_headers:
1693
+ buf = self.tarinfo.create_pax_global_header(self.pax_headers.copy())
1694
+ self.fileobj.write(buf)
1695
+ self.offset += len(buf)
1696
+ except:
1697
+ if not self._extfileobj:
1698
+ self.fileobj.close()
1699
+ self.closed = True
1700
+ raise
1701
+
1702
+ #--------------------------------------------------------------------------
1703
+ # Below are the classmethods which act as alternate constructors to the
1704
+ # TarFile class. The open() method is the only one that is needed for
1705
+ # public use; it is the "super"-constructor and is able to select an
1706
+ # adequate "sub"-constructor for a particular compression using the mapping
1707
+ # from OPEN_METH.
1708
+ #
1709
+ # This concept allows one to subclass TarFile without losing the comfort of
1710
+ # the super-constructor. A sub-constructor is registered and made available
1711
+ # by adding it to the mapping in OPEN_METH.
1712
+
1713
+ @classmethod
1714
+ def open(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE, **kwargs):
1715
+ """Open a tar archive for reading, writing or appending. Return
1716
+ an appropriate TarFile class.
1717
+
1718
+ mode:
1719
+ 'r' or 'r:*' open for reading with transparent compression
1720
+ 'r:' open for reading exclusively uncompressed
1721
+ 'r:gz' open for reading with gzip compression
1722
+ 'r:bz2' open for reading with bzip2 compression
1723
+ 'a' or 'a:' open for appending, creating the file if necessary
1724
+ 'w' or 'w:' open for writing without compression
1725
+ 'w:gz' open for writing with gzip compression
1726
+ 'w:bz2' open for writing with bzip2 compression
1727
+
1728
+ 'r|*' open a stream of tar blocks with transparent compression
1729
+ 'r|' open an uncompressed stream of tar blocks for reading
1730
+ 'r|gz' open a gzip compressed stream of tar blocks
1731
+ 'r|bz2' open a bzip2 compressed stream of tar blocks
1732
+ 'w|' open an uncompressed stream for writing
1733
+ 'w|gz' open a gzip compressed stream for writing
1734
+ 'w|bz2' open a bzip2 compressed stream for writing
1735
+ """
1736
+
1737
+ if not name and not fileobj:
1738
+ raise ValueError("nothing to open")
1739
+
1740
+ if mode in ("r", "r:*"):
1741
+ # Find out which *open() is appropriate for opening the file.
1742
+ for comptype in cls.OPEN_METH:
1743
+ func = getattr(cls, cls.OPEN_METH[comptype])
1744
+ if fileobj is not None:
1745
+ saved_pos = fileobj.tell()
1746
+ try:
1747
+ return func(name, "r", fileobj, **kwargs)
1748
+ except (ReadError, CompressionError) as e:
1749
+ if fileobj is not None:
1750
+ fileobj.seek(saved_pos)
1751
+ continue
1752
+ raise ReadError("file could not be opened successfully")
1753
+
1754
+ elif ":" in mode:
1755
+ filemode, comptype = mode.split(":", 1)
1756
+ filemode = filemode or "r"
1757
+ comptype = comptype or "tar"
1758
+
1759
+ # Select the *open() function according to
1760
+ # given compression.
1761
+ if comptype in cls.OPEN_METH:
1762
+ func = getattr(cls, cls.OPEN_METH[comptype])
1763
+ else:
1764
+ raise CompressionError("unknown compression type %r" % comptype)
1765
+ return func(name, filemode, fileobj, **kwargs)
1766
+
1767
+ elif "|" in mode:
1768
+ filemode, comptype = mode.split("|", 1)
1769
+ filemode = filemode or "r"
1770
+ comptype = comptype or "tar"
1771
+
1772
+ if filemode not in "rw":
1773
+ raise ValueError("mode must be 'r' or 'w'")
1774
+
1775
+ stream = _Stream(name, filemode, comptype, fileobj, bufsize)
1776
+ try:
1777
+ t = cls(name, filemode, stream, **kwargs)
1778
+ except:
1779
+ stream.close()
1780
+ raise
1781
+ t._extfileobj = False
1782
+ return t
1783
+
1784
+ elif mode in "aw":
1785
+ return cls.taropen(name, mode, fileobj, **kwargs)
1786
+
1787
+ raise ValueError("undiscernible mode")
1788
+
1789
+ @classmethod
1790
+ def taropen(cls, name, mode="r", fileobj=None, **kwargs):
1791
+ """Open uncompressed tar archive name for reading or writing.
1792
+ """
1793
+ if len(mode) > 1 or mode not in "raw":
1794
+ raise ValueError("mode must be 'r', 'a' or 'w'")
1795
+ return cls(name, mode, fileobj, **kwargs)
1796
+
1797
+ @classmethod
1798
+ def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
1799
+ """Open gzip compressed tar archive name for reading or writing.
1800
+ Appending is not allowed.
1801
+ """
1802
+ if len(mode) > 1 or mode not in "rw":
1803
+ raise ValueError("mode must be 'r' or 'w'")
1804
+
1805
+ try:
1806
+ import gzip
1807
+ gzip.GzipFile
1808
+ except (ImportError, AttributeError):
1809
+ raise CompressionError("gzip module is not available")
1810
+
1811
+ extfileobj = fileobj is not None
1812
+ try:
1813
+ fileobj = gzip.GzipFile(name, mode + "b", compresslevel, fileobj)
1814
+ t = cls.taropen(name, mode, fileobj, **kwargs)
1815
+ except IOError:
1816
+ if not extfileobj and fileobj is not None:
1817
+ fileobj.close()
1818
+ if fileobj is None:
1819
+ raise
1820
+ raise ReadError("not a gzip file")
1821
+ except:
1822
+ if not extfileobj and fileobj is not None:
1823
+ fileobj.close()
1824
+ raise
1825
+ t._extfileobj = extfileobj
1826
+ return t
1827
+
1828
+ @classmethod
1829
+ def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
1830
+ """Open bzip2 compressed tar archive name for reading or writing.
1831
+ Appending is not allowed.
1832
+ """
1833
+ if len(mode) > 1 or mode not in "rw":
1834
+ raise ValueError("mode must be 'r' or 'w'.")
1835
+
1836
+ try:
1837
+ import bz2
1838
+ except ImportError:
1839
+ raise CompressionError("bz2 module is not available")
1840
+
1841
+ if fileobj is not None:
1842
+ fileobj = _BZ2Proxy(fileobj, mode)
1843
+ else:
1844
+ fileobj = bz2.BZ2File(name, mode, compresslevel=compresslevel)
1845
+
1846
+ try:
1847
+ t = cls.taropen(name, mode, fileobj, **kwargs)
1848
+ except (IOError, EOFError):
1849
+ fileobj.close()
1850
+ raise ReadError("not a bzip2 file")
1851
+ t._extfileobj = False
1852
+ return t
1853
+
1854
+ # All *open() methods are registered here.
1855
+ OPEN_METH = {
1856
+ "tar": "taropen", # uncompressed tar
1857
+ "gz": "gzopen", # gzip compressed tar
1858
+ "bz2": "bz2open" # bzip2 compressed tar
1859
+ }
1860
+
1861
+ #--------------------------------------------------------------------------
1862
+ # The public methods which TarFile provides:
1863
+
1864
+ def close(self):
1865
+ """Close the TarFile. In write-mode, two finishing zero blocks are
1866
+ appended to the archive.
1867
+ """
1868
+ if self.closed:
1869
+ return
1870
+
1871
+ if self.mode in "aw":
1872
+ self.fileobj.write(NUL * (BLOCKSIZE * 2))
1873
+ self.offset += (BLOCKSIZE * 2)
1874
+ # fill up the end with zero-blocks
1875
+ # (like option -b20 for tar does)
1876
+ blocks, remainder = divmod(self.offset, RECORDSIZE)
1877
+ if remainder > 0:
1878
+ self.fileobj.write(NUL * (RECORDSIZE - remainder))
1879
+
1880
+ if not self._extfileobj:
1881
+ self.fileobj.close()
1882
+ self.closed = True
1883
+
1884
+ def getmember(self, name):
1885
+ """Return a TarInfo object for member `name'. If `name' can not be
1886
+ found in the archive, KeyError is raised. If a member occurs more
1887
+ than once in the archive, its last occurrence is assumed to be the
1888
+ most up-to-date version.
1889
+ """
1890
+ tarinfo = self._getmember(name)
1891
+ if tarinfo is None:
1892
+ raise KeyError("filename %r not found" % name)
1893
+ return tarinfo
1894
+
1895
+ def getmembers(self):
1896
+ """Return the members of the archive as a list of TarInfo objects. The
1897
+ list has the same order as the members in the archive.
1898
+ """
1899
+ self._check()
1900
+ if not self._loaded: # if we want to obtain a list of
1901
+ self._load() # all members, we first have to
1902
+ # scan the whole archive.
1903
+ return self.members
1904
+
1905
+ def getnames(self):
1906
+ """Return the members of the archive as a list of their names. It has
1907
+ the same order as the list returned by getmembers().
1908
+ """
1909
+ return [tarinfo.name for tarinfo in self.getmembers()]
1910
+
1911
+ def gettarinfo(self, name=None, arcname=None, fileobj=None):
1912
+ """Create a TarInfo object for either the file `name' or the file
1913
+ object `fileobj' (using os.fstat on its file descriptor). You can
1914
+ modify some of the TarInfo's attributes before you add it using
1915
+ addfile(). If given, `arcname' specifies an alternative name for the
1916
+ file in the archive.
1917
+ """
1918
+ self._check("aw")
1919
+
1920
+ # When fileobj is given, replace name by
1921
+ # fileobj's real name.
1922
+ if fileobj is not None:
1923
+ name = fileobj.name
1924
+
1925
+ # Building the name of the member in the archive.
1926
+ # Backward slashes are converted to forward slashes,
1927
+ # Absolute paths are turned to relative paths.
1928
+ if arcname is None:
1929
+ arcname = name
1930
+ drv, arcname = os.path.splitdrive(arcname)
1931
+ arcname = arcname.replace(os.sep, "/")
1932
+ arcname = arcname.lstrip("/")
1933
+
1934
+ # Now, fill the TarInfo object with
1935
+ # information specific for the file.
1936
+ tarinfo = self.tarinfo()
1937
+ tarinfo.tarfile = self
1938
+
1939
+ # Use os.stat or os.lstat, depending on platform
1940
+ # and if symlinks shall be resolved.
1941
+ if fileobj is None:
1942
+ if hasattr(os, "lstat") and not self.dereference:
1943
+ statres = os.lstat(name)
1944
+ else:
1945
+ statres = os.stat(name)
1946
+ else:
1947
+ statres = os.fstat(fileobj.fileno())
1948
+ linkname = ""
1949
+
1950
+ stmd = statres.st_mode
1951
+ if stat.S_ISREG(stmd):
1952
+ inode = (statres.st_ino, statres.st_dev)
1953
+ if not self.dereference and statres.st_nlink > 1 and \
1954
+ inode in self.inodes and arcname != self.inodes[inode]:
1955
+ # Is it a hardlink to an already
1956
+ # archived file?
1957
+ type = LNKTYPE
1958
+ linkname = self.inodes[inode]
1959
+ else:
1960
+ # The inode is added only if its valid.
1961
+ # For win32 it is always 0.
1962
+ type = REGTYPE
1963
+ if inode[0]:
1964
+ self.inodes[inode] = arcname
1965
+ elif stat.S_ISDIR(stmd):
1966
+ type = DIRTYPE
1967
+ elif stat.S_ISFIFO(stmd):
1968
+ type = FIFOTYPE
1969
+ elif stat.S_ISLNK(stmd):
1970
+ type = SYMTYPE
1971
+ linkname = os.readlink(name)
1972
+ elif stat.S_ISCHR(stmd):
1973
+ type = CHRTYPE
1974
+ elif stat.S_ISBLK(stmd):
1975
+ type = BLKTYPE
1976
+ else:
1977
+ return None
1978
+
1979
+ # Fill the TarInfo object with all
1980
+ # information we can get.
1981
+ tarinfo.name = arcname
1982
+ tarinfo.mode = stmd
1983
+ tarinfo.uid = statres.st_uid
1984
+ tarinfo.gid = statres.st_gid
1985
+ if type == REGTYPE:
1986
+ tarinfo.size = statres.st_size
1987
+ else:
1988
+ tarinfo.size = 0
1989
+ tarinfo.mtime = statres.st_mtime
1990
+ tarinfo.type = type
1991
+ tarinfo.linkname = linkname
1992
+ if pwd:
1993
+ try:
1994
+ tarinfo.uname = pwd.getpwuid(tarinfo.uid)[0]
1995
+ except KeyError:
1996
+ pass
1997
+ if grp:
1998
+ try:
1999
+ tarinfo.gname = grp.getgrgid(tarinfo.gid)[0]
2000
+ except KeyError:
2001
+ pass
2002
+
2003
+ if type in (CHRTYPE, BLKTYPE):
2004
+ if hasattr(os, "major") and hasattr(os, "minor"):
2005
+ tarinfo.devmajor = os.major(statres.st_rdev)
2006
+ tarinfo.devminor = os.minor(statres.st_rdev)
2007
+ return tarinfo
2008
+
2009
+ def list(self, verbose=True):
2010
+ """Print a table of contents to sys.stdout. If `verbose' is False, only
2011
+ the names of the members are printed. If it is True, an `ls -l'-like
2012
+ output is produced.
2013
+ """
2014
+ self._check()
2015
+
2016
+ for tarinfo in self:
2017
+ if verbose:
2018
+ print(filemode(tarinfo.mode), end=' ')
2019
+ print("%s/%s" % (tarinfo.uname or tarinfo.uid,
2020
+ tarinfo.gname or tarinfo.gid), end=' ')
2021
+ if tarinfo.ischr() or tarinfo.isblk():
2022
+ print("%10s" % ("%d,%d" \
2023
+ % (tarinfo.devmajor, tarinfo.devminor)), end=' ')
2024
+ else:
2025
+ print("%10d" % tarinfo.size, end=' ')
2026
+ print("%d-%02d-%02d %02d:%02d:%02d" \
2027
+ % time.localtime(tarinfo.mtime)[:6], end=' ')
2028
+
2029
+ print(tarinfo.name + ("/" if tarinfo.isdir() else ""), end=' ')
2030
+
2031
+ if verbose:
2032
+ if tarinfo.issym():
2033
+ print("->", tarinfo.linkname, end=' ')
2034
+ if tarinfo.islnk():
2035
+ print("link to", tarinfo.linkname, end=' ')
2036
+ print()
2037
+
2038
+ def add(self, name, arcname=None, recursive=True, exclude=None, filter=None):
2039
+ """Add the file `name' to the archive. `name' may be any type of file
2040
+ (directory, fifo, symbolic link, etc.). If given, `arcname'
2041
+ specifies an alternative name for the file in the archive.
2042
+ Directories are added recursively by default. This can be avoided by
2043
+ setting `recursive' to False. `exclude' is a function that should
2044
+ return True for each filename to be excluded. `filter' is a function
2045
+ that expects a TarInfo object argument and returns the changed
2046
+ TarInfo object, if it returns None the TarInfo object will be
2047
+ excluded from the archive.
2048
+ """
2049
+ self._check("aw")
2050
+
2051
+ if arcname is None:
2052
+ arcname = name
2053
+
2054
+ # Exclude pathnames.
2055
+ if exclude is not None:
2056
+ import warnings
2057
+ warnings.warn("use the filter argument instead",
2058
+ DeprecationWarning, 2)
2059
+ if exclude(name):
2060
+ self._dbg(2, "tarfile: Excluded %r" % name)
2061
+ return
2062
+
2063
+ # Skip if somebody tries to archive the archive...
2064
+ if self.name is not None and os.path.abspath(name) == self.name:
2065
+ self._dbg(2, "tarfile: Skipped %r" % name)
2066
+ return
2067
+
2068
+ self._dbg(1, name)
2069
+
2070
+ # Create a TarInfo object from the file.
2071
+ tarinfo = self.gettarinfo(name, arcname)
2072
+
2073
+ if tarinfo is None:
2074
+ self._dbg(1, "tarfile: Unsupported type %r" % name)
2075
+ return
2076
+
2077
+ # Change or exclude the TarInfo object.
2078
+ if filter is not None:
2079
+ tarinfo = filter(tarinfo)
2080
+ if tarinfo is None:
2081
+ self._dbg(2, "tarfile: Excluded %r" % name)
2082
+ return
2083
+
2084
+ # Append the tar header and data to the archive.
2085
+ if tarinfo.isreg():
2086
+ f = bltn_open(name, "rb")
2087
+ self.addfile(tarinfo, f)
2088
+ f.close()
2089
+
2090
+ elif tarinfo.isdir():
2091
+ self.addfile(tarinfo)
2092
+ if recursive:
2093
+ for f in os.listdir(name):
2094
+ self.add(os.path.join(name, f), os.path.join(arcname, f),
2095
+ recursive, exclude, filter=filter)
2096
+
2097
+ else:
2098
+ self.addfile(tarinfo)
2099
+
2100
+ def addfile(self, tarinfo, fileobj=None):
2101
+ """Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
2102
+ given, tarinfo.size bytes are read from it and added to the archive.
2103
+ You can create TarInfo objects using gettarinfo().
2104
+ On Windows platforms, `fileobj' should always be opened with mode
2105
+ 'rb' to avoid irritation about the file size.
2106
+ """
2107
+ self._check("aw")
2108
+
2109
+ tarinfo = copy.copy(tarinfo)
2110
+
2111
+ buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
2112
+ self.fileobj.write(buf)
2113
+ self.offset += len(buf)
2114
+
2115
+ # If there's data to follow, append it.
2116
+ if fileobj is not None:
2117
+ copyfileobj(fileobj, self.fileobj, tarinfo.size)
2118
+ blocks, remainder = divmod(tarinfo.size, BLOCKSIZE)
2119
+ if remainder > 0:
2120
+ self.fileobj.write(NUL * (BLOCKSIZE - remainder))
2121
+ blocks += 1
2122
+ self.offset += blocks * BLOCKSIZE
2123
+
2124
+ self.members.append(tarinfo)
2125
+
2126
+ def extractall(self, path=".", members=None):
2127
+ """Extract all members from the archive to the current working
2128
+ directory and set owner, modification time and permissions on
2129
+ directories afterwards. `path' specifies a different directory
2130
+ to extract to. `members' is optional and must be a subset of the
2131
+ list returned by getmembers().
2132
+ """
2133
+ directories = []
2134
+
2135
+ if members is None:
2136
+ members = self
2137
+
2138
+ for tarinfo in members:
2139
+ if tarinfo.isdir():
2140
+ # Extract directories with a safe mode.
2141
+ directories.append(tarinfo)
2142
+ tarinfo = copy.copy(tarinfo)
2143
+ tarinfo.mode = 0o700
2144
+ # Do not set_attrs directories, as we will do that further down
2145
+ self.extract(tarinfo, path, set_attrs=not tarinfo.isdir())
2146
+
2147
+ # Reverse sort directories.
2148
+ directories.sort(key=lambda a: a.name)
2149
+ directories.reverse()
2150
+
2151
+ # Set correct owner, mtime and filemode on directories.
2152
+ for tarinfo in directories:
2153
+ dirpath = os.path.join(path, tarinfo.name)
2154
+ try:
2155
+ self.chown(tarinfo, dirpath)
2156
+ self.utime(tarinfo, dirpath)
2157
+ self.chmod(tarinfo, dirpath)
2158
+ except ExtractError as e:
2159
+ if self.errorlevel > 1:
2160
+ raise
2161
+ else:
2162
+ self._dbg(1, "tarfile: %s" % e)
2163
+
2164
+ def extract(self, member, path="", set_attrs=True):
2165
+ """Extract a member from the archive to the current working directory,
2166
+ using its full name. Its file information is extracted as accurately
2167
+ as possible. `member' may be a filename or a TarInfo object. You can
2168
+ specify a different directory using `path'. File attributes (owner,
2169
+ mtime, mode) are set unless `set_attrs' is False.
2170
+ """
2171
+ self._check("r")
2172
+
2173
+ if isinstance(member, str):
2174
+ tarinfo = self.getmember(member)
2175
+ else:
2176
+ tarinfo = member
2177
+
2178
+ # Prepare the link target for makelink().
2179
+ if tarinfo.islnk():
2180
+ tarinfo._link_target = os.path.join(path, tarinfo.linkname)
2181
+
2182
+ try:
2183
+ self._extract_member(tarinfo, os.path.join(path, tarinfo.name),
2184
+ set_attrs=set_attrs)
2185
+ except EnvironmentError as e:
2186
+ if self.errorlevel > 0:
2187
+ raise
2188
+ else:
2189
+ if e.filename is None:
2190
+ self._dbg(1, "tarfile: %s" % e.strerror)
2191
+ else:
2192
+ self._dbg(1, "tarfile: %s %r" % (e.strerror, e.filename))
2193
+ except ExtractError as e:
2194
+ if self.errorlevel > 1:
2195
+ raise
2196
+ else:
2197
+ self._dbg(1, "tarfile: %s" % e)
2198
+
2199
+ def extractfile(self, member):
2200
+ """Extract a member from the archive as a file object. `member' may be
2201
+ a filename or a TarInfo object. If `member' is a regular file, a
2202
+ file-like object is returned. If `member' is a link, a file-like
2203
+ object is constructed from the link's target. If `member' is none of
2204
+ the above, None is returned.
2205
+ The file-like object is read-only and provides the following
2206
+ methods: read(), readline(), readlines(), seek() and tell()
2207
+ """
2208
+ self._check("r")
2209
+
2210
+ if isinstance(member, str):
2211
+ tarinfo = self.getmember(member)
2212
+ else:
2213
+ tarinfo = member
2214
+
2215
+ if tarinfo.isreg():
2216
+ return self.fileobject(self, tarinfo)
2217
+
2218
+ elif tarinfo.type not in SUPPORTED_TYPES:
2219
+ # If a member's type is unknown, it is treated as a
2220
+ # regular file.
2221
+ return self.fileobject(self, tarinfo)
2222
+
2223
+ elif tarinfo.islnk() or tarinfo.issym():
2224
+ if isinstance(self.fileobj, _Stream):
2225
+ # A small but ugly workaround for the case that someone tries
2226
+ # to extract a (sym)link as a file-object from a non-seekable
2227
+ # stream of tar blocks.
2228
+ raise StreamError("cannot extract (sym)link as file object")
2229
+ else:
2230
+ # A (sym)link's file object is its target's file object.
2231
+ return self.extractfile(self._find_link_target(tarinfo))
2232
+ else:
2233
+ # If there's no data associated with the member (directory, chrdev,
2234
+ # blkdev, etc.), return None instead of a file object.
2235
+ return None
2236
+
2237
+ def _extract_member(self, tarinfo, targetpath, set_attrs=True):
2238
+ """Extract the TarInfo object tarinfo to a physical
2239
+ file called targetpath.
2240
+ """
2241
+ # Fetch the TarInfo object for the given name
2242
+ # and build the destination pathname, replacing
2243
+ # forward slashes to platform specific separators.
2244
+ targetpath = targetpath.rstrip("/")
2245
+ targetpath = targetpath.replace("/", os.sep)
2246
+
2247
+ # Create all upper directories.
2248
+ upperdirs = os.path.dirname(targetpath)
2249
+ if upperdirs and not os.path.exists(upperdirs):
2250
+ # Create directories that are not part of the archive with
2251
+ # default permissions.
2252
+ os.makedirs(upperdirs)
2253
+
2254
+ if tarinfo.islnk() or tarinfo.issym():
2255
+ self._dbg(1, "%s -> %s" % (tarinfo.name, tarinfo.linkname))
2256
+ else:
2257
+ self._dbg(1, tarinfo.name)
2258
+
2259
+ if tarinfo.isreg():
2260
+ self.makefile(tarinfo, targetpath)
2261
+ elif tarinfo.isdir():
2262
+ self.makedir(tarinfo, targetpath)
2263
+ elif tarinfo.isfifo():
2264
+ self.makefifo(tarinfo, targetpath)
2265
+ elif tarinfo.ischr() or tarinfo.isblk():
2266
+ self.makedev(tarinfo, targetpath)
2267
+ elif tarinfo.islnk() or tarinfo.issym():
2268
+ self.makelink(tarinfo, targetpath)
2269
+ elif tarinfo.type not in SUPPORTED_TYPES:
2270
+ self.makeunknown(tarinfo, targetpath)
2271
+ else:
2272
+ self.makefile(tarinfo, targetpath)
2273
+
2274
+ if set_attrs:
2275
+ self.chown(tarinfo, targetpath)
2276
+ if not tarinfo.issym():
2277
+ self.chmod(tarinfo, targetpath)
2278
+ self.utime(tarinfo, targetpath)
2279
+
2280
+ #--------------------------------------------------------------------------
2281
+ # Below are the different file methods. They are called via
2282
+ # _extract_member() when extract() is called. They can be replaced in a
2283
+ # subclass to implement other functionality.
2284
+
2285
+ def makedir(self, tarinfo, targetpath):
2286
+ """Make a directory called targetpath.
2287
+ """
2288
+ try:
2289
+ # Use a safe mode for the directory, the real mode is set
2290
+ # later in _extract_member().
2291
+ os.mkdir(targetpath, 0o700)
2292
+ except EnvironmentError as e:
2293
+ if e.errno != errno.EEXIST:
2294
+ raise
2295
+
2296
+ def makefile(self, tarinfo, targetpath):
2297
+ """Make a file called targetpath.
2298
+ """
2299
+ source = self.fileobj
2300
+ source.seek(tarinfo.offset_data)
2301
+ target = bltn_open(targetpath, "wb")
2302
+ if tarinfo.sparse is not None:
2303
+ for offset, size in tarinfo.sparse:
2304
+ target.seek(offset)
2305
+ copyfileobj(source, target, size)
2306
+ else:
2307
+ copyfileobj(source, target, tarinfo.size)
2308
+ target.seek(tarinfo.size)
2309
+ target.truncate()
2310
+ target.close()
2311
+
2312
+ def makeunknown(self, tarinfo, targetpath):
2313
+ """Make a file from a TarInfo object with an unknown type
2314
+ at targetpath.
2315
+ """
2316
+ self.makefile(tarinfo, targetpath)
2317
+ self._dbg(1, "tarfile: Unknown file type %r, " \
2318
+ "extracted as regular file." % tarinfo.type)
2319
+
2320
+ def makefifo(self, tarinfo, targetpath):
2321
+ """Make a fifo called targetpath.
2322
+ """
2323
+ if hasattr(os, "mkfifo"):
2324
+ os.mkfifo(targetpath)
2325
+ else:
2326
+ raise ExtractError("fifo not supported by system")
2327
+
2328
+ def makedev(self, tarinfo, targetpath):
2329
+ """Make a character or block device called targetpath.
2330
+ """
2331
+ if not hasattr(os, "mknod") or not hasattr(os, "makedev"):
2332
+ raise ExtractError("special devices not supported by system")
2333
+
2334
+ mode = tarinfo.mode
2335
+ if tarinfo.isblk():
2336
+ mode |= stat.S_IFBLK
2337
+ else:
2338
+ mode |= stat.S_IFCHR
2339
+
2340
+ os.mknod(targetpath, mode,
2341
+ os.makedev(tarinfo.devmajor, tarinfo.devminor))
2342
+
2343
+ def makelink(self, tarinfo, targetpath):
2344
+ """Make a (symbolic) link called targetpath. If it cannot be created
2345
+ (platform limitation), we try to make a copy of the referenced file
2346
+ instead of a link.
2347
+ """
2348
+ try:
2349
+ # For systems that support symbolic and hard links.
2350
+ if tarinfo.issym():
2351
+ os.symlink(tarinfo.linkname, targetpath)
2352
+ else:
2353
+ # See extract().
2354
+ if os.path.exists(tarinfo._link_target):
2355
+ os.link(tarinfo._link_target, targetpath)
2356
+ else:
2357
+ self._extract_member(self._find_link_target(tarinfo),
2358
+ targetpath)
2359
+ except symlink_exception:
2360
+ if tarinfo.issym():
2361
+ linkpath = os.path.join(os.path.dirname(tarinfo.name),
2362
+ tarinfo.linkname)
2363
+ else:
2364
+ linkpath = tarinfo.linkname
2365
+ else:
2366
+ try:
2367
+ self._extract_member(self._find_link_target(tarinfo),
2368
+ targetpath)
2369
+ except KeyError:
2370
+ raise ExtractError("unable to resolve link inside archive")
2371
+
2372
+ def chown(self, tarinfo, targetpath):
2373
+ """Set owner of targetpath according to tarinfo.
2374
+ """
2375
+ if pwd and hasattr(os, "geteuid") and os.geteuid() == 0:
2376
+ # We have to be root to do so.
2377
+ try:
2378
+ g = grp.getgrnam(tarinfo.gname)[2]
2379
+ except KeyError:
2380
+ g = tarinfo.gid
2381
+ try:
2382
+ u = pwd.getpwnam(tarinfo.uname)[2]
2383
+ except KeyError:
2384
+ u = tarinfo.uid
2385
+ try:
2386
+ if tarinfo.issym() and hasattr(os, "lchown"):
2387
+ os.lchown(targetpath, u, g)
2388
+ else:
2389
+ if sys.platform != "os2emx":
2390
+ os.chown(targetpath, u, g)
2391
+ except EnvironmentError as e:
2392
+ raise ExtractError("could not change owner")
2393
+
2394
+ def chmod(self, tarinfo, targetpath):
2395
+ """Set file permissions of targetpath according to tarinfo.
2396
+ """
2397
+ if hasattr(os, 'chmod'):
2398
+ try:
2399
+ os.chmod(targetpath, tarinfo.mode)
2400
+ except EnvironmentError as e:
2401
+ raise ExtractError("could not change mode")
2402
+
2403
+ def utime(self, tarinfo, targetpath):
2404
+ """Set modification time of targetpath according to tarinfo.
2405
+ """
2406
+ if not hasattr(os, 'utime'):
2407
+ return
2408
+ try:
2409
+ os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime))
2410
+ except EnvironmentError as e:
2411
+ raise ExtractError("could not change modification time")
2412
+
2413
+ #--------------------------------------------------------------------------
2414
+ def next(self):
2415
+ """Return the next member of the archive as a TarInfo object, when
2416
+ TarFile is opened for reading. Return None if there is no more
2417
+ available.
2418
+ """
2419
+ self._check("ra")
2420
+ if self.firstmember is not None:
2421
+ m = self.firstmember
2422
+ self.firstmember = None
2423
+ return m
2424
+
2425
+ # Read the next block.
2426
+ self.fileobj.seek(self.offset)
2427
+ tarinfo = None
2428
+ while True:
2429
+ try:
2430
+ tarinfo = self.tarinfo.fromtarfile(self)
2431
+ except EOFHeaderError as e:
2432
+ if self.ignore_zeros:
2433
+ self._dbg(2, "0x%X: %s" % (self.offset, e))
2434
+ self.offset += BLOCKSIZE
2435
+ continue
2436
+ except InvalidHeaderError as e:
2437
+ if self.ignore_zeros:
2438
+ self._dbg(2, "0x%X: %s" % (self.offset, e))
2439
+ self.offset += BLOCKSIZE
2440
+ continue
2441
+ elif self.offset == 0:
2442
+ raise ReadError(str(e))
2443
+ except EmptyHeaderError:
2444
+ if self.offset == 0:
2445
+ raise ReadError("empty file")
2446
+ except TruncatedHeaderError as e:
2447
+ if self.offset == 0:
2448
+ raise ReadError(str(e))
2449
+ except SubsequentHeaderError as e:
2450
+ raise ReadError(str(e))
2451
+ break
2452
+
2453
+ if tarinfo is not None:
2454
+ self.members.append(tarinfo)
2455
+ else:
2456
+ self._loaded = True
2457
+
2458
+ return tarinfo
2459
+
2460
+ #--------------------------------------------------------------------------
2461
+ # Little helper methods:
2462
+
2463
+ def _getmember(self, name, tarinfo=None, normalize=False):
2464
+ """Find an archive member by name from bottom to top.
2465
+ If tarinfo is given, it is used as the starting point.
2466
+ """
2467
+ # Ensure that all members have been loaded.
2468
+ members = self.getmembers()
2469
+
2470
+ # Limit the member search list up to tarinfo.
2471
+ if tarinfo is not None:
2472
+ members = members[:members.index(tarinfo)]
2473
+
2474
+ if normalize:
2475
+ name = os.path.normpath(name)
2476
+
2477
+ for member in reversed(members):
2478
+ if normalize:
2479
+ member_name = os.path.normpath(member.name)
2480
+ else:
2481
+ member_name = member.name
2482
+
2483
+ if name == member_name:
2484
+ return member
2485
+
2486
+ def _load(self):
2487
+ """Read through the entire archive file and look for readable
2488
+ members.
2489
+ """
2490
+ while True:
2491
+ tarinfo = self.next()
2492
+ if tarinfo is None:
2493
+ break
2494
+ self._loaded = True
2495
+
2496
+ def _check(self, mode=None):
2497
+ """Check if TarFile is still open, and if the operation's mode
2498
+ corresponds to TarFile's mode.
2499
+ """
2500
+ if self.closed:
2501
+ raise IOError("%s is closed" % self.__class__.__name__)
2502
+ if mode is not None and self.mode not in mode:
2503
+ raise IOError("bad operation for mode %r" % self.mode)
2504
+
2505
+ def _find_link_target(self, tarinfo):
2506
+ """Find the target member of a symlink or hardlink member in the
2507
+ archive.
2508
+ """
2509
+ if tarinfo.issym():
2510
+ # Always search the entire archive.
2511
+ linkname = os.path.dirname(tarinfo.name) + "/" + tarinfo.linkname
2512
+ limit = None
2513
+ else:
2514
+ # Search the archive before the link, because a hard link is
2515
+ # just a reference to an already archived file.
2516
+ linkname = tarinfo.linkname
2517
+ limit = tarinfo
2518
+
2519
+ member = self._getmember(linkname, tarinfo=limit, normalize=True)
2520
+ if member is None:
2521
+ raise KeyError("linkname %r not found" % linkname)
2522
+ return member
2523
+
2524
+ def __iter__(self):
2525
+ """Provide an iterator object.
2526
+ """
2527
+ if self._loaded:
2528
+ return iter(self.members)
2529
+ else:
2530
+ return TarIter(self)
2531
+
2532
+ def _dbg(self, level, msg):
2533
+ """Write debugging output to sys.stderr.
2534
+ """
2535
+ if level <= self.debug:
2536
+ print(msg, file=sys.stderr)
2537
+
2538
+ def __enter__(self):
2539
+ self._check()
2540
+ return self
2541
+
2542
+ def __exit__(self, type, value, traceback):
2543
+ if type is None:
2544
+ self.close()
2545
+ else:
2546
+ # An exception occurred. We must not call close() because
2547
+ # it would try to write end-of-archive blocks and padding.
2548
+ if not self._extfileobj:
2549
+ self.fileobj.close()
2550
+ self.closed = True
2551
+ # class TarFile
2552
+
2553
+ class TarIter(object):
2554
+ """Iterator Class.
2555
+
2556
+ for tarinfo in TarFile(...):
2557
+ suite...
2558
+ """
2559
+
2560
+ def __init__(self, tarfile):
2561
+ """Construct a TarIter object.
2562
+ """
2563
+ self.tarfile = tarfile
2564
+ self.index = 0
2565
+ def __iter__(self):
2566
+ """Return iterator object.
2567
+ """
2568
+ return self
2569
+
2570
+ def __next__(self):
2571
+ """Return the next item using TarFile's next() method.
2572
+ When all members have been read, set TarFile as _loaded.
2573
+ """
2574
+ # Fix for SF #1100429: Under rare circumstances it can
2575
+ # happen that getmembers() is called during iteration,
2576
+ # which will cause TarIter to stop prematurely.
2577
+ if not self.tarfile._loaded:
2578
+ tarinfo = self.tarfile.next()
2579
+ if not tarinfo:
2580
+ self.tarfile._loaded = True
2581
+ raise StopIteration
2582
+ else:
2583
+ try:
2584
+ tarinfo = self.tarfile.members[self.index]
2585
+ except IndexError:
2586
+ raise StopIteration
2587
+ self.index += 1
2588
+ return tarinfo
2589
+
2590
+ next = __next__ # for Python 2.x
2591
+
2592
+ #--------------------
2593
+ # exported functions
2594
+ #--------------------
2595
+ def is_tarfile(name):
2596
+ """Return True if name points to a tar archive that we
2597
+ are able to handle, else return False.
2598
+ """
2599
+ try:
2600
+ t = open(name)
2601
+ t.close()
2602
+ return True
2603
+ except TarError:
2604
+ return False
2605
+
2606
+ bltn_open = open
2607
+ open = TarFile.open