@tedbrain/vlink 0.0.0-dpv2.ted-runner.python-linux-x64.3.9.0-dpv2.1.r6 → 0.0.0-dpv2.ted-runner.vlink-linux-x64.0.2.24.r6

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 (660) hide show
  1. package/bin/vlink +0 -0
  2. package/package.json +1 -1
  3. package/bin/python3 +0 -0
  4. package/lib/libX11.so.6 +0 -0
  5. package/lib/libXau.so.6 +0 -0
  6. package/lib/libXdmcp.so.6 +0 -0
  7. package/lib/libcrypt.so.1 +0 -0
  8. package/lib/libcrypto.so.1.1 +0 -0
  9. package/lib/libffi.so.7 +0 -0
  10. package/lib/libfreebl3.so +0 -0
  11. package/lib/liblzma.so.5 +0 -0
  12. package/lib/libncursesw.so.6 +0 -0
  13. package/lib/libnsl.so.1 +0 -0
  14. package/lib/libpanelw.so.6 +0 -0
  15. package/lib/libpython3.9.so.1.0 +0 -0
  16. package/lib/libreadline.so.8 +0 -0
  17. package/lib/libsqlite3.so.0 +0 -0
  18. package/lib/libssl.so.1.1 +0 -0
  19. package/lib/libtcl8.6.so +0 -0
  20. package/lib/libtinfow.so.6 +0 -0
  21. package/lib/libtk8.6.so +0 -0
  22. package/lib/libxcb.so.1 +0 -0
  23. package/lib/libz.so.1 +0 -0
  24. package/lib/python3.9/LICENSE.txt +0 -279
  25. package/lib/python3.9/__future__.py +0 -147
  26. package/lib/python3.9/__phello__.foo.py +0 -1
  27. package/lib/python3.9/_aix_support.py +0 -89
  28. package/lib/python3.9/_bootlocale.py +0 -46
  29. package/lib/python3.9/_bootsubprocess.py +0 -97
  30. package/lib/python3.9/_collections_abc.py +0 -1031
  31. package/lib/python3.9/_compat_pickle.py +0 -251
  32. package/lib/python3.9/_compression.py +0 -152
  33. package/lib/python3.9/_markupbase.py +0 -395
  34. package/lib/python3.9/_osx_support.py +0 -515
  35. package/lib/python3.9/_py_abc.py +0 -147
  36. package/lib/python3.9/_pydecimal.py +0 -6410
  37. package/lib/python3.9/_pyio.py +0 -2692
  38. package/lib/python3.9/_sitebuiltins.py +0 -103
  39. package/lib/python3.9/_strptime.py +0 -579
  40. package/lib/python3.9/_sysconfigdata__linux_x86_64-linux-gnu.py +0 -969
  41. package/lib/python3.9/_sysconfigdata__linux_x86_64-linux-gnu.py.orig +0 -969
  42. package/lib/python3.9/_sysconfigdata_x86_64_conda_cos6_linux_gnu.py +0 -969
  43. package/lib/python3.9/_threading_local.py +0 -242
  44. package/lib/python3.9/_weakrefset.py +0 -202
  45. package/lib/python3.9/abc.py +0 -129
  46. package/lib/python3.9/aifc.py +0 -947
  47. package/lib/python3.9/antigravity.py +0 -17
  48. package/lib/python3.9/argparse.py +0 -2575
  49. package/lib/python3.9/ast.py +0 -1530
  50. package/lib/python3.9/asynchat.py +0 -307
  51. package/lib/python3.9/asyncio/__init__.py +0 -47
  52. package/lib/python3.9/asyncio/__main__.py +0 -125
  53. package/lib/python3.9/asyncio/base_events.py +0 -1915
  54. package/lib/python3.9/asyncio/base_futures.py +0 -61
  55. package/lib/python3.9/asyncio/base_subprocess.py +0 -285
  56. package/lib/python3.9/asyncio/base_tasks.py +0 -85
  57. package/lib/python3.9/asyncio/constants.py +0 -27
  58. package/lib/python3.9/asyncio/coroutines.py +0 -269
  59. package/lib/python3.9/asyncio/events.py +0 -795
  60. package/lib/python3.9/asyncio/exceptions.py +0 -57
  61. package/lib/python3.9/asyncio/format_helpers.py +0 -76
  62. package/lib/python3.9/asyncio/futures.py +0 -423
  63. package/lib/python3.9/asyncio/locks.py +0 -451
  64. package/lib/python3.9/asyncio/log.py +0 -7
  65. package/lib/python3.9/asyncio/proactor_events.py +0 -868
  66. package/lib/python3.9/asyncio/protocols.py +0 -220
  67. package/lib/python3.9/asyncio/queues.py +0 -252
  68. package/lib/python3.9/asyncio/runners.py +0 -74
  69. package/lib/python3.9/asyncio/selector_events.py +0 -1099
  70. package/lib/python3.9/asyncio/sslproto.py +0 -733
  71. package/lib/python3.9/asyncio/staggered.py +0 -149
  72. package/lib/python3.9/asyncio/streams.py +0 -741
  73. package/lib/python3.9/asyncio/subprocess.py +0 -241
  74. package/lib/python3.9/asyncio/tasks.py +0 -980
  75. package/lib/python3.9/asyncio/threads.py +0 -25
  76. package/lib/python3.9/asyncio/transports.py +0 -329
  77. package/lib/python3.9/asyncio/trsock.py +0 -206
  78. package/lib/python3.9/asyncio/unix_events.py +0 -1466
  79. package/lib/python3.9/asyncio/windows_events.py +0 -908
  80. package/lib/python3.9/asyncio/windows_utils.py +0 -173
  81. package/lib/python3.9/asyncore.py +0 -642
  82. package/lib/python3.9/base64.py +0 -579
  83. package/lib/python3.9/bdb.py +0 -864
  84. package/lib/python3.9/binhex.py +0 -502
  85. package/lib/python3.9/bisect.py +0 -80
  86. package/lib/python3.9/bz2.py +0 -350
  87. package/lib/python3.9/cProfile.py +0 -180
  88. package/lib/python3.9/calendar.py +0 -770
  89. package/lib/python3.9/cgi.py +0 -996
  90. package/lib/python3.9/cgitb.py +0 -321
  91. package/lib/python3.9/chunk.py +0 -169
  92. package/lib/python3.9/cmd.py +0 -401
  93. package/lib/python3.9/code.py +0 -315
  94. package/lib/python3.9/codecs.py +0 -1126
  95. package/lib/python3.9/codeop.py +0 -178
  96. package/lib/python3.9/collections/__init__.py +0 -1508
  97. package/lib/python3.9/collections/abc.py +0 -2
  98. package/lib/python3.9/colorsys.py +0 -164
  99. package/lib/python3.9/compileall.py +0 -461
  100. package/lib/python3.9/concurrent/__init__.py +0 -1
  101. package/lib/python3.9/concurrent/futures/__init__.py +0 -53
  102. package/lib/python3.9/concurrent/futures/_base.py +0 -635
  103. package/lib/python3.9/concurrent/futures/process.py +0 -751
  104. package/lib/python3.9/concurrent/futures/thread.py +0 -230
  105. package/lib/python3.9/config-3.9-x86_64-linux-gnu/Makefile +0 -2015
  106. package/lib/python3.9/config-3.9-x86_64-linux-gnu/Setup +0 -372
  107. package/lib/python3.9/config-3.9-x86_64-linux-gnu/Setup.local +0 -1
  108. package/lib/python3.9/config-3.9-x86_64-linux-gnu/config.c +0 -116
  109. package/lib/python3.9/config-3.9-x86_64-linux-gnu/config.c.in +0 -67
  110. package/lib/python3.9/config-3.9-x86_64-linux-gnu/install-sh +0 -518
  111. package/lib/python3.9/config-3.9-x86_64-linux-gnu/makesetup +0 -309
  112. package/lib/python3.9/config-3.9-x86_64-linux-gnu/python-config.py +0 -74
  113. package/lib/python3.9/config-3.9-x86_64-linux-gnu/python.o +0 -0
  114. package/lib/python3.9/configparser.py +0 -1363
  115. package/lib/python3.9/contextlib.py +0 -676
  116. package/lib/python3.9/contextvars.py +0 -4
  117. package/lib/python3.9/copy.py +0 -303
  118. package/lib/python3.9/copyreg.py +0 -209
  119. package/lib/python3.9/crypt.py +0 -120
  120. package/lib/python3.9/csv.py +0 -448
  121. package/lib/python3.9/ctypes/__init__.py +0 -571
  122. package/lib/python3.9/ctypes/_aix.py +0 -331
  123. package/lib/python3.9/ctypes/_endian.py +0 -61
  124. package/lib/python3.9/ctypes/macholib/README.ctypes +0 -7
  125. package/lib/python3.9/ctypes/macholib/__init__.py +0 -9
  126. package/lib/python3.9/ctypes/macholib/dyld.py +0 -182
  127. package/lib/python3.9/ctypes/macholib/dylib.py +0 -63
  128. package/lib/python3.9/ctypes/macholib/fetch_macholib +0 -2
  129. package/lib/python3.9/ctypes/macholib/fetch_macholib.bat +0 -1
  130. package/lib/python3.9/ctypes/macholib/framework.py +0 -65
  131. package/lib/python3.9/ctypes/util.py +0 -379
  132. package/lib/python3.9/ctypes/wintypes.py +0 -202
  133. package/lib/python3.9/curses/__init__.py +0 -101
  134. package/lib/python3.9/curses/ascii.py +0 -99
  135. package/lib/python3.9/curses/has_key.py +0 -192
  136. package/lib/python3.9/curses/panel.py +0 -6
  137. package/lib/python3.9/curses/textpad.py +0 -201
  138. package/lib/python3.9/dataclasses.py +0 -1284
  139. package/lib/python3.9/datetime.py +0 -2555
  140. package/lib/python3.9/dbm/__init__.py +0 -189
  141. package/lib/python3.9/dbm/dumb.py +0 -316
  142. package/lib/python3.9/dbm/gnu.py +0 -3
  143. package/lib/python3.9/dbm/ndbm.py +0 -3
  144. package/lib/python3.9/decimal.py +0 -11
  145. package/lib/python3.9/difflib.py +0 -2096
  146. package/lib/python3.9/dis.py +0 -553
  147. package/lib/python3.9/distutils/README +0 -11
  148. package/lib/python3.9/distutils/__init__.py +0 -13
  149. package/lib/python3.9/distutils/_msvccompiler.py +0 -546
  150. package/lib/python3.9/distutils/archive_util.py +0 -256
  151. package/lib/python3.9/distutils/bcppcompiler.py +0 -393
  152. package/lib/python3.9/distutils/ccompiler.py +0 -1116
  153. package/lib/python3.9/distutils/cmd.py +0 -403
  154. package/lib/python3.9/distutils/command/__init__.py +0 -31
  155. package/lib/python3.9/distutils/command/bdist.py +0 -143
  156. package/lib/python3.9/distutils/command/bdist_dumb.py +0 -123
  157. package/lib/python3.9/distutils/command/bdist_msi.py +0 -749
  158. package/lib/python3.9/distutils/command/bdist_rpm.py +0 -579
  159. package/lib/python3.9/distutils/command/bdist_wininst.py +0 -377
  160. package/lib/python3.9/distutils/command/build.py +0 -157
  161. package/lib/python3.9/distutils/command/build_clib.py +0 -209
  162. package/lib/python3.9/distutils/command/build_ext.py +0 -754
  163. package/lib/python3.9/distutils/command/build_py.py +0 -416
  164. package/lib/python3.9/distutils/command/build_scripts.py +0 -160
  165. package/lib/python3.9/distutils/command/check.py +0 -148
  166. package/lib/python3.9/distutils/command/clean.py +0 -76
  167. package/lib/python3.9/distutils/command/command_template +0 -33
  168. package/lib/python3.9/distutils/command/config.py +0 -344
  169. package/lib/python3.9/distutils/command/install.py +0 -657
  170. package/lib/python3.9/distutils/command/install_data.py +0 -79
  171. package/lib/python3.9/distutils/command/install_egg_info.py +0 -77
  172. package/lib/python3.9/distutils/command/install_headers.py +0 -47
  173. package/lib/python3.9/distutils/command/install_lib.py +0 -217
  174. package/lib/python3.9/distutils/command/install_scripts.py +0 -60
  175. package/lib/python3.9/distutils/command/register.py +0 -304
  176. package/lib/python3.9/distutils/command/sdist.py +0 -494
  177. package/lib/python3.9/distutils/command/upload.py +0 -214
  178. package/lib/python3.9/distutils/config.py +0 -130
  179. package/lib/python3.9/distutils/core.py +0 -234
  180. package/lib/python3.9/distutils/cygwinccompiler.py +0 -410
  181. package/lib/python3.9/distutils/debug.py +0 -5
  182. package/lib/python3.9/distutils/dep_util.py +0 -92
  183. package/lib/python3.9/distutils/dir_util.py +0 -210
  184. package/lib/python3.9/distutils/dist.py +0 -1256
  185. package/lib/python3.9/distutils/errors.py +0 -97
  186. package/lib/python3.9/distutils/extension.py +0 -240
  187. package/lib/python3.9/distutils/fancy_getopt.py +0 -457
  188. package/lib/python3.9/distutils/file_util.py +0 -238
  189. package/lib/python3.9/distutils/filelist.py +0 -327
  190. package/lib/python3.9/distutils/log.py +0 -77
  191. package/lib/python3.9/distutils/msvc9compiler.py +0 -788
  192. package/lib/python3.9/distutils/msvccompiler.py +0 -643
  193. package/lib/python3.9/distutils/spawn.py +0 -125
  194. package/lib/python3.9/distutils/sysconfig.py +0 -560
  195. package/lib/python3.9/distutils/text_file.py +0 -286
  196. package/lib/python3.9/distutils/unixccompiler.py +0 -330
  197. package/lib/python3.9/distutils/util.py +0 -559
  198. package/lib/python3.9/distutils/version.py +0 -347
  199. package/lib/python3.9/distutils/versionpredicate.py +0 -166
  200. package/lib/python3.9/doctest.py +0 -2793
  201. package/lib/python3.9/email/__init__.py +0 -62
  202. package/lib/python3.9/email/_encoded_words.py +0 -233
  203. package/lib/python3.9/email/_header_value_parser.py +0 -3003
  204. package/lib/python3.9/email/_parseaddr.py +0 -549
  205. package/lib/python3.9/email/_policybase.py +0 -374
  206. package/lib/python3.9/email/architecture.rst +0 -216
  207. package/lib/python3.9/email/base64mime.py +0 -119
  208. package/lib/python3.9/email/charset.py +0 -404
  209. package/lib/python3.9/email/contentmanager.py +0 -250
  210. package/lib/python3.9/email/encoders.py +0 -69
  211. package/lib/python3.9/email/errors.py +0 -110
  212. package/lib/python3.9/email/feedparser.py +0 -536
  213. package/lib/python3.9/email/generator.py +0 -508
  214. package/lib/python3.9/email/header.py +0 -578
  215. package/lib/python3.9/email/headerregistry.py +0 -601
  216. package/lib/python3.9/email/iterators.py +0 -71
  217. package/lib/python3.9/email/message.py +0 -1173
  218. package/lib/python3.9/email/mime/__init__.py +0 -0
  219. package/lib/python3.9/email/mime/application.py +0 -37
  220. package/lib/python3.9/email/mime/audio.py +0 -74
  221. package/lib/python3.9/email/mime/base.py +0 -30
  222. package/lib/python3.9/email/mime/image.py +0 -47
  223. package/lib/python3.9/email/mime/message.py +0 -34
  224. package/lib/python3.9/email/mime/multipart.py +0 -48
  225. package/lib/python3.9/email/mime/nonmultipart.py +0 -22
  226. package/lib/python3.9/email/mime/text.py +0 -42
  227. package/lib/python3.9/email/parser.py +0 -131
  228. package/lib/python3.9/email/policy.py +0 -224
  229. package/lib/python3.9/email/quoprimime.py +0 -299
  230. package/lib/python3.9/email/utils.py +0 -368
  231. package/lib/python3.9/encodings/__init__.py +0 -169
  232. package/lib/python3.9/encodings/aliases.py +0 -551
  233. package/lib/python3.9/encodings/ascii.py +0 -50
  234. package/lib/python3.9/encodings/base64_codec.py +0 -55
  235. package/lib/python3.9/encodings/big5.py +0 -39
  236. package/lib/python3.9/encodings/big5hkscs.py +0 -39
  237. package/lib/python3.9/encodings/bz2_codec.py +0 -78
  238. package/lib/python3.9/encodings/charmap.py +0 -69
  239. package/lib/python3.9/encodings/cp037.py +0 -307
  240. package/lib/python3.9/encodings/cp1006.py +0 -307
  241. package/lib/python3.9/encodings/cp1026.py +0 -307
  242. package/lib/python3.9/encodings/cp1125.py +0 -698
  243. package/lib/python3.9/encodings/cp1140.py +0 -307
  244. package/lib/python3.9/encodings/cp1250.py +0 -307
  245. package/lib/python3.9/encodings/cp1251.py +0 -307
  246. package/lib/python3.9/encodings/cp1252.py +0 -307
  247. package/lib/python3.9/encodings/cp1253.py +0 -307
  248. package/lib/python3.9/encodings/cp1254.py +0 -307
  249. package/lib/python3.9/encodings/cp1255.py +0 -307
  250. package/lib/python3.9/encodings/cp1256.py +0 -307
  251. package/lib/python3.9/encodings/cp1257.py +0 -307
  252. package/lib/python3.9/encodings/cp1258.py +0 -307
  253. package/lib/python3.9/encodings/cp273.py +0 -307
  254. package/lib/python3.9/encodings/cp424.py +0 -307
  255. package/lib/python3.9/encodings/cp437.py +0 -698
  256. package/lib/python3.9/encodings/cp500.py +0 -307
  257. package/lib/python3.9/encodings/cp720.py +0 -309
  258. package/lib/python3.9/encodings/cp737.py +0 -698
  259. package/lib/python3.9/encodings/cp775.py +0 -697
  260. package/lib/python3.9/encodings/cp850.py +0 -698
  261. package/lib/python3.9/encodings/cp852.py +0 -698
  262. package/lib/python3.9/encodings/cp855.py +0 -698
  263. package/lib/python3.9/encodings/cp856.py +0 -307
  264. package/lib/python3.9/encodings/cp857.py +0 -694
  265. package/lib/python3.9/encodings/cp858.py +0 -698
  266. package/lib/python3.9/encodings/cp860.py +0 -698
  267. package/lib/python3.9/encodings/cp861.py +0 -698
  268. package/lib/python3.9/encodings/cp862.py +0 -698
  269. package/lib/python3.9/encodings/cp863.py +0 -698
  270. package/lib/python3.9/encodings/cp864.py +0 -690
  271. package/lib/python3.9/encodings/cp865.py +0 -698
  272. package/lib/python3.9/encodings/cp866.py +0 -698
  273. package/lib/python3.9/encodings/cp869.py +0 -689
  274. package/lib/python3.9/encodings/cp874.py +0 -307
  275. package/lib/python3.9/encodings/cp875.py +0 -307
  276. package/lib/python3.9/encodings/cp932.py +0 -39
  277. package/lib/python3.9/encodings/cp949.py +0 -39
  278. package/lib/python3.9/encodings/cp950.py +0 -39
  279. package/lib/python3.9/encodings/euc_jis_2004.py +0 -39
  280. package/lib/python3.9/encodings/euc_jisx0213.py +0 -39
  281. package/lib/python3.9/encodings/euc_jp.py +0 -39
  282. package/lib/python3.9/encodings/euc_kr.py +0 -39
  283. package/lib/python3.9/encodings/gb18030.py +0 -39
  284. package/lib/python3.9/encodings/gb2312.py +0 -39
  285. package/lib/python3.9/encodings/gbk.py +0 -39
  286. package/lib/python3.9/encodings/hex_codec.py +0 -55
  287. package/lib/python3.9/encodings/hp_roman8.py +0 -314
  288. package/lib/python3.9/encodings/hz.py +0 -39
  289. package/lib/python3.9/encodings/idna.py +0 -309
  290. package/lib/python3.9/encodings/iso2022_jp.py +0 -39
  291. package/lib/python3.9/encodings/iso2022_jp_1.py +0 -39
  292. package/lib/python3.9/encodings/iso2022_jp_2.py +0 -39
  293. package/lib/python3.9/encodings/iso2022_jp_2004.py +0 -39
  294. package/lib/python3.9/encodings/iso2022_jp_3.py +0 -39
  295. package/lib/python3.9/encodings/iso2022_jp_ext.py +0 -39
  296. package/lib/python3.9/encodings/iso2022_kr.py +0 -39
  297. package/lib/python3.9/encodings/iso8859_1.py +0 -307
  298. package/lib/python3.9/encodings/iso8859_10.py +0 -307
  299. package/lib/python3.9/encodings/iso8859_11.py +0 -307
  300. package/lib/python3.9/encodings/iso8859_13.py +0 -307
  301. package/lib/python3.9/encodings/iso8859_14.py +0 -307
  302. package/lib/python3.9/encodings/iso8859_15.py +0 -307
  303. package/lib/python3.9/encodings/iso8859_16.py +0 -307
  304. package/lib/python3.9/encodings/iso8859_2.py +0 -307
  305. package/lib/python3.9/encodings/iso8859_3.py +0 -307
  306. package/lib/python3.9/encodings/iso8859_4.py +0 -307
  307. package/lib/python3.9/encodings/iso8859_5.py +0 -307
  308. package/lib/python3.9/encodings/iso8859_6.py +0 -307
  309. package/lib/python3.9/encodings/iso8859_7.py +0 -307
  310. package/lib/python3.9/encodings/iso8859_8.py +0 -307
  311. package/lib/python3.9/encodings/iso8859_9.py +0 -307
  312. package/lib/python3.9/encodings/johab.py +0 -39
  313. package/lib/python3.9/encodings/koi8_r.py +0 -307
  314. package/lib/python3.9/encodings/koi8_t.py +0 -308
  315. package/lib/python3.9/encodings/koi8_u.py +0 -307
  316. package/lib/python3.9/encodings/kz1048.py +0 -307
  317. package/lib/python3.9/encodings/latin_1.py +0 -50
  318. package/lib/python3.9/encodings/mac_arabic.py +0 -698
  319. package/lib/python3.9/encodings/mac_croatian.py +0 -307
  320. package/lib/python3.9/encodings/mac_cyrillic.py +0 -307
  321. package/lib/python3.9/encodings/mac_farsi.py +0 -307
  322. package/lib/python3.9/encodings/mac_greek.py +0 -307
  323. package/lib/python3.9/encodings/mac_iceland.py +0 -307
  324. package/lib/python3.9/encodings/mac_latin2.py +0 -312
  325. package/lib/python3.9/encodings/mac_roman.py +0 -307
  326. package/lib/python3.9/encodings/mac_romanian.py +0 -307
  327. package/lib/python3.9/encodings/mac_turkish.py +0 -307
  328. package/lib/python3.9/encodings/mbcs.py +0 -47
  329. package/lib/python3.9/encodings/oem.py +0 -41
  330. package/lib/python3.9/encodings/palmos.py +0 -308
  331. package/lib/python3.9/encodings/ptcp154.py +0 -312
  332. package/lib/python3.9/encodings/punycode.py +0 -237
  333. package/lib/python3.9/encodings/quopri_codec.py +0 -56
  334. package/lib/python3.9/encodings/raw_unicode_escape.py +0 -45
  335. package/lib/python3.9/encodings/rot_13.py +0 -113
  336. package/lib/python3.9/encodings/shift_jis.py +0 -39
  337. package/lib/python3.9/encodings/shift_jis_2004.py +0 -39
  338. package/lib/python3.9/encodings/shift_jisx0213.py +0 -39
  339. package/lib/python3.9/encodings/tis_620.py +0 -307
  340. package/lib/python3.9/encodings/undefined.py +0 -49
  341. package/lib/python3.9/encodings/unicode_escape.py +0 -45
  342. package/lib/python3.9/encodings/utf_16.py +0 -155
  343. package/lib/python3.9/encodings/utf_16_be.py +0 -42
  344. package/lib/python3.9/encodings/utf_16_le.py +0 -42
  345. package/lib/python3.9/encodings/utf_32.py +0 -150
  346. package/lib/python3.9/encodings/utf_32_be.py +0 -37
  347. package/lib/python3.9/encodings/utf_32_le.py +0 -37
  348. package/lib/python3.9/encodings/utf_7.py +0 -38
  349. package/lib/python3.9/encodings/utf_8.py +0 -42
  350. package/lib/python3.9/encodings/utf_8_sig.py +0 -130
  351. package/lib/python3.9/encodings/uu_codec.py +0 -103
  352. package/lib/python3.9/encodings/zlib_codec.py +0 -77
  353. package/lib/python3.9/enum.py +0 -913
  354. package/lib/python3.9/filecmp.py +0 -309
  355. package/lib/python3.9/fileinput.py +0 -432
  356. package/lib/python3.9/fnmatch.py +0 -183
  357. package/lib/python3.9/formatter.py +0 -452
  358. package/lib/python3.9/fractions.py +0 -641
  359. package/lib/python3.9/ftplib.py +0 -974
  360. package/lib/python3.9/functools.py +0 -980
  361. package/lib/python3.9/genericpath.py +0 -155
  362. package/lib/python3.9/getopt.py +0 -215
  363. package/lib/python3.9/getpass.py +0 -185
  364. package/lib/python3.9/gettext.py +0 -788
  365. package/lib/python3.9/glob.py +0 -173
  366. package/lib/python3.9/graphlib.py +0 -245
  367. package/lib/python3.9/gzip.py +0 -609
  368. package/lib/python3.9/hashlib.py +0 -262
  369. package/lib/python3.9/heapq.py +0 -601
  370. package/lib/python3.9/hmac.py +0 -203
  371. package/lib/python3.9/html/__init__.py +0 -132
  372. package/lib/python3.9/html/entities.py +0 -2509
  373. package/lib/python3.9/html/parser.py +0 -462
  374. package/lib/python3.9/http/__init__.py +0 -149
  375. package/lib/python3.9/http/client.py +0 -1495
  376. package/lib/python3.9/http/cookiejar.py +0 -2113
  377. package/lib/python3.9/http/cookies.py +0 -612
  378. package/lib/python3.9/http/server.py +0 -1299
  379. package/lib/python3.9/imaplib.py +0 -1650
  380. package/lib/python3.9/imghdr.py +0 -168
  381. package/lib/python3.9/imp.py +0 -345
  382. package/lib/python3.9/importlib/__init__.py +0 -176
  383. package/lib/python3.9/importlib/_bootstrap.py +0 -1189
  384. package/lib/python3.9/importlib/_bootstrap_external.py +0 -1637
  385. package/lib/python3.9/importlib/_common.py +0 -62
  386. package/lib/python3.9/importlib/abc.py +0 -474
  387. package/lib/python3.9/importlib/machinery.py +0 -21
  388. package/lib/python3.9/importlib/metadata.py +0 -586
  389. package/lib/python3.9/importlib/resources.py +0 -215
  390. package/lib/python3.9/importlib/util.py +0 -300
  391. package/lib/python3.9/inspect.py +0 -3180
  392. package/lib/python3.9/io.py +0 -99
  393. package/lib/python3.9/ipaddress.py +0 -2280
  394. package/lib/python3.9/json/__init__.py +0 -359
  395. package/lib/python3.9/json/decoder.py +0 -356
  396. package/lib/python3.9/json/encoder.py +0 -442
  397. package/lib/python3.9/json/scanner.py +0 -73
  398. package/lib/python3.9/json/tool.py +0 -78
  399. package/lib/python3.9/keyword.py +0 -62
  400. package/lib/python3.9/lib-dynload/_asyncio.cpython-39-x86_64-linux-gnu.so +0 -0
  401. package/lib/python3.9/lib-dynload/_bisect.cpython-39-x86_64-linux-gnu.so +0 -0
  402. package/lib/python3.9/lib-dynload/_blake2.cpython-39-x86_64-linux-gnu.so +0 -0
  403. package/lib/python3.9/lib-dynload/_bz2.cpython-39-x86_64-linux-gnu.so +0 -0
  404. package/lib/python3.9/lib-dynload/_codecs_cn.cpython-39-x86_64-linux-gnu.so +0 -0
  405. package/lib/python3.9/lib-dynload/_codecs_hk.cpython-39-x86_64-linux-gnu.so +0 -0
  406. package/lib/python3.9/lib-dynload/_codecs_iso2022.cpython-39-x86_64-linux-gnu.so +0 -0
  407. package/lib/python3.9/lib-dynload/_codecs_jp.cpython-39-x86_64-linux-gnu.so +0 -0
  408. package/lib/python3.9/lib-dynload/_codecs_kr.cpython-39-x86_64-linux-gnu.so +0 -0
  409. package/lib/python3.9/lib-dynload/_codecs_tw.cpython-39-x86_64-linux-gnu.so +0 -0
  410. package/lib/python3.9/lib-dynload/_contextvars.cpython-39-x86_64-linux-gnu.so +0 -0
  411. package/lib/python3.9/lib-dynload/_crypt.cpython-39-x86_64-linux-gnu.so +0 -0
  412. package/lib/python3.9/lib-dynload/_csv.cpython-39-x86_64-linux-gnu.so +0 -0
  413. package/lib/python3.9/lib-dynload/_ctypes.cpython-39-x86_64-linux-gnu.so +0 -0
  414. package/lib/python3.9/lib-dynload/_ctypes_test.cpython-39-x86_64-linux-gnu.so +0 -0
  415. package/lib/python3.9/lib-dynload/_curses.cpython-39-x86_64-linux-gnu.so +0 -0
  416. package/lib/python3.9/lib-dynload/_curses_panel.cpython-39-x86_64-linux-gnu.so +0 -0
  417. package/lib/python3.9/lib-dynload/_datetime.cpython-39-x86_64-linux-gnu.so +0 -0
  418. package/lib/python3.9/lib-dynload/_decimal.cpython-39-x86_64-linux-gnu.so +0 -0
  419. package/lib/python3.9/lib-dynload/_elementtree.cpython-39-x86_64-linux-gnu.so +0 -0
  420. package/lib/python3.9/lib-dynload/_hashlib.cpython-39-x86_64-linux-gnu.so +0 -0
  421. package/lib/python3.9/lib-dynload/_heapq.cpython-39-x86_64-linux-gnu.so +0 -0
  422. package/lib/python3.9/lib-dynload/_json.cpython-39-x86_64-linux-gnu.so +0 -0
  423. package/lib/python3.9/lib-dynload/_lsprof.cpython-39-x86_64-linux-gnu.so +0 -0
  424. package/lib/python3.9/lib-dynload/_lzma.cpython-39-x86_64-linux-gnu.so +0 -0
  425. package/lib/python3.9/lib-dynload/_md5.cpython-39-x86_64-linux-gnu.so +0 -0
  426. package/lib/python3.9/lib-dynload/_multibytecodec.cpython-39-x86_64-linux-gnu.so +0 -0
  427. package/lib/python3.9/lib-dynload/_multiprocessing.cpython-39-x86_64-linux-gnu.so +0 -0
  428. package/lib/python3.9/lib-dynload/_opcode.cpython-39-x86_64-linux-gnu.so +0 -0
  429. package/lib/python3.9/lib-dynload/_pickle.cpython-39-x86_64-linux-gnu.so +0 -0
  430. package/lib/python3.9/lib-dynload/_posixshmem.cpython-39-x86_64-linux-gnu.so +0 -0
  431. package/lib/python3.9/lib-dynload/_posixsubprocess.cpython-39-x86_64-linux-gnu.so +0 -0
  432. package/lib/python3.9/lib-dynload/_queue.cpython-39-x86_64-linux-gnu.so +0 -0
  433. package/lib/python3.9/lib-dynload/_random.cpython-39-x86_64-linux-gnu.so +0 -0
  434. package/lib/python3.9/lib-dynload/_sha1.cpython-39-x86_64-linux-gnu.so +0 -0
  435. package/lib/python3.9/lib-dynload/_sha256.cpython-39-x86_64-linux-gnu.so +0 -0
  436. package/lib/python3.9/lib-dynload/_sha3.cpython-39-x86_64-linux-gnu.so +0 -0
  437. package/lib/python3.9/lib-dynload/_sha512.cpython-39-x86_64-linux-gnu.so +0 -0
  438. package/lib/python3.9/lib-dynload/_socket.cpython-39-x86_64-linux-gnu.so +0 -0
  439. package/lib/python3.9/lib-dynload/_sqlite3.cpython-39-x86_64-linux-gnu.so +0 -0
  440. package/lib/python3.9/lib-dynload/_ssl.cpython-39-x86_64-linux-gnu.so +0 -0
  441. package/lib/python3.9/lib-dynload/_statistics.cpython-39-x86_64-linux-gnu.so +0 -0
  442. package/lib/python3.9/lib-dynload/_struct.cpython-39-x86_64-linux-gnu.so +0 -0
  443. package/lib/python3.9/lib-dynload/_testbuffer.cpython-39-x86_64-linux-gnu.so +0 -0
  444. package/lib/python3.9/lib-dynload/_testcapi.cpython-39-x86_64-linux-gnu.so +0 -0
  445. package/lib/python3.9/lib-dynload/_testimportmultiple.cpython-39-x86_64-linux-gnu.so +0 -0
  446. package/lib/python3.9/lib-dynload/_testinternalcapi.cpython-39-x86_64-linux-gnu.so +0 -0
  447. package/lib/python3.9/lib-dynload/_testmultiphase.cpython-39-x86_64-linux-gnu.so +0 -0
  448. package/lib/python3.9/lib-dynload/_tkinter.cpython-39-x86_64-linux-gnu.so +0 -0
  449. package/lib/python3.9/lib-dynload/_xxsubinterpreters.cpython-39-x86_64-linux-gnu.so +0 -0
  450. package/lib/python3.9/lib-dynload/_xxtestfuzz.cpython-39-x86_64-linux-gnu.so +0 -0
  451. package/lib/python3.9/lib-dynload/_zoneinfo.cpython-39-x86_64-linux-gnu.so +0 -0
  452. package/lib/python3.9/lib-dynload/array.cpython-39-x86_64-linux-gnu.so +0 -0
  453. package/lib/python3.9/lib-dynload/audioop.cpython-39-x86_64-linux-gnu.so +0 -0
  454. package/lib/python3.9/lib-dynload/binascii.cpython-39-x86_64-linux-gnu.so +0 -0
  455. package/lib/python3.9/lib-dynload/cmath.cpython-39-x86_64-linux-gnu.so +0 -0
  456. package/lib/python3.9/lib-dynload/fcntl.cpython-39-x86_64-linux-gnu.so +0 -0
  457. package/lib/python3.9/lib-dynload/grp.cpython-39-x86_64-linux-gnu.so +0 -0
  458. package/lib/python3.9/lib-dynload/math.cpython-39-x86_64-linux-gnu.so +0 -0
  459. package/lib/python3.9/lib-dynload/mmap.cpython-39-x86_64-linux-gnu.so +0 -0
  460. package/lib/python3.9/lib-dynload/nis.cpython-39-x86_64-linux-gnu.so +0 -0
  461. package/lib/python3.9/lib-dynload/ossaudiodev.cpython-39-x86_64-linux-gnu.so +0 -0
  462. package/lib/python3.9/lib-dynload/parser.cpython-39-x86_64-linux-gnu.so +0 -0
  463. package/lib/python3.9/lib-dynload/pyexpat.cpython-39-x86_64-linux-gnu.so +0 -0
  464. package/lib/python3.9/lib-dynload/readline.cpython-39-x86_64-linux-gnu.so +0 -0
  465. package/lib/python3.9/lib-dynload/resource.cpython-39-x86_64-linux-gnu.so +0 -0
  466. package/lib/python3.9/lib-dynload/select.cpython-39-x86_64-linux-gnu.so +0 -0
  467. package/lib/python3.9/lib-dynload/spwd.cpython-39-x86_64-linux-gnu.so +0 -0
  468. package/lib/python3.9/lib-dynload/syslog.cpython-39-x86_64-linux-gnu.so +0 -0
  469. package/lib/python3.9/lib-dynload/termios.cpython-39-x86_64-linux-gnu.so +0 -0
  470. package/lib/python3.9/lib-dynload/unicodedata.cpython-39-x86_64-linux-gnu.so +0 -0
  471. package/lib/python3.9/lib-dynload/xxlimited.cpython-39-x86_64-linux-gnu.so +0 -0
  472. package/lib/python3.9/lib-dynload/zlib.cpython-39-x86_64-linux-gnu.so +0 -0
  473. package/lib/python3.9/linecache.py +0 -177
  474. package/lib/python3.9/locale.py +0 -1755
  475. package/lib/python3.9/logging/__init__.py +0 -2208
  476. package/lib/python3.9/logging/config.py +0 -945
  477. package/lib/python3.9/logging/handlers.py +0 -1543
  478. package/lib/python3.9/lzma.py +0 -347
  479. package/lib/python3.9/mailbox.py +0 -2151
  480. package/lib/python3.9/mailcap.py +0 -276
  481. package/lib/python3.9/mimetypes.py +0 -614
  482. package/lib/python3.9/modulefinder.py +0 -685
  483. package/lib/python3.9/multiprocessing/__init__.py +0 -37
  484. package/lib/python3.9/multiprocessing/connection.py +0 -978
  485. package/lib/python3.9/multiprocessing/context.py +0 -362
  486. package/lib/python3.9/multiprocessing/dummy/__init__.py +0 -126
  487. package/lib/python3.9/multiprocessing/dummy/connection.py +0 -75
  488. package/lib/python3.9/multiprocessing/forkserver.py +0 -348
  489. package/lib/python3.9/multiprocessing/heap.py +0 -337
  490. package/lib/python3.9/multiprocessing/managers.py +0 -1369
  491. package/lib/python3.9/multiprocessing/pool.py +0 -954
  492. package/lib/python3.9/multiprocessing/popen_fork.py +0 -83
  493. package/lib/python3.9/multiprocessing/popen_forkserver.py +0 -74
  494. package/lib/python3.9/multiprocessing/popen_spawn_posix.py +0 -72
  495. package/lib/python3.9/multiprocessing/popen_spawn_win32.py +0 -131
  496. package/lib/python3.9/multiprocessing/process.py +0 -432
  497. package/lib/python3.9/multiprocessing/queues.py +0 -380
  498. package/lib/python3.9/multiprocessing/reduction.py +0 -281
  499. package/lib/python3.9/multiprocessing/resource_sharer.py +0 -154
  500. package/lib/python3.9/multiprocessing/resource_tracker.py +0 -231
  501. package/lib/python3.9/multiprocessing/shared_memory.py +0 -532
  502. package/lib/python3.9/multiprocessing/sharedctypes.py +0 -240
  503. package/lib/python3.9/multiprocessing/spawn.py +0 -297
  504. package/lib/python3.9/multiprocessing/synchronize.py +0 -394
  505. package/lib/python3.9/multiprocessing/util.py +0 -489
  506. package/lib/python3.9/netrc.py +0 -139
  507. package/lib/python3.9/nntplib.py +0 -1090
  508. package/lib/python3.9/ntpath.py +0 -794
  509. package/lib/python3.9/nturl2path.py +0 -73
  510. package/lib/python3.9/numbers.py +0 -389
  511. package/lib/python3.9/opcode.py +0 -217
  512. package/lib/python3.9/operator.py +0 -460
  513. package/lib/python3.9/optparse.py +0 -1681
  514. package/lib/python3.9/os.py +0 -1116
  515. package/lib/python3.9/pathlib.py +0 -1576
  516. package/lib/python3.9/pdb.py +0 -1731
  517. package/lib/python3.9/pickle.py +0 -1817
  518. package/lib/python3.9/pickletools.py +0 -2890
  519. package/lib/python3.9/pipes.py +0 -247
  520. package/lib/python3.9/pkgutil.py +0 -707
  521. package/lib/python3.9/platform.py +0 -1259
  522. package/lib/python3.9/plistlib.py +0 -881
  523. package/lib/python3.9/poplib.py +0 -483
  524. package/lib/python3.9/posixpath.py +0 -525
  525. package/lib/python3.9/pprint.py +0 -638
  526. package/lib/python3.9/profile.py +0 -600
  527. package/lib/python3.9/pstats.py +0 -779
  528. package/lib/python3.9/pty.py +0 -172
  529. package/lib/python3.9/py_compile.py +0 -215
  530. package/lib/python3.9/pyclbr.py +0 -404
  531. package/lib/python3.9/pydoc.py +0 -2855
  532. package/lib/python3.9/pydoc_data/__init__.py +0 -0
  533. package/lib/python3.9/pydoc_data/_pydoc.css +0 -6
  534. package/lib/python3.9/pydoc_data/topics.py +0 -13968
  535. package/lib/python3.9/queue.py +0 -326
  536. package/lib/python3.9/quopri.py +0 -242
  537. package/lib/python3.9/random.py +0 -887
  538. package/lib/python3.9/re.py +0 -384
  539. package/lib/python3.9/reprlib.py +0 -161
  540. package/lib/python3.9/rlcompleter.py +0 -205
  541. package/lib/python3.9/runpy.py +0 -300
  542. package/lib/python3.9/sched.py +0 -167
  543. package/lib/python3.9/secrets.py +0 -72
  544. package/lib/python3.9/selectors.py +0 -619
  545. package/lib/python3.9/shelve.py +0 -243
  546. package/lib/python3.9/shlex.py +0 -350
  547. package/lib/python3.9/shutil.py +0 -1443
  548. package/lib/python3.9/signal.py +0 -85
  549. package/lib/python3.9/site.py +0 -643
  550. package/lib/python3.9/smtpd.py +0 -967
  551. package/lib/python3.9/smtplib.py +0 -1123
  552. package/lib/python3.9/sndhdr.py +0 -257
  553. package/lib/python3.9/socket.py +0 -958
  554. package/lib/python3.9/socketserver.py +0 -817
  555. package/lib/python3.9/sqlite3/__init__.py +0 -23
  556. package/lib/python3.9/sqlite3/dbapi2.py +0 -89
  557. package/lib/python3.9/sqlite3/dump.py +0 -70
  558. package/lib/python3.9/sre_compile.py +0 -784
  559. package/lib/python3.9/sre_constants.py +0 -259
  560. package/lib/python3.9/sre_parse.py +0 -1064
  561. package/lib/python3.9/ssl.py +0 -1489
  562. package/lib/python3.9/stat.py +0 -195
  563. package/lib/python3.9/statistics.py +0 -1120
  564. package/lib/python3.9/string.py +0 -280
  565. package/lib/python3.9/stringprep.py +0 -272
  566. package/lib/python3.9/struct.py +0 -15
  567. package/lib/python3.9/subprocess.py +0 -2074
  568. package/lib/python3.9/sunau.py +0 -526
  569. package/lib/python3.9/symbol.py +0 -122
  570. package/lib/python3.9/symtable.py +0 -243
  571. package/lib/python3.9/sysconfig.py +0 -720
  572. package/lib/python3.9/tabnanny.py +0 -333
  573. package/lib/python3.9/tarfile.py +0 -2576
  574. package/lib/python3.9/telnetlib.py +0 -677
  575. package/lib/python3.9/tempfile.py +0 -832
  576. package/lib/python3.9/textwrap.py +0 -486
  577. package/lib/python3.9/this.py +0 -28
  578. package/lib/python3.9/threading.py +0 -1502
  579. package/lib/python3.9/timeit.py +0 -375
  580. package/lib/python3.9/token.py +0 -136
  581. package/lib/python3.9/tokenize.py +0 -682
  582. package/lib/python3.9/trace.py +0 -740
  583. package/lib/python3.9/traceback.py +0 -623
  584. package/lib/python3.9/tracemalloc.py +0 -560
  585. package/lib/python3.9/tty.py +0 -36
  586. package/lib/python3.9/turtle.py +0 -4140
  587. package/lib/python3.9/types.py +0 -299
  588. package/lib/python3.9/typing.py +0 -2147
  589. package/lib/python3.9/unittest/__init__.py +0 -95
  590. package/lib/python3.9/unittest/__main__.py +0 -18
  591. package/lib/python3.9/unittest/_log.py +0 -69
  592. package/lib/python3.9/unittest/async_case.py +0 -160
  593. package/lib/python3.9/unittest/case.py +0 -1437
  594. package/lib/python3.9/unittest/loader.py +0 -517
  595. package/lib/python3.9/unittest/main.py +0 -275
  596. package/lib/python3.9/unittest/mock.py +0 -2891
  597. package/lib/python3.9/unittest/result.py +0 -216
  598. package/lib/python3.9/unittest/runner.py +0 -221
  599. package/lib/python3.9/unittest/signals.py +0 -71
  600. package/lib/python3.9/unittest/suite.py +0 -361
  601. package/lib/python3.9/unittest/util.py +0 -170
  602. package/lib/python3.9/urllib/__init__.py +0 -0
  603. package/lib/python3.9/urllib/error.py +0 -77
  604. package/lib/python3.9/urllib/parse.py +0 -1179
  605. package/lib/python3.9/urllib/request.py +0 -2765
  606. package/lib/python3.9/urllib/response.py +0 -84
  607. package/lib/python3.9/urllib/robotparser.py +0 -273
  608. package/lib/python3.9/uu.py +0 -206
  609. package/lib/python3.9/uuid.py +0 -728
  610. package/lib/python3.9/venv/__init__.py +0 -504
  611. package/lib/python3.9/venv/__main__.py +0 -10
  612. package/lib/python3.9/venv/scripts/common/Activate.ps1 +0 -241
  613. package/lib/python3.9/venv/scripts/common/activate +0 -66
  614. package/lib/python3.9/venv/scripts/posix/activate.csh +0 -25
  615. package/lib/python3.9/venv/scripts/posix/activate.fish +0 -64
  616. package/lib/python3.9/warnings.py +0 -549
  617. package/lib/python3.9/wave.py +0 -513
  618. package/lib/python3.9/weakref.py +0 -664
  619. package/lib/python3.9/webbrowser.py +0 -713
  620. package/lib/python3.9/wsgiref/__init__.py +0 -23
  621. package/lib/python3.9/wsgiref/handlers.py +0 -571
  622. package/lib/python3.9/wsgiref/headers.py +0 -184
  623. package/lib/python3.9/wsgiref/simple_server.py +0 -165
  624. package/lib/python3.9/wsgiref/util.py +0 -172
  625. package/lib/python3.9/wsgiref/validate.py +0 -441
  626. package/lib/python3.9/xdrlib.py +0 -241
  627. package/lib/python3.9/xml/__init__.py +0 -20
  628. package/lib/python3.9/xml/dom/NodeFilter.py +0 -27
  629. package/lib/python3.9/xml/dom/__init__.py +0 -140
  630. package/lib/python3.9/xml/dom/domreg.py +0 -99
  631. package/lib/python3.9/xml/dom/expatbuilder.py +0 -965
  632. package/lib/python3.9/xml/dom/minicompat.py +0 -109
  633. package/lib/python3.9/xml/dom/minidom.py +0 -2011
  634. package/lib/python3.9/xml/dom/pulldom.py +0 -349
  635. package/lib/python3.9/xml/dom/xmlbuilder.py +0 -387
  636. package/lib/python3.9/xml/etree/ElementInclude.py +0 -185
  637. package/lib/python3.9/xml/etree/ElementPath.py +0 -405
  638. package/lib/python3.9/xml/etree/ElementTree.py +0 -2085
  639. package/lib/python3.9/xml/etree/__init__.py +0 -33
  640. package/lib/python3.9/xml/etree/cElementTree.py +0 -3
  641. package/lib/python3.9/xml/parsers/__init__.py +0 -8
  642. package/lib/python3.9/xml/parsers/expat.py +0 -8
  643. package/lib/python3.9/xml/sax/__init__.py +0 -107
  644. package/lib/python3.9/xml/sax/_exceptions.py +0 -131
  645. package/lib/python3.9/xml/sax/expatreader.py +0 -446
  646. package/lib/python3.9/xml/sax/handler.py +0 -342
  647. package/lib/python3.9/xml/sax/saxutils.py +0 -369
  648. package/lib/python3.9/xml/sax/xmlreader.py +0 -380
  649. package/lib/python3.9/xmlrpc/__init__.py +0 -1
  650. package/lib/python3.9/xmlrpc/client.py +0 -1524
  651. package/lib/python3.9/xmlrpc/server.py +0 -993
  652. package/lib/python3.9/zipapp.py +0 -206
  653. package/lib/python3.9/zipfile.py +0 -2426
  654. package/lib/python3.9/zipimport.py +0 -792
  655. package/lib/python3.9/zoneinfo/__init__.py +0 -31
  656. package/lib/python3.9/zoneinfo/_common.py +0 -165
  657. package/lib/python3.9/zoneinfo/_tzpath.py +0 -175
  658. package/lib/python3.9/zoneinfo/_zoneinfo.py +0 -752
  659. package/runtime.json +0 -1
  660. package/ssl/cacert.pem +0 -3959
@@ -1,2576 +0,0 @@
1
- #!/usr/bin/env python3
2
- #-------------------------------------------------------------------
3
- # tarfile.py
4
- #-------------------------------------------------------------------
5
- # Copyright (C) 2002 Lars Gustaebel <lars@gustaebel.de>
6
- # All rights reserved.
7
- #
8
- # Permission is hereby granted, free of charge, to any person
9
- # obtaining a copy of this software and associated documentation
10
- # files (the "Software"), to deal in the Software without
11
- # restriction, including without limitation the rights to use,
12
- # copy, modify, merge, publish, distribute, sublicense, and/or sell
13
- # copies of the Software, and to permit persons to whom the
14
- # Software is furnished to do so, subject to the following
15
- # conditions:
16
- #
17
- # The above copyright notice and this permission notice shall be
18
- # included in all copies or substantial portions of the Software.
19
- #
20
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22
- # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
- # OTHER DEALINGS IN THE SOFTWARE.
28
- #
29
- """Read from and write to tar format archives.
30
- """
31
-
32
- version = "0.9.0"
33
- __author__ = "Lars Gust\u00e4bel (lars@gustaebel.de)"
34
- __credits__ = "Gustavo Niemeyer, Niels Gust\u00e4bel, Richard Townsend."
35
-
36
- #---------
37
- # Imports
38
- #---------
39
- from builtins import open as bltn_open
40
- import sys
41
- import os
42
- import io
43
- import shutil
44
- import stat
45
- import time
46
- import struct
47
- import copy
48
- import re
49
-
50
- try:
51
- import pwd
52
- except ImportError:
53
- pwd = None
54
- try:
55
- import grp
56
- except ImportError:
57
- grp = None
58
-
59
- # os.symlink on Windows prior to 6.0 raises NotImplementedError
60
- symlink_exception = (AttributeError, NotImplementedError)
61
- try:
62
- # OSError (winerror=1314) will be raised if the caller does not hold the
63
- # SeCreateSymbolicLinkPrivilege privilege
64
- symlink_exception += (OSError,)
65
- except NameError:
66
- pass
67
-
68
- # from tarfile import *
69
- __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError", "ReadError",
70
- "CompressionError", "StreamError", "ExtractError", "HeaderError",
71
- "ENCODING", "USTAR_FORMAT", "GNU_FORMAT", "PAX_FORMAT",
72
- "DEFAULT_FORMAT", "open"]
73
-
74
- #---------------------------------------------------------
75
- # tar constants
76
- #---------------------------------------------------------
77
- NUL = b"\0" # the null character
78
- BLOCKSIZE = 512 # length of processing blocks
79
- RECORDSIZE = BLOCKSIZE * 20 # length of records
80
- GNU_MAGIC = b"ustar \0" # magic gnu tar string
81
- POSIX_MAGIC = b"ustar\x0000" # magic posix tar string
82
-
83
- LENGTH_NAME = 100 # maximum length of a filename
84
- LENGTH_LINK = 100 # maximum length of a linkname
85
- LENGTH_PREFIX = 155 # maximum length of the prefix field
86
-
87
- REGTYPE = b"0" # regular file
88
- AREGTYPE = b"\0" # regular file
89
- LNKTYPE = b"1" # link (inside tarfile)
90
- SYMTYPE = b"2" # symbolic link
91
- CHRTYPE = b"3" # character special device
92
- BLKTYPE = b"4" # block special device
93
- DIRTYPE = b"5" # directory
94
- FIFOTYPE = b"6" # fifo special device
95
- CONTTYPE = b"7" # contiguous file
96
-
97
- GNUTYPE_LONGNAME = b"L" # GNU tar longname
98
- GNUTYPE_LONGLINK = b"K" # GNU tar longlink
99
- GNUTYPE_SPARSE = b"S" # GNU tar sparse file
100
-
101
- XHDTYPE = b"x" # POSIX.1-2001 extended header
102
- XGLTYPE = b"g" # POSIX.1-2001 global header
103
- SOLARIS_XHDTYPE = b"X" # Solaris extended header
104
-
105
- USTAR_FORMAT = 0 # POSIX.1-1988 (ustar) format
106
- GNU_FORMAT = 1 # GNU tar format
107
- PAX_FORMAT = 2 # POSIX.1-2001 (pax) format
108
- DEFAULT_FORMAT = PAX_FORMAT
109
-
110
- #---------------------------------------------------------
111
- # tarfile constants
112
- #---------------------------------------------------------
113
- # File types that tarfile supports:
114
- SUPPORTED_TYPES = (REGTYPE, AREGTYPE, LNKTYPE,
115
- SYMTYPE, DIRTYPE, FIFOTYPE,
116
- CONTTYPE, CHRTYPE, BLKTYPE,
117
- GNUTYPE_LONGNAME, GNUTYPE_LONGLINK,
118
- GNUTYPE_SPARSE)
119
-
120
- # File types that will be treated as a regular file.
121
- REGULAR_TYPES = (REGTYPE, AREGTYPE,
122
- CONTTYPE, GNUTYPE_SPARSE)
123
-
124
- # File types that are part of the GNU tar format.
125
- GNU_TYPES = (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK,
126
- GNUTYPE_SPARSE)
127
-
128
- # Fields from a pax header that override a TarInfo attribute.
129
- PAX_FIELDS = ("path", "linkpath", "size", "mtime",
130
- "uid", "gid", "uname", "gname")
131
-
132
- # Fields from a pax header that are affected by hdrcharset.
133
- PAX_NAME_FIELDS = {"path", "linkpath", "uname", "gname"}
134
-
135
- # Fields in a pax header that are numbers, all other fields
136
- # are treated as strings.
137
- PAX_NUMBER_FIELDS = {
138
- "atime": float,
139
- "ctime": float,
140
- "mtime": float,
141
- "uid": int,
142
- "gid": int,
143
- "size": int
144
- }
145
-
146
- #---------------------------------------------------------
147
- # initialization
148
- #---------------------------------------------------------
149
- if os.name == "nt":
150
- ENCODING = "utf-8"
151
- else:
152
- ENCODING = sys.getfilesystemencoding()
153
-
154
- #---------------------------------------------------------
155
- # Some useful functions
156
- #---------------------------------------------------------
157
-
158
- def stn(s, length, encoding, errors):
159
- """Convert a string to a null-terminated bytes object.
160
- """
161
- s = s.encode(encoding, errors)
162
- return s[:length] + (length - len(s)) * NUL
163
-
164
- def nts(s, encoding, errors):
165
- """Convert a null-terminated bytes object to a string.
166
- """
167
- p = s.find(b"\0")
168
- if p != -1:
169
- s = s[:p]
170
- return s.decode(encoding, errors)
171
-
172
- def nti(s):
173
- """Convert a number field to a python number.
174
- """
175
- # There are two possible encodings for a number field, see
176
- # itn() below.
177
- if s[0] in (0o200, 0o377):
178
- n = 0
179
- for i in range(len(s) - 1):
180
- n <<= 8
181
- n += s[i + 1]
182
- if s[0] == 0o377:
183
- n = -(256 ** (len(s) - 1) - n)
184
- else:
185
- try:
186
- s = nts(s, "ascii", "strict")
187
- n = int(s.strip() or "0", 8)
188
- except ValueError:
189
- raise InvalidHeaderError("invalid header")
190
- return n
191
-
192
- def itn(n, digits=8, format=DEFAULT_FORMAT):
193
- """Convert a python number to a number field.
194
- """
195
- # POSIX 1003.1-1988 requires numbers to be encoded as a string of
196
- # octal digits followed by a null-byte, this allows values up to
197
- # (8**(digits-1))-1. GNU tar allows storing numbers greater than
198
- # that if necessary. A leading 0o200 or 0o377 byte indicate this
199
- # particular encoding, the following digits-1 bytes are a big-endian
200
- # base-256 representation. This allows values up to (256**(digits-1))-1.
201
- # A 0o200 byte indicates a positive number, a 0o377 byte a negative
202
- # number.
203
- n = int(n)
204
- if 0 <= n < 8 ** (digits - 1):
205
- s = bytes("%0*o" % (digits - 1, n), "ascii") + NUL
206
- elif format == GNU_FORMAT and -256 ** (digits - 1) <= n < 256 ** (digits - 1):
207
- if n >= 0:
208
- s = bytearray([0o200])
209
- else:
210
- s = bytearray([0o377])
211
- n = 256 ** digits + n
212
-
213
- for i in range(digits - 1):
214
- s.insert(1, n & 0o377)
215
- n >>= 8
216
- else:
217
- raise ValueError("overflow in number field")
218
-
219
- return s
220
-
221
- def calc_chksums(buf):
222
- """Calculate the checksum for a member's header by summing up all
223
- characters except for the chksum field which is treated as if
224
- it was filled with spaces. According to the GNU tar sources,
225
- some tars (Sun and NeXT) calculate chksum with signed char,
226
- which will be different if there are chars in the buffer with
227
- the high bit set. So we calculate two checksums, unsigned and
228
- signed.
229
- """
230
- unsigned_chksum = 256 + sum(struct.unpack_from("148B8x356B", buf))
231
- signed_chksum = 256 + sum(struct.unpack_from("148b8x356b", buf))
232
- return unsigned_chksum, signed_chksum
233
-
234
- def copyfileobj(src, dst, length=None, exception=OSError, bufsize=None):
235
- """Copy length bytes from fileobj src to fileobj dst.
236
- If length is None, copy the entire content.
237
- """
238
- bufsize = bufsize or 16 * 1024
239
- if length == 0:
240
- return
241
- if length is None:
242
- shutil.copyfileobj(src, dst, bufsize)
243
- return
244
-
245
- blocks, remainder = divmod(length, bufsize)
246
- for b in range(blocks):
247
- buf = src.read(bufsize)
248
- if len(buf) < bufsize:
249
- raise exception("unexpected end of data")
250
- dst.write(buf)
251
-
252
- if remainder != 0:
253
- buf = src.read(remainder)
254
- if len(buf) < remainder:
255
- raise exception("unexpected end of data")
256
- dst.write(buf)
257
- return
258
-
259
- def _safe_print(s):
260
- encoding = getattr(sys.stdout, 'encoding', None)
261
- if encoding is not None:
262
- s = s.encode(encoding, 'backslashreplace').decode(encoding)
263
- print(s, end=' ')
264
-
265
-
266
- class TarError(Exception):
267
- """Base exception."""
268
- pass
269
- class ExtractError(TarError):
270
- """General exception for extract errors."""
271
- pass
272
- class ReadError(TarError):
273
- """Exception for unreadable tar archives."""
274
- pass
275
- class CompressionError(TarError):
276
- """Exception for unavailable compression methods."""
277
- pass
278
- class StreamError(TarError):
279
- """Exception for unsupported operations on stream-like TarFiles."""
280
- pass
281
- class HeaderError(TarError):
282
- """Base exception for header errors."""
283
- pass
284
- class EmptyHeaderError(HeaderError):
285
- """Exception for empty headers."""
286
- pass
287
- class TruncatedHeaderError(HeaderError):
288
- """Exception for truncated headers."""
289
- pass
290
- class EOFHeaderError(HeaderError):
291
- """Exception for end of file headers."""
292
- pass
293
- class InvalidHeaderError(HeaderError):
294
- """Exception for invalid headers."""
295
- pass
296
- class SubsequentHeaderError(HeaderError):
297
- """Exception for missing and invalid extended headers."""
298
- pass
299
-
300
- #---------------------------
301
- # internal stream interface
302
- #---------------------------
303
- class _LowLevelFile:
304
- """Low-level file object. Supports reading and writing.
305
- It is used instead of a regular file object for streaming
306
- access.
307
- """
308
-
309
- def __init__(self, name, mode):
310
- mode = {
311
- "r": os.O_RDONLY,
312
- "w": os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
313
- }[mode]
314
- if hasattr(os, "O_BINARY"):
315
- mode |= os.O_BINARY
316
- self.fd = os.open(name, mode, 0o666)
317
-
318
- def close(self):
319
- os.close(self.fd)
320
-
321
- def read(self, size):
322
- return os.read(self.fd, size)
323
-
324
- def write(self, s):
325
- os.write(self.fd, s)
326
-
327
- class _Stream:
328
- """Class that serves as an adapter between TarFile and
329
- a stream-like object. The stream-like object only
330
- needs to have a read() or write() method and is accessed
331
- blockwise. Use of gzip or bzip2 compression is possible.
332
- A stream-like object could be for example: sys.stdin,
333
- sys.stdout, a socket, a tape device etc.
334
-
335
- _Stream is intended to be used only internally.
336
- """
337
-
338
- def __init__(self, name, mode, comptype, fileobj, bufsize):
339
- """Construct a _Stream object.
340
- """
341
- self._extfileobj = True
342
- if fileobj is None:
343
- fileobj = _LowLevelFile(name, mode)
344
- self._extfileobj = False
345
-
346
- if comptype == '*':
347
- # Enable transparent compression detection for the
348
- # stream interface
349
- fileobj = _StreamProxy(fileobj)
350
- comptype = fileobj.getcomptype()
351
-
352
- self.name = name or ""
353
- self.mode = mode
354
- self.comptype = comptype
355
- self.fileobj = fileobj
356
- self.bufsize = bufsize
357
- self.buf = b""
358
- self.pos = 0
359
- self.closed = False
360
-
361
- try:
362
- if comptype == "gz":
363
- try:
364
- import zlib
365
- except ImportError:
366
- raise CompressionError("zlib module is not available")
367
- self.zlib = zlib
368
- self.crc = zlib.crc32(b"")
369
- if mode == "r":
370
- self._init_read_gz()
371
- self.exception = zlib.error
372
- else:
373
- self._init_write_gz()
374
-
375
- elif comptype == "bz2":
376
- try:
377
- import bz2
378
- except ImportError:
379
- raise CompressionError("bz2 module is not available")
380
- if mode == "r":
381
- self.dbuf = b""
382
- self.cmp = bz2.BZ2Decompressor()
383
- self.exception = OSError
384
- else:
385
- self.cmp = bz2.BZ2Compressor()
386
-
387
- elif comptype == "xz":
388
- try:
389
- import lzma
390
- except ImportError:
391
- raise CompressionError("lzma module is not available")
392
- if mode == "r":
393
- self.dbuf = b""
394
- self.cmp = lzma.LZMADecompressor()
395
- self.exception = lzma.LZMAError
396
- else:
397
- self.cmp = lzma.LZMACompressor()
398
-
399
- elif comptype != "tar":
400
- raise CompressionError("unknown compression type %r" % comptype)
401
-
402
- except:
403
- if not self._extfileobj:
404
- self.fileobj.close()
405
- self.closed = True
406
- raise
407
-
408
- def __del__(self):
409
- if hasattr(self, "closed") and not self.closed:
410
- self.close()
411
-
412
- def _init_write_gz(self):
413
- """Initialize for writing with gzip compression.
414
- """
415
- self.cmp = self.zlib.compressobj(9, self.zlib.DEFLATED,
416
- -self.zlib.MAX_WBITS,
417
- self.zlib.DEF_MEM_LEVEL,
418
- 0)
419
- timestamp = struct.pack("<L", int(time.time()))
420
- self.__write(b"\037\213\010\010" + timestamp + b"\002\377")
421
- if self.name.endswith(".gz"):
422
- self.name = self.name[:-3]
423
- # RFC1952 says we must use ISO-8859-1 for the FNAME field.
424
- self.__write(self.name.encode("iso-8859-1", "replace") + NUL)
425
-
426
- def write(self, s):
427
- """Write string s to the stream.
428
- """
429
- if self.comptype == "gz":
430
- self.crc = self.zlib.crc32(s, self.crc)
431
- self.pos += len(s)
432
- if self.comptype != "tar":
433
- s = self.cmp.compress(s)
434
- self.__write(s)
435
-
436
- def __write(self, s):
437
- """Write string s to the stream if a whole new block
438
- is ready to be written.
439
- """
440
- self.buf += s
441
- while len(self.buf) > self.bufsize:
442
- self.fileobj.write(self.buf[:self.bufsize])
443
- self.buf = self.buf[self.bufsize:]
444
-
445
- def close(self):
446
- """Close the _Stream object. No operation should be
447
- done on it afterwards.
448
- """
449
- if self.closed:
450
- return
451
-
452
- self.closed = True
453
- try:
454
- if self.mode == "w" and self.comptype != "tar":
455
- self.buf += self.cmp.flush()
456
-
457
- if self.mode == "w" and self.buf:
458
- self.fileobj.write(self.buf)
459
- self.buf = b""
460
- if self.comptype == "gz":
461
- self.fileobj.write(struct.pack("<L", self.crc))
462
- self.fileobj.write(struct.pack("<L", self.pos & 0xffffFFFF))
463
- finally:
464
- if not self._extfileobj:
465
- self.fileobj.close()
466
-
467
- def _init_read_gz(self):
468
- """Initialize for reading a gzip compressed fileobj.
469
- """
470
- self.cmp = self.zlib.decompressobj(-self.zlib.MAX_WBITS)
471
- self.dbuf = b""
472
-
473
- # taken from gzip.GzipFile with some alterations
474
- if self.__read(2) != b"\037\213":
475
- raise ReadError("not a gzip file")
476
- if self.__read(1) != b"\010":
477
- raise CompressionError("unsupported compression method")
478
-
479
- flag = ord(self.__read(1))
480
- self.__read(6)
481
-
482
- if flag & 4:
483
- xlen = ord(self.__read(1)) + 256 * ord(self.__read(1))
484
- self.read(xlen)
485
- if flag & 8:
486
- while True:
487
- s = self.__read(1)
488
- if not s or s == NUL:
489
- break
490
- if flag & 16:
491
- while True:
492
- s = self.__read(1)
493
- if not s or s == NUL:
494
- break
495
- if flag & 2:
496
- self.__read(2)
497
-
498
- def tell(self):
499
- """Return the stream's file pointer position.
500
- """
501
- return self.pos
502
-
503
- def seek(self, pos=0):
504
- """Set the stream's file pointer to pos. Negative seeking
505
- is forbidden.
506
- """
507
- if pos - self.pos >= 0:
508
- blocks, remainder = divmod(pos - self.pos, self.bufsize)
509
- for i in range(blocks):
510
- self.read(self.bufsize)
511
- self.read(remainder)
512
- else:
513
- raise StreamError("seeking backwards is not allowed")
514
- return self.pos
515
-
516
- def read(self, size):
517
- """Return the next size number of bytes from the stream."""
518
- assert size is not None
519
- buf = self._read(size)
520
- self.pos += len(buf)
521
- return buf
522
-
523
- def _read(self, size):
524
- """Return size bytes from the stream.
525
- """
526
- if self.comptype == "tar":
527
- return self.__read(size)
528
-
529
- c = len(self.dbuf)
530
- t = [self.dbuf]
531
- while c < size:
532
- # Skip underlying buffer to avoid unaligned double buffering.
533
- if self.buf:
534
- buf = self.buf
535
- self.buf = b""
536
- else:
537
- buf = self.fileobj.read(self.bufsize)
538
- if not buf:
539
- break
540
- try:
541
- buf = self.cmp.decompress(buf)
542
- except self.exception:
543
- raise ReadError("invalid compressed data")
544
- t.append(buf)
545
- c += len(buf)
546
- t = b"".join(t)
547
- self.dbuf = t[size:]
548
- return t[:size]
549
-
550
- def __read(self, size):
551
- """Return size bytes from stream. If internal buffer is empty,
552
- read another block from the stream.
553
- """
554
- c = len(self.buf)
555
- t = [self.buf]
556
- while c < size:
557
- buf = self.fileobj.read(self.bufsize)
558
- if not buf:
559
- break
560
- t.append(buf)
561
- c += len(buf)
562
- t = b"".join(t)
563
- self.buf = t[size:]
564
- return t[:size]
565
- # class _Stream
566
-
567
- class _StreamProxy(object):
568
- """Small proxy class that enables transparent compression
569
- detection for the Stream interface (mode 'r|*').
570
- """
571
-
572
- def __init__(self, fileobj):
573
- self.fileobj = fileobj
574
- self.buf = self.fileobj.read(BLOCKSIZE)
575
-
576
- def read(self, size):
577
- self.read = self.fileobj.read
578
- return self.buf
579
-
580
- def getcomptype(self):
581
- if self.buf.startswith(b"\x1f\x8b\x08"):
582
- return "gz"
583
- elif self.buf[0:3] == b"BZh" and self.buf[4:10] == b"1AY&SY":
584
- return "bz2"
585
- elif self.buf.startswith((b"\x5d\x00\x00\x80", b"\xfd7zXZ")):
586
- return "xz"
587
- else:
588
- return "tar"
589
-
590
- def close(self):
591
- self.fileobj.close()
592
- # class StreamProxy
593
-
594
- #------------------------
595
- # Extraction file object
596
- #------------------------
597
- class _FileInFile(object):
598
- """A thin wrapper around an existing file object that
599
- provides a part of its data as an individual file
600
- object.
601
- """
602
-
603
- def __init__(self, fileobj, offset, size, blockinfo=None):
604
- self.fileobj = fileobj
605
- self.offset = offset
606
- self.size = size
607
- self.position = 0
608
- self.name = getattr(fileobj, "name", None)
609
- self.closed = False
610
-
611
- if blockinfo is None:
612
- blockinfo = [(0, size)]
613
-
614
- # Construct a map with data and zero blocks.
615
- self.map_index = 0
616
- self.map = []
617
- lastpos = 0
618
- realpos = self.offset
619
- for offset, size in blockinfo:
620
- if offset > lastpos:
621
- self.map.append((False, lastpos, offset, None))
622
- self.map.append((True, offset, offset + size, realpos))
623
- realpos += size
624
- lastpos = offset + size
625
- if lastpos < self.size:
626
- self.map.append((False, lastpos, self.size, None))
627
-
628
- def flush(self):
629
- pass
630
-
631
- def readable(self):
632
- return True
633
-
634
- def writable(self):
635
- return False
636
-
637
- def seekable(self):
638
- return self.fileobj.seekable()
639
-
640
- def tell(self):
641
- """Return the current file position.
642
- """
643
- return self.position
644
-
645
- def seek(self, position, whence=io.SEEK_SET):
646
- """Seek to a position in the file.
647
- """
648
- if whence == io.SEEK_SET:
649
- self.position = min(max(position, 0), self.size)
650
- elif whence == io.SEEK_CUR:
651
- if position < 0:
652
- self.position = max(self.position + position, 0)
653
- else:
654
- self.position = min(self.position + position, self.size)
655
- elif whence == io.SEEK_END:
656
- self.position = max(min(self.size + position, self.size), 0)
657
- else:
658
- raise ValueError("Invalid argument")
659
- return self.position
660
-
661
- def read(self, size=None):
662
- """Read data from the file.
663
- """
664
- if size is None:
665
- size = self.size - self.position
666
- else:
667
- size = min(size, self.size - self.position)
668
-
669
- buf = b""
670
- while size > 0:
671
- while True:
672
- data, start, stop, offset = self.map[self.map_index]
673
- if start <= self.position < stop:
674
- break
675
- else:
676
- self.map_index += 1
677
- if self.map_index == len(self.map):
678
- self.map_index = 0
679
- length = min(size, stop - self.position)
680
- if data:
681
- self.fileobj.seek(offset + (self.position - start))
682
- b = self.fileobj.read(length)
683
- if len(b) != length:
684
- raise ReadError("unexpected end of data")
685
- buf += b
686
- else:
687
- buf += NUL * length
688
- size -= length
689
- self.position += length
690
- return buf
691
-
692
- def readinto(self, b):
693
- buf = self.read(len(b))
694
- b[:len(buf)] = buf
695
- return len(buf)
696
-
697
- def close(self):
698
- self.closed = True
699
- #class _FileInFile
700
-
701
- class ExFileObject(io.BufferedReader):
702
-
703
- def __init__(self, tarfile, tarinfo):
704
- fileobj = _FileInFile(tarfile.fileobj, tarinfo.offset_data,
705
- tarinfo.size, tarinfo.sparse)
706
- super().__init__(fileobj)
707
- #class ExFileObject
708
-
709
- #------------------
710
- # Exported Classes
711
- #------------------
712
- class TarInfo(object):
713
- """Informational class which holds the details about an
714
- archive member given by a tar header block.
715
- TarInfo objects are returned by TarFile.getmember(),
716
- TarFile.getmembers() and TarFile.gettarinfo() and are
717
- usually created internally.
718
- """
719
-
720
- __slots__ = dict(
721
- name = 'Name of the archive member.',
722
- mode = 'Permission bits.',
723
- uid = 'User ID of the user who originally stored this member.',
724
- gid = 'Group ID of the user who originally stored this member.',
725
- size = 'Size in bytes.',
726
- mtime = 'Time of last modification.',
727
- chksum = 'Header checksum.',
728
- type = ('File type. type is usually one of these constants: '
729
- 'REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, '
730
- 'CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.'),
731
- linkname = ('Name of the target file name, which is only present '
732
- 'in TarInfo objects of type LNKTYPE and SYMTYPE.'),
733
- uname = 'User name.',
734
- gname = 'Group name.',
735
- devmajor = 'Device major number.',
736
- devminor = 'Device minor number.',
737
- offset = 'The tar header starts here.',
738
- offset_data = "The file's data starts here.",
739
- pax_headers = ('A dictionary containing key-value pairs of an '
740
- 'associated pax extended header.'),
741
- sparse = 'Sparse member information.',
742
- tarfile = None,
743
- _sparse_structs = None,
744
- _link_target = None,
745
- )
746
-
747
- def __init__(self, name=""):
748
- """Construct a TarInfo object. name is the optional name
749
- of the member.
750
- """
751
- self.name = name # member name
752
- self.mode = 0o644 # file permissions
753
- self.uid = 0 # user id
754
- self.gid = 0 # group id
755
- self.size = 0 # file size
756
- self.mtime = 0 # modification time
757
- self.chksum = 0 # header checksum
758
- self.type = REGTYPE # member type
759
- self.linkname = "" # link name
760
- self.uname = "" # user name
761
- self.gname = "" # group name
762
- self.devmajor = 0 # device major number
763
- self.devminor = 0 # device minor number
764
-
765
- self.offset = 0 # the tar header starts here
766
- self.offset_data = 0 # the file's data starts here
767
-
768
- self.sparse = None # sparse member information
769
- self.pax_headers = {} # pax header information
770
-
771
- @property
772
- def path(self):
773
- 'In pax headers, "name" is called "path".'
774
- return self.name
775
-
776
- @path.setter
777
- def path(self, name):
778
- self.name = name
779
-
780
- @property
781
- def linkpath(self):
782
- 'In pax headers, "linkname" is called "linkpath".'
783
- return self.linkname
784
-
785
- @linkpath.setter
786
- def linkpath(self, linkname):
787
- self.linkname = linkname
788
-
789
- def __repr__(self):
790
- return "<%s %r at %#x>" % (self.__class__.__name__,self.name,id(self))
791
-
792
- def get_info(self):
793
- """Return the TarInfo's attributes as a dictionary.
794
- """
795
- info = {
796
- "name": self.name,
797
- "mode": self.mode & 0o7777,
798
- "uid": self.uid,
799
- "gid": self.gid,
800
- "size": self.size,
801
- "mtime": self.mtime,
802
- "chksum": self.chksum,
803
- "type": self.type,
804
- "linkname": self.linkname,
805
- "uname": self.uname,
806
- "gname": self.gname,
807
- "devmajor": self.devmajor,
808
- "devminor": self.devminor
809
- }
810
-
811
- if info["type"] == DIRTYPE and not info["name"].endswith("/"):
812
- info["name"] += "/"
813
-
814
- return info
815
-
816
- def tobuf(self, format=DEFAULT_FORMAT, encoding=ENCODING, errors="surrogateescape"):
817
- """Return a tar header as a string of 512 byte blocks.
818
- """
819
- info = self.get_info()
820
-
821
- if format == USTAR_FORMAT:
822
- return self.create_ustar_header(info, encoding, errors)
823
- elif format == GNU_FORMAT:
824
- return self.create_gnu_header(info, encoding, errors)
825
- elif format == PAX_FORMAT:
826
- return self.create_pax_header(info, encoding)
827
- else:
828
- raise ValueError("invalid format")
829
-
830
- def create_ustar_header(self, info, encoding, errors):
831
- """Return the object as a ustar header block.
832
- """
833
- info["magic"] = POSIX_MAGIC
834
-
835
- if len(info["linkname"].encode(encoding, errors)) > LENGTH_LINK:
836
- raise ValueError("linkname is too long")
837
-
838
- if len(info["name"].encode(encoding, errors)) > LENGTH_NAME:
839
- info["prefix"], info["name"] = self._posix_split_name(info["name"], encoding, errors)
840
-
841
- return self._create_header(info, USTAR_FORMAT, encoding, errors)
842
-
843
- def create_gnu_header(self, info, encoding, errors):
844
- """Return the object as a GNU header block sequence.
845
- """
846
- info["magic"] = GNU_MAGIC
847
-
848
- buf = b""
849
- if len(info["linkname"].encode(encoding, errors)) > LENGTH_LINK:
850
- buf += self._create_gnu_long_header(info["linkname"], GNUTYPE_LONGLINK, encoding, errors)
851
-
852
- if len(info["name"].encode(encoding, errors)) > LENGTH_NAME:
853
- buf += self._create_gnu_long_header(info["name"], GNUTYPE_LONGNAME, encoding, errors)
854
-
855
- return buf + self._create_header(info, GNU_FORMAT, encoding, errors)
856
-
857
- def create_pax_header(self, info, encoding):
858
- """Return the object as a ustar header block. If it cannot be
859
- represented this way, prepend a pax extended header sequence
860
- with supplement information.
861
- """
862
- info["magic"] = POSIX_MAGIC
863
- pax_headers = self.pax_headers.copy()
864
-
865
- # Test string fields for values that exceed the field length or cannot
866
- # be represented in ASCII encoding.
867
- for name, hname, length in (
868
- ("name", "path", LENGTH_NAME), ("linkname", "linkpath", LENGTH_LINK),
869
- ("uname", "uname", 32), ("gname", "gname", 32)):
870
-
871
- if hname in pax_headers:
872
- # The pax header has priority.
873
- continue
874
-
875
- # Try to encode the string as ASCII.
876
- try:
877
- info[name].encode("ascii", "strict")
878
- except UnicodeEncodeError:
879
- pax_headers[hname] = info[name]
880
- continue
881
-
882
- if len(info[name]) > length:
883
- pax_headers[hname] = info[name]
884
-
885
- # Test number fields for values that exceed the field limit or values
886
- # that like to be stored as float.
887
- for name, digits in (("uid", 8), ("gid", 8), ("size", 12), ("mtime", 12)):
888
- if name in pax_headers:
889
- # The pax header has priority. Avoid overflow.
890
- info[name] = 0
891
- continue
892
-
893
- val = info[name]
894
- if not 0 <= val < 8 ** (digits - 1) or isinstance(val, float):
895
- pax_headers[name] = str(val)
896
- info[name] = 0
897
-
898
- # Create a pax extended header if necessary.
899
- if pax_headers:
900
- buf = self._create_pax_generic_header(pax_headers, XHDTYPE, encoding)
901
- else:
902
- buf = b""
903
-
904
- return buf + self._create_header(info, USTAR_FORMAT, "ascii", "replace")
905
-
906
- @classmethod
907
- def create_pax_global_header(cls, pax_headers):
908
- """Return the object as a pax global header block sequence.
909
- """
910
- return cls._create_pax_generic_header(pax_headers, XGLTYPE, "utf-8")
911
-
912
- def _posix_split_name(self, name, encoding, errors):
913
- """Split a name longer than 100 chars into a prefix
914
- and a name part.
915
- """
916
- components = name.split("/")
917
- for i in range(1, len(components)):
918
- prefix = "/".join(components[:i])
919
- name = "/".join(components[i:])
920
- if len(prefix.encode(encoding, errors)) <= LENGTH_PREFIX and \
921
- len(name.encode(encoding, errors)) <= LENGTH_NAME:
922
- break
923
- else:
924
- raise ValueError("name is too long")
925
-
926
- return prefix, name
927
-
928
- @staticmethod
929
- def _create_header(info, format, encoding, errors):
930
- """Return a header block. info is a dictionary with file
931
- information, format must be one of the *_FORMAT constants.
932
- """
933
- has_device_fields = info.get("type") in (CHRTYPE, BLKTYPE)
934
- if has_device_fields:
935
- devmajor = itn(info.get("devmajor", 0), 8, format)
936
- devminor = itn(info.get("devminor", 0), 8, format)
937
- else:
938
- devmajor = stn("", 8, encoding, errors)
939
- devminor = stn("", 8, encoding, errors)
940
-
941
- parts = [
942
- stn(info.get("name", ""), 100, encoding, errors),
943
- itn(info.get("mode", 0) & 0o7777, 8, format),
944
- itn(info.get("uid", 0), 8, format),
945
- itn(info.get("gid", 0), 8, format),
946
- itn(info.get("size", 0), 12, format),
947
- itn(info.get("mtime", 0), 12, format),
948
- b" ", # checksum field
949
- info.get("type", REGTYPE),
950
- stn(info.get("linkname", ""), 100, encoding, errors),
951
- info.get("magic", POSIX_MAGIC),
952
- stn(info.get("uname", ""), 32, encoding, errors),
953
- stn(info.get("gname", ""), 32, encoding, errors),
954
- devmajor,
955
- devminor,
956
- stn(info.get("prefix", ""), 155, encoding, errors)
957
- ]
958
-
959
- buf = struct.pack("%ds" % BLOCKSIZE, b"".join(parts))
960
- chksum = calc_chksums(buf[-BLOCKSIZE:])[0]
961
- buf = buf[:-364] + bytes("%06o\0" % chksum, "ascii") + buf[-357:]
962
- return buf
963
-
964
- @staticmethod
965
- def _create_payload(payload):
966
- """Return the string payload filled with zero bytes
967
- up to the next 512 byte border.
968
- """
969
- blocks, remainder = divmod(len(payload), BLOCKSIZE)
970
- if remainder > 0:
971
- payload += (BLOCKSIZE - remainder) * NUL
972
- return payload
973
-
974
- @classmethod
975
- def _create_gnu_long_header(cls, name, type, encoding, errors):
976
- """Return a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence
977
- for name.
978
- """
979
- name = name.encode(encoding, errors) + NUL
980
-
981
- info = {}
982
- info["name"] = "././@LongLink"
983
- info["type"] = type
984
- info["size"] = len(name)
985
- info["magic"] = GNU_MAGIC
986
-
987
- # create extended header + name blocks.
988
- return cls._create_header(info, USTAR_FORMAT, encoding, errors) + \
989
- cls._create_payload(name)
990
-
991
- @classmethod
992
- def _create_pax_generic_header(cls, pax_headers, type, encoding):
993
- """Return a POSIX.1-2008 extended or global header sequence
994
- that contains a list of keyword, value pairs. The values
995
- must be strings.
996
- """
997
- # Check if one of the fields contains surrogate characters and thereby
998
- # forces hdrcharset=BINARY, see _proc_pax() for more information.
999
- binary = False
1000
- for keyword, value in pax_headers.items():
1001
- try:
1002
- value.encode("utf-8", "strict")
1003
- except UnicodeEncodeError:
1004
- binary = True
1005
- break
1006
-
1007
- records = b""
1008
- if binary:
1009
- # Put the hdrcharset field at the beginning of the header.
1010
- records += b"21 hdrcharset=BINARY\n"
1011
-
1012
- for keyword, value in pax_headers.items():
1013
- keyword = keyword.encode("utf-8")
1014
- if binary:
1015
- # Try to restore the original byte representation of `value'.
1016
- # Needless to say, that the encoding must match the string.
1017
- value = value.encode(encoding, "surrogateescape")
1018
- else:
1019
- value = value.encode("utf-8")
1020
-
1021
- l = len(keyword) + len(value) + 3 # ' ' + '=' + '\n'
1022
- n = p = 0
1023
- while True:
1024
- n = l + len(str(p))
1025
- if n == p:
1026
- break
1027
- p = n
1028
- records += bytes(str(p), "ascii") + b" " + keyword + b"=" + value + b"\n"
1029
-
1030
- # We use a hardcoded "././@PaxHeader" name like star does
1031
- # instead of the one that POSIX recommends.
1032
- info = {}
1033
- info["name"] = "././@PaxHeader"
1034
- info["type"] = type
1035
- info["size"] = len(records)
1036
- info["magic"] = POSIX_MAGIC
1037
-
1038
- # Create pax header + record blocks.
1039
- return cls._create_header(info, USTAR_FORMAT, "ascii", "replace") + \
1040
- cls._create_payload(records)
1041
-
1042
- @classmethod
1043
- def frombuf(cls, buf, encoding, errors):
1044
- """Construct a TarInfo object from a 512 byte bytes object.
1045
- """
1046
- if len(buf) == 0:
1047
- raise EmptyHeaderError("empty header")
1048
- if len(buf) != BLOCKSIZE:
1049
- raise TruncatedHeaderError("truncated header")
1050
- if buf.count(NUL) == BLOCKSIZE:
1051
- raise EOFHeaderError("end of file header")
1052
-
1053
- chksum = nti(buf[148:156])
1054
- if chksum not in calc_chksums(buf):
1055
- raise InvalidHeaderError("bad checksum")
1056
-
1057
- obj = cls()
1058
- obj.name = nts(buf[0:100], encoding, errors)
1059
- obj.mode = nti(buf[100:108])
1060
- obj.uid = nti(buf[108:116])
1061
- obj.gid = nti(buf[116:124])
1062
- obj.size = nti(buf[124:136])
1063
- obj.mtime = nti(buf[136:148])
1064
- obj.chksum = chksum
1065
- obj.type = buf[156:157]
1066
- obj.linkname = nts(buf[157:257], encoding, errors)
1067
- obj.uname = nts(buf[265:297], encoding, errors)
1068
- obj.gname = nts(buf[297:329], encoding, errors)
1069
- obj.devmajor = nti(buf[329:337])
1070
- obj.devminor = nti(buf[337:345])
1071
- prefix = nts(buf[345:500], encoding, errors)
1072
-
1073
- # Old V7 tar format represents a directory as a regular
1074
- # file with a trailing slash.
1075
- if obj.type == AREGTYPE and obj.name.endswith("/"):
1076
- obj.type = DIRTYPE
1077
-
1078
- # The old GNU sparse format occupies some of the unused
1079
- # space in the buffer for up to 4 sparse structures.
1080
- # Save them for later processing in _proc_sparse().
1081
- if obj.type == GNUTYPE_SPARSE:
1082
- pos = 386
1083
- structs = []
1084
- for i in range(4):
1085
- try:
1086
- offset = nti(buf[pos:pos + 12])
1087
- numbytes = nti(buf[pos + 12:pos + 24])
1088
- except ValueError:
1089
- break
1090
- structs.append((offset, numbytes))
1091
- pos += 24
1092
- isextended = bool(buf[482])
1093
- origsize = nti(buf[483:495])
1094
- obj._sparse_structs = (structs, isextended, origsize)
1095
-
1096
- # Remove redundant slashes from directories.
1097
- if obj.isdir():
1098
- obj.name = obj.name.rstrip("/")
1099
-
1100
- # Reconstruct a ustar longname.
1101
- if prefix and obj.type not in GNU_TYPES:
1102
- obj.name = prefix + "/" + obj.name
1103
- return obj
1104
-
1105
- @classmethod
1106
- def fromtarfile(cls, tarfile):
1107
- """Return the next TarInfo object from TarFile object
1108
- tarfile.
1109
- """
1110
- buf = tarfile.fileobj.read(BLOCKSIZE)
1111
- obj = cls.frombuf(buf, tarfile.encoding, tarfile.errors)
1112
- obj.offset = tarfile.fileobj.tell() - BLOCKSIZE
1113
- return obj._proc_member(tarfile)
1114
-
1115
- #--------------------------------------------------------------------------
1116
- # The following are methods that are called depending on the type of a
1117
- # member. The entry point is _proc_member() which can be overridden in a
1118
- # subclass to add custom _proc_*() methods. A _proc_*() method MUST
1119
- # implement the following
1120
- # operations:
1121
- # 1. Set self.offset_data to the position where the data blocks begin,
1122
- # if there is data that follows.
1123
- # 2. Set tarfile.offset to the position where the next member's header will
1124
- # begin.
1125
- # 3. Return self or another valid TarInfo object.
1126
- def _proc_member(self, tarfile):
1127
- """Choose the right processing method depending on
1128
- the type and call it.
1129
- """
1130
- if self.type in (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK):
1131
- return self._proc_gnulong(tarfile)
1132
- elif self.type == GNUTYPE_SPARSE:
1133
- return self._proc_sparse(tarfile)
1134
- elif self.type in (XHDTYPE, XGLTYPE, SOLARIS_XHDTYPE):
1135
- return self._proc_pax(tarfile)
1136
- else:
1137
- return self._proc_builtin(tarfile)
1138
-
1139
- def _proc_builtin(self, tarfile):
1140
- """Process a builtin type or an unknown type which
1141
- will be treated as a regular file.
1142
- """
1143
- self.offset_data = tarfile.fileobj.tell()
1144
- offset = self.offset_data
1145
- if self.isreg() or self.type not in SUPPORTED_TYPES:
1146
- # Skip the following data blocks.
1147
- offset += self._block(self.size)
1148
- tarfile.offset = offset
1149
-
1150
- # Patch the TarInfo object with saved global
1151
- # header information.
1152
- self._apply_pax_info(tarfile.pax_headers, tarfile.encoding, tarfile.errors)
1153
-
1154
- return self
1155
-
1156
- def _proc_gnulong(self, tarfile):
1157
- """Process the blocks that hold a GNU longname
1158
- or longlink member.
1159
- """
1160
- buf = tarfile.fileobj.read(self._block(self.size))
1161
-
1162
- # Fetch the next header and process it.
1163
- try:
1164
- next = self.fromtarfile(tarfile)
1165
- except HeaderError:
1166
- raise SubsequentHeaderError("missing or bad subsequent header")
1167
-
1168
- # Patch the TarInfo object from the next header with
1169
- # the longname information.
1170
- next.offset = self.offset
1171
- if self.type == GNUTYPE_LONGNAME:
1172
- next.name = nts(buf, tarfile.encoding, tarfile.errors)
1173
- elif self.type == GNUTYPE_LONGLINK:
1174
- next.linkname = nts(buf, tarfile.encoding, tarfile.errors)
1175
-
1176
- return next
1177
-
1178
- def _proc_sparse(self, tarfile):
1179
- """Process a GNU sparse header plus extra headers.
1180
- """
1181
- # We already collected some sparse structures in frombuf().
1182
- structs, isextended, origsize = self._sparse_structs
1183
- del self._sparse_structs
1184
-
1185
- # Collect sparse structures from extended header blocks.
1186
- while isextended:
1187
- buf = tarfile.fileobj.read(BLOCKSIZE)
1188
- pos = 0
1189
- for i in range(21):
1190
- try:
1191
- offset = nti(buf[pos:pos + 12])
1192
- numbytes = nti(buf[pos + 12:pos + 24])
1193
- except ValueError:
1194
- break
1195
- if offset and numbytes:
1196
- structs.append((offset, numbytes))
1197
- pos += 24
1198
- isextended = bool(buf[504])
1199
- self.sparse = structs
1200
-
1201
- self.offset_data = tarfile.fileobj.tell()
1202
- tarfile.offset = self.offset_data + self._block(self.size)
1203
- self.size = origsize
1204
- return self
1205
-
1206
- def _proc_pax(self, tarfile):
1207
- """Process an extended or global header as described in
1208
- POSIX.1-2008.
1209
- """
1210
- # Read the header information.
1211
- buf = tarfile.fileobj.read(self._block(self.size))
1212
-
1213
- # A pax header stores supplemental information for either
1214
- # the following file (extended) or all following files
1215
- # (global).
1216
- if self.type == XGLTYPE:
1217
- pax_headers = tarfile.pax_headers
1218
- else:
1219
- pax_headers = tarfile.pax_headers.copy()
1220
-
1221
- # Check if the pax header contains a hdrcharset field. This tells us
1222
- # the encoding of the path, linkpath, uname and gname fields. Normally,
1223
- # these fields are UTF-8 encoded but since POSIX.1-2008 tar
1224
- # implementations are allowed to store them as raw binary strings if
1225
- # the translation to UTF-8 fails.
1226
- match = re.search(br"\d+ hdrcharset=([^\n]+)\n", buf)
1227
- if match is not None:
1228
- pax_headers["hdrcharset"] = match.group(1).decode("utf-8")
1229
-
1230
- # For the time being, we don't care about anything other than "BINARY".
1231
- # The only other value that is currently allowed by the standard is
1232
- # "ISO-IR 10646 2000 UTF-8" in other words UTF-8.
1233
- hdrcharset = pax_headers.get("hdrcharset")
1234
- if hdrcharset == "BINARY":
1235
- encoding = tarfile.encoding
1236
- else:
1237
- encoding = "utf-8"
1238
-
1239
- # Parse pax header information. A record looks like that:
1240
- # "%d %s=%s\n" % (length, keyword, value). length is the size
1241
- # of the complete record including the length field itself and
1242
- # the newline. keyword and value are both UTF-8 encoded strings.
1243
- regex = re.compile(br"(\d+) ([^=]+)=")
1244
- pos = 0
1245
- while True:
1246
- match = regex.match(buf, pos)
1247
- if not match:
1248
- break
1249
-
1250
- length, keyword = match.groups()
1251
- length = int(length)
1252
- if length == 0:
1253
- raise InvalidHeaderError("invalid header")
1254
- value = buf[match.end(2) + 1:match.start(1) + length - 1]
1255
-
1256
- # Normally, we could just use "utf-8" as the encoding and "strict"
1257
- # as the error handler, but we better not take the risk. For
1258
- # example, GNU tar <= 1.23 is known to store filenames it cannot
1259
- # translate to UTF-8 as raw strings (unfortunately without a
1260
- # hdrcharset=BINARY header).
1261
- # We first try the strict standard encoding, and if that fails we
1262
- # fall back on the user's encoding and error handler.
1263
- keyword = self._decode_pax_field(keyword, "utf-8", "utf-8",
1264
- tarfile.errors)
1265
- if keyword in PAX_NAME_FIELDS:
1266
- value = self._decode_pax_field(value, encoding, tarfile.encoding,
1267
- tarfile.errors)
1268
- else:
1269
- value = self._decode_pax_field(value, "utf-8", "utf-8",
1270
- tarfile.errors)
1271
-
1272
- pax_headers[keyword] = value
1273
- pos += length
1274
-
1275
- # Fetch the next header.
1276
- try:
1277
- next = self.fromtarfile(tarfile)
1278
- except HeaderError:
1279
- raise SubsequentHeaderError("missing or bad subsequent header")
1280
-
1281
- # Process GNU sparse information.
1282
- if "GNU.sparse.map" in pax_headers:
1283
- # GNU extended sparse format version 0.1.
1284
- self._proc_gnusparse_01(next, pax_headers)
1285
-
1286
- elif "GNU.sparse.size" in pax_headers:
1287
- # GNU extended sparse format version 0.0.
1288
- self._proc_gnusparse_00(next, pax_headers, buf)
1289
-
1290
- elif pax_headers.get("GNU.sparse.major") == "1" and pax_headers.get("GNU.sparse.minor") == "0":
1291
- # GNU extended sparse format version 1.0.
1292
- self._proc_gnusparse_10(next, pax_headers, tarfile)
1293
-
1294
- if self.type in (XHDTYPE, SOLARIS_XHDTYPE):
1295
- # Patch the TarInfo object with the extended header info.
1296
- next._apply_pax_info(pax_headers, tarfile.encoding, tarfile.errors)
1297
- next.offset = self.offset
1298
-
1299
- if "size" in pax_headers:
1300
- # If the extended header replaces the size field,
1301
- # we need to recalculate the offset where the next
1302
- # header starts.
1303
- offset = next.offset_data
1304
- if next.isreg() or next.type not in SUPPORTED_TYPES:
1305
- offset += next._block(next.size)
1306
- tarfile.offset = offset
1307
-
1308
- return next
1309
-
1310
- def _proc_gnusparse_00(self, next, pax_headers, buf):
1311
- """Process a GNU tar extended sparse header, version 0.0.
1312
- """
1313
- offsets = []
1314
- for match in re.finditer(br"\d+ GNU.sparse.offset=(\d+)\n", buf):
1315
- offsets.append(int(match.group(1)))
1316
- numbytes = []
1317
- for match in re.finditer(br"\d+ GNU.sparse.numbytes=(\d+)\n", buf):
1318
- numbytes.append(int(match.group(1)))
1319
- next.sparse = list(zip(offsets, numbytes))
1320
-
1321
- def _proc_gnusparse_01(self, next, pax_headers):
1322
- """Process a GNU tar extended sparse header, version 0.1.
1323
- """
1324
- sparse = [int(x) for x in pax_headers["GNU.sparse.map"].split(",")]
1325
- next.sparse = list(zip(sparse[::2], sparse[1::2]))
1326
-
1327
- def _proc_gnusparse_10(self, next, pax_headers, tarfile):
1328
- """Process a GNU tar extended sparse header, version 1.0.
1329
- """
1330
- fields = None
1331
- sparse = []
1332
- buf = tarfile.fileobj.read(BLOCKSIZE)
1333
- fields, buf = buf.split(b"\n", 1)
1334
- fields = int(fields)
1335
- while len(sparse) < fields * 2:
1336
- if b"\n" not in buf:
1337
- buf += tarfile.fileobj.read(BLOCKSIZE)
1338
- number, buf = buf.split(b"\n", 1)
1339
- sparse.append(int(number))
1340
- next.offset_data = tarfile.fileobj.tell()
1341
- next.sparse = list(zip(sparse[::2], sparse[1::2]))
1342
-
1343
- def _apply_pax_info(self, pax_headers, encoding, errors):
1344
- """Replace fields with supplemental information from a previous
1345
- pax extended or global header.
1346
- """
1347
- for keyword, value in pax_headers.items():
1348
- if keyword == "GNU.sparse.name":
1349
- setattr(self, "path", value)
1350
- elif keyword == "GNU.sparse.size":
1351
- setattr(self, "size", int(value))
1352
- elif keyword == "GNU.sparse.realsize":
1353
- setattr(self, "size", int(value))
1354
- elif keyword in PAX_FIELDS:
1355
- if keyword in PAX_NUMBER_FIELDS:
1356
- try:
1357
- value = PAX_NUMBER_FIELDS[keyword](value)
1358
- except ValueError:
1359
- value = 0
1360
- if keyword == "path":
1361
- value = value.rstrip("/")
1362
- setattr(self, keyword, value)
1363
-
1364
- self.pax_headers = pax_headers.copy()
1365
-
1366
- def _decode_pax_field(self, value, encoding, fallback_encoding, fallback_errors):
1367
- """Decode a single field from a pax record.
1368
- """
1369
- try:
1370
- return value.decode(encoding, "strict")
1371
- except UnicodeDecodeError:
1372
- return value.decode(fallback_encoding, fallback_errors)
1373
-
1374
- def _block(self, count):
1375
- """Round up a byte count by BLOCKSIZE and return it,
1376
- e.g. _block(834) => 1024.
1377
- """
1378
- blocks, remainder = divmod(count, BLOCKSIZE)
1379
- if remainder:
1380
- blocks += 1
1381
- return blocks * BLOCKSIZE
1382
-
1383
- def isreg(self):
1384
- 'Return True if the Tarinfo object is a regular file.'
1385
- return self.type in REGULAR_TYPES
1386
-
1387
- def isfile(self):
1388
- 'Return True if the Tarinfo object is a regular file.'
1389
- return self.isreg()
1390
-
1391
- def isdir(self):
1392
- 'Return True if it is a directory.'
1393
- return self.type == DIRTYPE
1394
-
1395
- def issym(self):
1396
- 'Return True if it is a symbolic link.'
1397
- return self.type == SYMTYPE
1398
-
1399
- def islnk(self):
1400
- 'Return True if it is a hard link.'
1401
- return self.type == LNKTYPE
1402
-
1403
- def ischr(self):
1404
- 'Return True if it is a character device.'
1405
- return self.type == CHRTYPE
1406
-
1407
- def isblk(self):
1408
- 'Return True if it is a block device.'
1409
- return self.type == BLKTYPE
1410
-
1411
- def isfifo(self):
1412
- 'Return True if it is a FIFO.'
1413
- return self.type == FIFOTYPE
1414
-
1415
- def issparse(self):
1416
- return self.sparse is not None
1417
-
1418
- def isdev(self):
1419
- 'Return True if it is one of character device, block device or FIFO.'
1420
- return self.type in (CHRTYPE, BLKTYPE, FIFOTYPE)
1421
- # class TarInfo
1422
-
1423
- class TarFile(object):
1424
- """The TarFile Class provides an interface to tar archives.
1425
- """
1426
-
1427
- debug = 0 # May be set from 0 (no msgs) to 3 (all msgs)
1428
-
1429
- dereference = False # If true, add content of linked file to the
1430
- # tar file, else the link.
1431
-
1432
- ignore_zeros = False # If true, skips empty or invalid blocks and
1433
- # continues processing.
1434
-
1435
- errorlevel = 1 # If 0, fatal errors only appear in debug
1436
- # messages (if debug >= 0). If > 0, errors
1437
- # are passed to the caller as exceptions.
1438
-
1439
- format = DEFAULT_FORMAT # The format to use when creating an archive.
1440
-
1441
- encoding = ENCODING # Encoding for 8-bit character strings.
1442
-
1443
- errors = None # Error handler for unicode conversion.
1444
-
1445
- tarinfo = TarInfo # The default TarInfo class to use.
1446
-
1447
- fileobject = ExFileObject # The file-object for extractfile().
1448
-
1449
- def __init__(self, name=None, mode="r", fileobj=None, format=None,
1450
- tarinfo=None, dereference=None, ignore_zeros=None, encoding=None,
1451
- errors="surrogateescape", pax_headers=None, debug=None,
1452
- errorlevel=None, copybufsize=None):
1453
- """Open an (uncompressed) tar archive `name'. `mode' is either 'r' to
1454
- read from an existing archive, 'a' to append data to an existing
1455
- file or 'w' to create a new file overwriting an existing one. `mode'
1456
- defaults to 'r'.
1457
- If `fileobj' is given, it is used for reading or writing data. If it
1458
- can be determined, `mode' is overridden by `fileobj's mode.
1459
- `fileobj' is not closed, when TarFile is closed.
1460
- """
1461
- modes = {"r": "rb", "a": "r+b", "w": "wb", "x": "xb"}
1462
- if mode not in modes:
1463
- raise ValueError("mode must be 'r', 'a', 'w' or 'x'")
1464
- self.mode = mode
1465
- self._mode = modes[mode]
1466
-
1467
- if not fileobj:
1468
- if self.mode == "a" and not os.path.exists(name):
1469
- # Create nonexistent files in append mode.
1470
- self.mode = "w"
1471
- self._mode = "wb"
1472
- fileobj = bltn_open(name, self._mode)
1473
- self._extfileobj = False
1474
- else:
1475
- if (name is None and hasattr(fileobj, "name") and
1476
- isinstance(fileobj.name, (str, bytes))):
1477
- name = fileobj.name
1478
- if hasattr(fileobj, "mode"):
1479
- self._mode = fileobj.mode
1480
- self._extfileobj = True
1481
- self.name = os.path.abspath(name) if name else None
1482
- self.fileobj = fileobj
1483
-
1484
- # Init attributes.
1485
- if format is not None:
1486
- self.format = format
1487
- if tarinfo is not None:
1488
- self.tarinfo = tarinfo
1489
- if dereference is not None:
1490
- self.dereference = dereference
1491
- if ignore_zeros is not None:
1492
- self.ignore_zeros = ignore_zeros
1493
- if encoding is not None:
1494
- self.encoding = encoding
1495
- self.errors = errors
1496
-
1497
- if pax_headers is not None and self.format == PAX_FORMAT:
1498
- self.pax_headers = pax_headers
1499
- else:
1500
- self.pax_headers = {}
1501
-
1502
- if debug is not None:
1503
- self.debug = debug
1504
- if errorlevel is not None:
1505
- self.errorlevel = errorlevel
1506
-
1507
- # Init datastructures.
1508
- self.copybufsize = copybufsize
1509
- self.closed = False
1510
- self.members = [] # list of members as TarInfo objects
1511
- self._loaded = False # flag if all members have been read
1512
- self.offset = self.fileobj.tell()
1513
- # current position in the archive file
1514
- self.inodes = {} # dictionary caching the inodes of
1515
- # archive members already added
1516
-
1517
- try:
1518
- if self.mode == "r":
1519
- self.firstmember = None
1520
- self.firstmember = self.next()
1521
-
1522
- if self.mode == "a":
1523
- # Move to the end of the archive,
1524
- # before the first empty block.
1525
- while True:
1526
- self.fileobj.seek(self.offset)
1527
- try:
1528
- tarinfo = self.tarinfo.fromtarfile(self)
1529
- self.members.append(tarinfo)
1530
- except EOFHeaderError:
1531
- self.fileobj.seek(self.offset)
1532
- break
1533
- except HeaderError as e:
1534
- raise ReadError(str(e))
1535
-
1536
- if self.mode in ("a", "w", "x"):
1537
- self._loaded = True
1538
-
1539
- if self.pax_headers:
1540
- buf = self.tarinfo.create_pax_global_header(self.pax_headers.copy())
1541
- self.fileobj.write(buf)
1542
- self.offset += len(buf)
1543
- except:
1544
- if not self._extfileobj:
1545
- self.fileobj.close()
1546
- self.closed = True
1547
- raise
1548
-
1549
- #--------------------------------------------------------------------------
1550
- # Below are the classmethods which act as alternate constructors to the
1551
- # TarFile class. The open() method is the only one that is needed for
1552
- # public use; it is the "super"-constructor and is able to select an
1553
- # adequate "sub"-constructor for a particular compression using the mapping
1554
- # from OPEN_METH.
1555
- #
1556
- # This concept allows one to subclass TarFile without losing the comfort of
1557
- # the super-constructor. A sub-constructor is registered and made available
1558
- # by adding it to the mapping in OPEN_METH.
1559
-
1560
- @classmethod
1561
- def open(cls, name=None, mode="r", fileobj=None, bufsize=RECORDSIZE, **kwargs):
1562
- """Open a tar archive for reading, writing or appending. Return
1563
- an appropriate TarFile class.
1564
-
1565
- mode:
1566
- 'r' or 'r:*' open for reading with transparent compression
1567
- 'r:' open for reading exclusively uncompressed
1568
- 'r:gz' open for reading with gzip compression
1569
- 'r:bz2' open for reading with bzip2 compression
1570
- 'r:xz' open for reading with lzma compression
1571
- 'a' or 'a:' open for appending, creating the file if necessary
1572
- 'w' or 'w:' open for writing without compression
1573
- 'w:gz' open for writing with gzip compression
1574
- 'w:bz2' open for writing with bzip2 compression
1575
- 'w:xz' open for writing with lzma compression
1576
-
1577
- 'x' or 'x:' create a tarfile exclusively without compression, raise
1578
- an exception if the file is already created
1579
- 'x:gz' create a gzip compressed tarfile, raise an exception
1580
- if the file is already created
1581
- 'x:bz2' create a bzip2 compressed tarfile, raise an exception
1582
- if the file is already created
1583
- 'x:xz' create an lzma compressed tarfile, raise an exception
1584
- if the file is already created
1585
-
1586
- 'r|*' open a stream of tar blocks with transparent compression
1587
- 'r|' open an uncompressed stream of tar blocks for reading
1588
- 'r|gz' open a gzip compressed stream of tar blocks
1589
- 'r|bz2' open a bzip2 compressed stream of tar blocks
1590
- 'r|xz' open an lzma compressed stream of tar blocks
1591
- 'w|' open an uncompressed stream for writing
1592
- 'w|gz' open a gzip compressed stream for writing
1593
- 'w|bz2' open a bzip2 compressed stream for writing
1594
- 'w|xz' open an lzma compressed stream for writing
1595
- """
1596
-
1597
- if not name and not fileobj:
1598
- raise ValueError("nothing to open")
1599
-
1600
- if mode in ("r", "r:*"):
1601
- # Find out which *open() is appropriate for opening the file.
1602
- def not_compressed(comptype):
1603
- return cls.OPEN_METH[comptype] == 'taropen'
1604
- for comptype in sorted(cls.OPEN_METH, key=not_compressed):
1605
- func = getattr(cls, cls.OPEN_METH[comptype])
1606
- if fileobj is not None:
1607
- saved_pos = fileobj.tell()
1608
- try:
1609
- return func(name, "r", fileobj, **kwargs)
1610
- except (ReadError, CompressionError):
1611
- if fileobj is not None:
1612
- fileobj.seek(saved_pos)
1613
- continue
1614
- raise ReadError("file could not be opened successfully")
1615
-
1616
- elif ":" in mode:
1617
- filemode, comptype = mode.split(":", 1)
1618
- filemode = filemode or "r"
1619
- comptype = comptype or "tar"
1620
-
1621
- # Select the *open() function according to
1622
- # given compression.
1623
- if comptype in cls.OPEN_METH:
1624
- func = getattr(cls, cls.OPEN_METH[comptype])
1625
- else:
1626
- raise CompressionError("unknown compression type %r" % comptype)
1627
- return func(name, filemode, fileobj, **kwargs)
1628
-
1629
- elif "|" in mode:
1630
- filemode, comptype = mode.split("|", 1)
1631
- filemode = filemode or "r"
1632
- comptype = comptype or "tar"
1633
-
1634
- if filemode not in ("r", "w"):
1635
- raise ValueError("mode must be 'r' or 'w'")
1636
-
1637
- stream = _Stream(name, filemode, comptype, fileobj, bufsize)
1638
- try:
1639
- t = cls(name, filemode, stream, **kwargs)
1640
- except:
1641
- stream.close()
1642
- raise
1643
- t._extfileobj = False
1644
- return t
1645
-
1646
- elif mode in ("a", "w", "x"):
1647
- return cls.taropen(name, mode, fileobj, **kwargs)
1648
-
1649
- raise ValueError("undiscernible mode")
1650
-
1651
- @classmethod
1652
- def taropen(cls, name, mode="r", fileobj=None, **kwargs):
1653
- """Open uncompressed tar archive name for reading or writing.
1654
- """
1655
- if mode not in ("r", "a", "w", "x"):
1656
- raise ValueError("mode must be 'r', 'a', 'w' or 'x'")
1657
- return cls(name, mode, fileobj, **kwargs)
1658
-
1659
- @classmethod
1660
- def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
1661
- """Open gzip compressed tar archive name for reading or writing.
1662
- Appending is not allowed.
1663
- """
1664
- if mode not in ("r", "w", "x"):
1665
- raise ValueError("mode must be 'r', 'w' or 'x'")
1666
-
1667
- try:
1668
- from gzip import GzipFile
1669
- except ImportError:
1670
- raise CompressionError("gzip module is not available")
1671
-
1672
- try:
1673
- fileobj = GzipFile(name, mode + "b", compresslevel, fileobj)
1674
- except OSError:
1675
- if fileobj is not None and mode == 'r':
1676
- raise ReadError("not a gzip file")
1677
- raise
1678
-
1679
- try:
1680
- t = cls.taropen(name, mode, fileobj, **kwargs)
1681
- except OSError:
1682
- fileobj.close()
1683
- if mode == 'r':
1684
- raise ReadError("not a gzip file")
1685
- raise
1686
- except:
1687
- fileobj.close()
1688
- raise
1689
- t._extfileobj = False
1690
- return t
1691
-
1692
- @classmethod
1693
- def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
1694
- """Open bzip2 compressed tar archive name for reading or writing.
1695
- Appending is not allowed.
1696
- """
1697
- if mode not in ("r", "w", "x"):
1698
- raise ValueError("mode must be 'r', 'w' or 'x'")
1699
-
1700
- try:
1701
- from bz2 import BZ2File
1702
- except ImportError:
1703
- raise CompressionError("bz2 module is not available")
1704
-
1705
- fileobj = BZ2File(fileobj or name, mode, compresslevel=compresslevel)
1706
-
1707
- try:
1708
- t = cls.taropen(name, mode, fileobj, **kwargs)
1709
- except (OSError, EOFError):
1710
- fileobj.close()
1711
- if mode == 'r':
1712
- raise ReadError("not a bzip2 file")
1713
- raise
1714
- except:
1715
- fileobj.close()
1716
- raise
1717
- t._extfileobj = False
1718
- return t
1719
-
1720
- @classmethod
1721
- def xzopen(cls, name, mode="r", fileobj=None, preset=None, **kwargs):
1722
- """Open lzma compressed tar archive name for reading or writing.
1723
- Appending is not allowed.
1724
- """
1725
- if mode not in ("r", "w", "x"):
1726
- raise ValueError("mode must be 'r', 'w' or 'x'")
1727
-
1728
- try:
1729
- from lzma import LZMAFile, LZMAError
1730
- except ImportError:
1731
- raise CompressionError("lzma module is not available")
1732
-
1733
- fileobj = LZMAFile(fileobj or name, mode, preset=preset)
1734
-
1735
- try:
1736
- t = cls.taropen(name, mode, fileobj, **kwargs)
1737
- except (LZMAError, EOFError):
1738
- fileobj.close()
1739
- if mode == 'r':
1740
- raise ReadError("not an lzma file")
1741
- raise
1742
- except:
1743
- fileobj.close()
1744
- raise
1745
- t._extfileobj = False
1746
- return t
1747
-
1748
- # All *open() methods are registered here.
1749
- OPEN_METH = {
1750
- "tar": "taropen", # uncompressed tar
1751
- "gz": "gzopen", # gzip compressed tar
1752
- "bz2": "bz2open", # bzip2 compressed tar
1753
- "xz": "xzopen" # lzma compressed tar
1754
- }
1755
-
1756
- #--------------------------------------------------------------------------
1757
- # The public methods which TarFile provides:
1758
-
1759
- def close(self):
1760
- """Close the TarFile. In write-mode, two finishing zero blocks are
1761
- appended to the archive.
1762
- """
1763
- if self.closed:
1764
- return
1765
-
1766
- self.closed = True
1767
- try:
1768
- if self.mode in ("a", "w", "x"):
1769
- self.fileobj.write(NUL * (BLOCKSIZE * 2))
1770
- self.offset += (BLOCKSIZE * 2)
1771
- # fill up the end with zero-blocks
1772
- # (like option -b20 for tar does)
1773
- blocks, remainder = divmod(self.offset, RECORDSIZE)
1774
- if remainder > 0:
1775
- self.fileobj.write(NUL * (RECORDSIZE - remainder))
1776
- finally:
1777
- if not self._extfileobj:
1778
- self.fileobj.close()
1779
-
1780
- def getmember(self, name):
1781
- """Return a TarInfo object for member `name'. If `name' can not be
1782
- found in the archive, KeyError is raised. If a member occurs more
1783
- than once in the archive, its last occurrence is assumed to be the
1784
- most up-to-date version.
1785
- """
1786
- tarinfo = self._getmember(name)
1787
- if tarinfo is None:
1788
- raise KeyError("filename %r not found" % name)
1789
- return tarinfo
1790
-
1791
- def getmembers(self):
1792
- """Return the members of the archive as a list of TarInfo objects. The
1793
- list has the same order as the members in the archive.
1794
- """
1795
- self._check()
1796
- if not self._loaded: # if we want to obtain a list of
1797
- self._load() # all members, we first have to
1798
- # scan the whole archive.
1799
- return self.members
1800
-
1801
- def getnames(self):
1802
- """Return the members of the archive as a list of their names. It has
1803
- the same order as the list returned by getmembers().
1804
- """
1805
- return [tarinfo.name for tarinfo in self.getmembers()]
1806
-
1807
- def gettarinfo(self, name=None, arcname=None, fileobj=None):
1808
- """Create a TarInfo object from the result of os.stat or equivalent
1809
- on an existing file. The file is either named by `name', or
1810
- specified as a file object `fileobj' with a file descriptor. If
1811
- given, `arcname' specifies an alternative name for the file in the
1812
- archive, otherwise, the name is taken from the 'name' attribute of
1813
- 'fileobj', or the 'name' argument. The name should be a text
1814
- string.
1815
- """
1816
- self._check("awx")
1817
-
1818
- # When fileobj is given, replace name by
1819
- # fileobj's real name.
1820
- if fileobj is not None:
1821
- name = fileobj.name
1822
-
1823
- # Building the name of the member in the archive.
1824
- # Backward slashes are converted to forward slashes,
1825
- # Absolute paths are turned to relative paths.
1826
- if arcname is None:
1827
- arcname = name
1828
- drv, arcname = os.path.splitdrive(arcname)
1829
- arcname = arcname.replace(os.sep, "/")
1830
- arcname = arcname.lstrip("/")
1831
-
1832
- # Now, fill the TarInfo object with
1833
- # information specific for the file.
1834
- tarinfo = self.tarinfo()
1835
- tarinfo.tarfile = self # Not needed
1836
-
1837
- # Use os.stat or os.lstat, depending on if symlinks shall be resolved.
1838
- if fileobj is None:
1839
- if not self.dereference:
1840
- statres = os.lstat(name)
1841
- else:
1842
- statres = os.stat(name)
1843
- else:
1844
- statres = os.fstat(fileobj.fileno())
1845
- linkname = ""
1846
-
1847
- stmd = statres.st_mode
1848
- if stat.S_ISREG(stmd):
1849
- inode = (statres.st_ino, statres.st_dev)
1850
- if not self.dereference and statres.st_nlink > 1 and \
1851
- inode in self.inodes and arcname != self.inodes[inode]:
1852
- # Is it a hardlink to an already
1853
- # archived file?
1854
- type = LNKTYPE
1855
- linkname = self.inodes[inode]
1856
- else:
1857
- # The inode is added only if its valid.
1858
- # For win32 it is always 0.
1859
- type = REGTYPE
1860
- if inode[0]:
1861
- self.inodes[inode] = arcname
1862
- elif stat.S_ISDIR(stmd):
1863
- type = DIRTYPE
1864
- elif stat.S_ISFIFO(stmd):
1865
- type = FIFOTYPE
1866
- elif stat.S_ISLNK(stmd):
1867
- type = SYMTYPE
1868
- linkname = os.readlink(name)
1869
- elif stat.S_ISCHR(stmd):
1870
- type = CHRTYPE
1871
- elif stat.S_ISBLK(stmd):
1872
- type = BLKTYPE
1873
- else:
1874
- return None
1875
-
1876
- # Fill the TarInfo object with all
1877
- # information we can get.
1878
- tarinfo.name = arcname
1879
- tarinfo.mode = stmd
1880
- tarinfo.uid = statres.st_uid
1881
- tarinfo.gid = statres.st_gid
1882
- if type == REGTYPE:
1883
- tarinfo.size = statres.st_size
1884
- else:
1885
- tarinfo.size = 0
1886
- tarinfo.mtime = statres.st_mtime
1887
- tarinfo.type = type
1888
- tarinfo.linkname = linkname
1889
- if pwd:
1890
- try:
1891
- tarinfo.uname = pwd.getpwuid(tarinfo.uid)[0]
1892
- except KeyError:
1893
- pass
1894
- if grp:
1895
- try:
1896
- tarinfo.gname = grp.getgrgid(tarinfo.gid)[0]
1897
- except KeyError:
1898
- pass
1899
-
1900
- if type in (CHRTYPE, BLKTYPE):
1901
- if hasattr(os, "major") and hasattr(os, "minor"):
1902
- tarinfo.devmajor = os.major(statres.st_rdev)
1903
- tarinfo.devminor = os.minor(statres.st_rdev)
1904
- return tarinfo
1905
-
1906
- def list(self, verbose=True, *, members=None):
1907
- """Print a table of contents to sys.stdout. If `verbose' is False, only
1908
- the names of the members are printed. If it is True, an `ls -l'-like
1909
- output is produced. `members' is optional and must be a subset of the
1910
- list returned by getmembers().
1911
- """
1912
- self._check()
1913
-
1914
- if members is None:
1915
- members = self
1916
- for tarinfo in members:
1917
- if verbose:
1918
- _safe_print(stat.filemode(tarinfo.mode))
1919
- _safe_print("%s/%s" % (tarinfo.uname or tarinfo.uid,
1920
- tarinfo.gname or tarinfo.gid))
1921
- if tarinfo.ischr() or tarinfo.isblk():
1922
- _safe_print("%10s" %
1923
- ("%d,%d" % (tarinfo.devmajor, tarinfo.devminor)))
1924
- else:
1925
- _safe_print("%10d" % tarinfo.size)
1926
- _safe_print("%d-%02d-%02d %02d:%02d:%02d" \
1927
- % time.localtime(tarinfo.mtime)[:6])
1928
-
1929
- _safe_print(tarinfo.name + ("/" if tarinfo.isdir() else ""))
1930
-
1931
- if verbose:
1932
- if tarinfo.issym():
1933
- _safe_print("-> " + tarinfo.linkname)
1934
- if tarinfo.islnk():
1935
- _safe_print("link to " + tarinfo.linkname)
1936
- print()
1937
-
1938
- def add(self, name, arcname=None, recursive=True, *, filter=None):
1939
- """Add the file `name' to the archive. `name' may be any type of file
1940
- (directory, fifo, symbolic link, etc.). If given, `arcname'
1941
- specifies an alternative name for the file in the archive.
1942
- Directories are added recursively by default. This can be avoided by
1943
- setting `recursive' to False. `filter' is a function
1944
- that expects a TarInfo object argument and returns the changed
1945
- TarInfo object, if it returns None the TarInfo object will be
1946
- excluded from the archive.
1947
- """
1948
- self._check("awx")
1949
-
1950
- if arcname is None:
1951
- arcname = name
1952
-
1953
- # Skip if somebody tries to archive the archive...
1954
- if self.name is not None and os.path.abspath(name) == self.name:
1955
- self._dbg(2, "tarfile: Skipped %r" % name)
1956
- return
1957
-
1958
- self._dbg(1, name)
1959
-
1960
- # Create a TarInfo object from the file.
1961
- tarinfo = self.gettarinfo(name, arcname)
1962
-
1963
- if tarinfo is None:
1964
- self._dbg(1, "tarfile: Unsupported type %r" % name)
1965
- return
1966
-
1967
- # Change or exclude the TarInfo object.
1968
- if filter is not None:
1969
- tarinfo = filter(tarinfo)
1970
- if tarinfo is None:
1971
- self._dbg(2, "tarfile: Excluded %r" % name)
1972
- return
1973
-
1974
- # Append the tar header and data to the archive.
1975
- if tarinfo.isreg():
1976
- with bltn_open(name, "rb") as f:
1977
- self.addfile(tarinfo, f)
1978
-
1979
- elif tarinfo.isdir():
1980
- self.addfile(tarinfo)
1981
- if recursive:
1982
- for f in sorted(os.listdir(name)):
1983
- self.add(os.path.join(name, f), os.path.join(arcname, f),
1984
- recursive, filter=filter)
1985
-
1986
- else:
1987
- self.addfile(tarinfo)
1988
-
1989
- def addfile(self, tarinfo, fileobj=None):
1990
- """Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
1991
- given, it should be a binary file, and tarinfo.size bytes are read
1992
- from it and added to the archive. You can create TarInfo objects
1993
- directly, or by using gettarinfo().
1994
- """
1995
- self._check("awx")
1996
-
1997
- tarinfo = copy.copy(tarinfo)
1998
-
1999
- buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
2000
- self.fileobj.write(buf)
2001
- self.offset += len(buf)
2002
- bufsize=self.copybufsize
2003
- # If there's data to follow, append it.
2004
- if fileobj is not None:
2005
- copyfileobj(fileobj, self.fileobj, tarinfo.size, bufsize=bufsize)
2006
- blocks, remainder = divmod(tarinfo.size, BLOCKSIZE)
2007
- if remainder > 0:
2008
- self.fileobj.write(NUL * (BLOCKSIZE - remainder))
2009
- blocks += 1
2010
- self.offset += blocks * BLOCKSIZE
2011
-
2012
- self.members.append(tarinfo)
2013
-
2014
- def extractall(self, path=".", members=None, *, numeric_owner=False):
2015
- """Extract all members from the archive to the current working
2016
- directory and set owner, modification time and permissions on
2017
- directories afterwards. `path' specifies a different directory
2018
- to extract to. `members' is optional and must be a subset of the
2019
- list returned by getmembers(). If `numeric_owner` is True, only
2020
- the numbers for user/group names are used and not the names.
2021
- """
2022
- directories = []
2023
-
2024
- if members is None:
2025
- members = self
2026
-
2027
- for tarinfo in members:
2028
- if tarinfo.isdir():
2029
- # Extract directories with a safe mode.
2030
- directories.append(tarinfo)
2031
- tarinfo = copy.copy(tarinfo)
2032
- tarinfo.mode = 0o700
2033
- # Do not set_attrs directories, as we will do that further down
2034
- self.extract(tarinfo, path, set_attrs=not tarinfo.isdir(),
2035
- numeric_owner=numeric_owner)
2036
-
2037
- # Reverse sort directories.
2038
- directories.sort(key=lambda a: a.name)
2039
- directories.reverse()
2040
-
2041
- # Set correct owner, mtime and filemode on directories.
2042
- for tarinfo in directories:
2043
- dirpath = os.path.join(path, tarinfo.name)
2044
- try:
2045
- self.chown(tarinfo, dirpath, numeric_owner=numeric_owner)
2046
- self.utime(tarinfo, dirpath)
2047
- self.chmod(tarinfo, dirpath)
2048
- except ExtractError as e:
2049
- if self.errorlevel > 1:
2050
- raise
2051
- else:
2052
- self._dbg(1, "tarfile: %s" % e)
2053
-
2054
- def extract(self, member, path="", set_attrs=True, *, numeric_owner=False):
2055
- """Extract a member from the archive to the current working directory,
2056
- using its full name. Its file information is extracted as accurately
2057
- as possible. `member' may be a filename or a TarInfo object. You can
2058
- specify a different directory using `path'. File attributes (owner,
2059
- mtime, mode) are set unless `set_attrs' is False. If `numeric_owner`
2060
- is True, only the numbers for user/group names are used and not
2061
- the names.
2062
- """
2063
- self._check("r")
2064
-
2065
- if isinstance(member, str):
2066
- tarinfo = self.getmember(member)
2067
- else:
2068
- tarinfo = member
2069
-
2070
- # Prepare the link target for makelink().
2071
- if tarinfo.islnk():
2072
- tarinfo._link_target = os.path.join(path, tarinfo.linkname)
2073
-
2074
- try:
2075
- self._extract_member(tarinfo, os.path.join(path, tarinfo.name),
2076
- set_attrs=set_attrs,
2077
- numeric_owner=numeric_owner)
2078
- except OSError as e:
2079
- if self.errorlevel > 0:
2080
- raise
2081
- else:
2082
- if e.filename is None:
2083
- self._dbg(1, "tarfile: %s" % e.strerror)
2084
- else:
2085
- self._dbg(1, "tarfile: %s %r" % (e.strerror, e.filename))
2086
- except ExtractError as e:
2087
- if self.errorlevel > 1:
2088
- raise
2089
- else:
2090
- self._dbg(1, "tarfile: %s" % e)
2091
-
2092
- def extractfile(self, member):
2093
- """Extract a member from the archive as a file object. `member' may be
2094
- a filename or a TarInfo object. If `member' is a regular file or a
2095
- link, an io.BufferedReader object is returned. Otherwise, None is
2096
- returned.
2097
- """
2098
- self._check("r")
2099
-
2100
- if isinstance(member, str):
2101
- tarinfo = self.getmember(member)
2102
- else:
2103
- tarinfo = member
2104
-
2105
- if tarinfo.isreg() or tarinfo.type not in SUPPORTED_TYPES:
2106
- # Members with unknown types are treated as regular files.
2107
- return self.fileobject(self, tarinfo)
2108
-
2109
- elif tarinfo.islnk() or tarinfo.issym():
2110
- if isinstance(self.fileobj, _Stream):
2111
- # A small but ugly workaround for the case that someone tries
2112
- # to extract a (sym)link as a file-object from a non-seekable
2113
- # stream of tar blocks.
2114
- raise StreamError("cannot extract (sym)link as file object")
2115
- else:
2116
- # A (sym)link's file object is its target's file object.
2117
- return self.extractfile(self._find_link_target(tarinfo))
2118
- else:
2119
- # If there's no data associated with the member (directory, chrdev,
2120
- # blkdev, etc.), return None instead of a file object.
2121
- return None
2122
-
2123
- def _extract_member(self, tarinfo, targetpath, set_attrs=True,
2124
- numeric_owner=False):
2125
- """Extract the TarInfo object tarinfo to a physical
2126
- file called targetpath.
2127
- """
2128
- # Fetch the TarInfo object for the given name
2129
- # and build the destination pathname, replacing
2130
- # forward slashes to platform specific separators.
2131
- targetpath = targetpath.rstrip("/")
2132
- targetpath = targetpath.replace("/", os.sep)
2133
-
2134
- # Create all upper directories.
2135
- upperdirs = os.path.dirname(targetpath)
2136
- if upperdirs and not os.path.exists(upperdirs):
2137
- # Create directories that are not part of the archive with
2138
- # default permissions.
2139
- os.makedirs(upperdirs)
2140
-
2141
- if tarinfo.islnk() or tarinfo.issym():
2142
- self._dbg(1, "%s -> %s" % (tarinfo.name, tarinfo.linkname))
2143
- else:
2144
- self._dbg(1, tarinfo.name)
2145
-
2146
- if tarinfo.isreg():
2147
- self.makefile(tarinfo, targetpath)
2148
- elif tarinfo.isdir():
2149
- self.makedir(tarinfo, targetpath)
2150
- elif tarinfo.isfifo():
2151
- self.makefifo(tarinfo, targetpath)
2152
- elif tarinfo.ischr() or tarinfo.isblk():
2153
- self.makedev(tarinfo, targetpath)
2154
- elif tarinfo.islnk() or tarinfo.issym():
2155
- self.makelink(tarinfo, targetpath)
2156
- elif tarinfo.type not in SUPPORTED_TYPES:
2157
- self.makeunknown(tarinfo, targetpath)
2158
- else:
2159
- self.makefile(tarinfo, targetpath)
2160
-
2161
- if set_attrs:
2162
- self.chown(tarinfo, targetpath, numeric_owner)
2163
- if not tarinfo.issym():
2164
- self.chmod(tarinfo, targetpath)
2165
- self.utime(tarinfo, targetpath)
2166
-
2167
- #--------------------------------------------------------------------------
2168
- # Below are the different file methods. They are called via
2169
- # _extract_member() when extract() is called. They can be replaced in a
2170
- # subclass to implement other functionality.
2171
-
2172
- def makedir(self, tarinfo, targetpath):
2173
- """Make a directory called targetpath.
2174
- """
2175
- try:
2176
- # Use a safe mode for the directory, the real mode is set
2177
- # later in _extract_member().
2178
- os.mkdir(targetpath, 0o700)
2179
- except FileExistsError:
2180
- pass
2181
-
2182
- def makefile(self, tarinfo, targetpath):
2183
- """Make a file called targetpath.
2184
- """
2185
- source = self.fileobj
2186
- source.seek(tarinfo.offset_data)
2187
- bufsize = self.copybufsize
2188
- with bltn_open(targetpath, "wb") as target:
2189
- if tarinfo.sparse is not None:
2190
- for offset, size in tarinfo.sparse:
2191
- target.seek(offset)
2192
- copyfileobj(source, target, size, ReadError, bufsize)
2193
- target.seek(tarinfo.size)
2194
- target.truncate()
2195
- else:
2196
- copyfileobj(source, target, tarinfo.size, ReadError, bufsize)
2197
-
2198
- def makeunknown(self, tarinfo, targetpath):
2199
- """Make a file from a TarInfo object with an unknown type
2200
- at targetpath.
2201
- """
2202
- self.makefile(tarinfo, targetpath)
2203
- self._dbg(1, "tarfile: Unknown file type %r, " \
2204
- "extracted as regular file." % tarinfo.type)
2205
-
2206
- def makefifo(self, tarinfo, targetpath):
2207
- """Make a fifo called targetpath.
2208
- """
2209
- if hasattr(os, "mkfifo"):
2210
- os.mkfifo(targetpath)
2211
- else:
2212
- raise ExtractError("fifo not supported by system")
2213
-
2214
- def makedev(self, tarinfo, targetpath):
2215
- """Make a character or block device called targetpath.
2216
- """
2217
- if not hasattr(os, "mknod") or not hasattr(os, "makedev"):
2218
- raise ExtractError("special devices not supported by system")
2219
-
2220
- mode = tarinfo.mode
2221
- if tarinfo.isblk():
2222
- mode |= stat.S_IFBLK
2223
- else:
2224
- mode |= stat.S_IFCHR
2225
-
2226
- os.mknod(targetpath, mode,
2227
- os.makedev(tarinfo.devmajor, tarinfo.devminor))
2228
-
2229
- def makelink(self, tarinfo, targetpath):
2230
- """Make a (symbolic) link called targetpath. If it cannot be created
2231
- (platform limitation), we try to make a copy of the referenced file
2232
- instead of a link.
2233
- """
2234
- try:
2235
- # For systems that support symbolic and hard links.
2236
- if tarinfo.issym():
2237
- os.symlink(tarinfo.linkname, targetpath)
2238
- else:
2239
- # See extract().
2240
- if os.path.exists(tarinfo._link_target):
2241
- os.link(tarinfo._link_target, targetpath)
2242
- else:
2243
- self._extract_member(self._find_link_target(tarinfo),
2244
- targetpath)
2245
- except symlink_exception:
2246
- try:
2247
- self._extract_member(self._find_link_target(tarinfo),
2248
- targetpath)
2249
- except KeyError:
2250
- raise ExtractError("unable to resolve link inside archive")
2251
-
2252
- def chown(self, tarinfo, targetpath, numeric_owner):
2253
- """Set owner of targetpath according to tarinfo. If numeric_owner
2254
- is True, use .gid/.uid instead of .gname/.uname. If numeric_owner
2255
- is False, fall back to .gid/.uid when the search based on name
2256
- fails.
2257
- """
2258
- if hasattr(os, "geteuid") and os.geteuid() == 0:
2259
- # We have to be root to do so.
2260
- g = tarinfo.gid
2261
- u = tarinfo.uid
2262
- if not numeric_owner:
2263
- try:
2264
- if grp:
2265
- g = grp.getgrnam(tarinfo.gname)[2]
2266
- except KeyError:
2267
- pass
2268
- try:
2269
- if pwd:
2270
- u = pwd.getpwnam(tarinfo.uname)[2]
2271
- except KeyError:
2272
- pass
2273
- try:
2274
- if tarinfo.issym() and hasattr(os, "lchown"):
2275
- os.lchown(targetpath, u, g)
2276
- else:
2277
- os.chown(targetpath, u, g)
2278
- except OSError:
2279
- raise ExtractError("could not change owner")
2280
-
2281
- def chmod(self, tarinfo, targetpath):
2282
- """Set file permissions of targetpath according to tarinfo.
2283
- """
2284
- try:
2285
- os.chmod(targetpath, tarinfo.mode)
2286
- except OSError:
2287
- raise ExtractError("could not change mode")
2288
-
2289
- def utime(self, tarinfo, targetpath):
2290
- """Set modification time of targetpath according to tarinfo.
2291
- """
2292
- if not hasattr(os, 'utime'):
2293
- return
2294
- try:
2295
- os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime))
2296
- except OSError:
2297
- raise ExtractError("could not change modification time")
2298
-
2299
- #--------------------------------------------------------------------------
2300
- def next(self):
2301
- """Return the next member of the archive as a TarInfo object, when
2302
- TarFile is opened for reading. Return None if there is no more
2303
- available.
2304
- """
2305
- self._check("ra")
2306
- if self.firstmember is not None:
2307
- m = self.firstmember
2308
- self.firstmember = None
2309
- return m
2310
-
2311
- # Advance the file pointer.
2312
- if self.offset != self.fileobj.tell():
2313
- self.fileobj.seek(self.offset - 1)
2314
- if not self.fileobj.read(1):
2315
- raise ReadError("unexpected end of data")
2316
-
2317
- # Read the next block.
2318
- tarinfo = None
2319
- while True:
2320
- try:
2321
- tarinfo = self.tarinfo.fromtarfile(self)
2322
- except EOFHeaderError as e:
2323
- if self.ignore_zeros:
2324
- self._dbg(2, "0x%X: %s" % (self.offset, e))
2325
- self.offset += BLOCKSIZE
2326
- continue
2327
- except InvalidHeaderError as e:
2328
- if self.ignore_zeros:
2329
- self._dbg(2, "0x%X: %s" % (self.offset, e))
2330
- self.offset += BLOCKSIZE
2331
- continue
2332
- elif self.offset == 0:
2333
- raise ReadError(str(e))
2334
- except EmptyHeaderError:
2335
- if self.offset == 0:
2336
- raise ReadError("empty file")
2337
- except TruncatedHeaderError as e:
2338
- if self.offset == 0:
2339
- raise ReadError(str(e))
2340
- except SubsequentHeaderError as e:
2341
- raise ReadError(str(e))
2342
- break
2343
-
2344
- if tarinfo is not None:
2345
- self.members.append(tarinfo)
2346
- else:
2347
- self._loaded = True
2348
-
2349
- return tarinfo
2350
-
2351
- #--------------------------------------------------------------------------
2352
- # Little helper methods:
2353
-
2354
- def _getmember(self, name, tarinfo=None, normalize=False):
2355
- """Find an archive member by name from bottom to top.
2356
- If tarinfo is given, it is used as the starting point.
2357
- """
2358
- # Ensure that all members have been loaded.
2359
- members = self.getmembers()
2360
-
2361
- # Limit the member search list up to tarinfo.
2362
- if tarinfo is not None:
2363
- members = members[:members.index(tarinfo)]
2364
-
2365
- if normalize:
2366
- name = os.path.normpath(name)
2367
-
2368
- for member in reversed(members):
2369
- if normalize:
2370
- member_name = os.path.normpath(member.name)
2371
- else:
2372
- member_name = member.name
2373
-
2374
- if name == member_name:
2375
- return member
2376
-
2377
- def _load(self):
2378
- """Read through the entire archive file and look for readable
2379
- members.
2380
- """
2381
- while True:
2382
- tarinfo = self.next()
2383
- if tarinfo is None:
2384
- break
2385
- self._loaded = True
2386
-
2387
- def _check(self, mode=None):
2388
- """Check if TarFile is still open, and if the operation's mode
2389
- corresponds to TarFile's mode.
2390
- """
2391
- if self.closed:
2392
- raise OSError("%s is closed" % self.__class__.__name__)
2393
- if mode is not None and self.mode not in mode:
2394
- raise OSError("bad operation for mode %r" % self.mode)
2395
-
2396
- def _find_link_target(self, tarinfo):
2397
- """Find the target member of a symlink or hardlink member in the
2398
- archive.
2399
- """
2400
- if tarinfo.issym():
2401
- # Always search the entire archive.
2402
- linkname = "/".join(filter(None, (os.path.dirname(tarinfo.name), tarinfo.linkname)))
2403
- limit = None
2404
- else:
2405
- # Search the archive before the link, because a hard link is
2406
- # just a reference to an already archived file.
2407
- linkname = tarinfo.linkname
2408
- limit = tarinfo
2409
-
2410
- member = self._getmember(linkname, tarinfo=limit, normalize=True)
2411
- if member is None:
2412
- raise KeyError("linkname %r not found" % linkname)
2413
- return member
2414
-
2415
- def __iter__(self):
2416
- """Provide an iterator object.
2417
- """
2418
- if self._loaded:
2419
- yield from self.members
2420
- return
2421
-
2422
- # Yield items using TarFile's next() method.
2423
- # When all members have been read, set TarFile as _loaded.
2424
- index = 0
2425
- # Fix for SF #1100429: Under rare circumstances it can
2426
- # happen that getmembers() is called during iteration,
2427
- # which will have already exhausted the next() method.
2428
- if self.firstmember is not None:
2429
- tarinfo = self.next()
2430
- index += 1
2431
- yield tarinfo
2432
-
2433
- while True:
2434
- if index < len(self.members):
2435
- tarinfo = self.members[index]
2436
- elif not self._loaded:
2437
- tarinfo = self.next()
2438
- if not tarinfo:
2439
- self._loaded = True
2440
- return
2441
- else:
2442
- return
2443
- index += 1
2444
- yield tarinfo
2445
-
2446
- def _dbg(self, level, msg):
2447
- """Write debugging output to sys.stderr.
2448
- """
2449
- if level <= self.debug:
2450
- print(msg, file=sys.stderr)
2451
-
2452
- def __enter__(self):
2453
- self._check()
2454
- return self
2455
-
2456
- def __exit__(self, type, value, traceback):
2457
- if type is None:
2458
- self.close()
2459
- else:
2460
- # An exception occurred. We must not call close() because
2461
- # it would try to write end-of-archive blocks and padding.
2462
- if not self._extfileobj:
2463
- self.fileobj.close()
2464
- self.closed = True
2465
-
2466
- #--------------------
2467
- # exported functions
2468
- #--------------------
2469
- def is_tarfile(name):
2470
- """Return True if name points to a tar archive that we
2471
- are able to handle, else return False.
2472
-
2473
- 'name' should be a string, file, or file-like object.
2474
- """
2475
- try:
2476
- if hasattr(name, "read"):
2477
- t = open(fileobj=name)
2478
- else:
2479
- t = open(name)
2480
- t.close()
2481
- return True
2482
- except TarError:
2483
- return False
2484
-
2485
- open = TarFile.open
2486
-
2487
-
2488
- def main():
2489
- import argparse
2490
-
2491
- description = 'A simple command-line interface for tarfile module.'
2492
- parser = argparse.ArgumentParser(description=description)
2493
- parser.add_argument('-v', '--verbose', action='store_true', default=False,
2494
- help='Verbose output')
2495
- group = parser.add_mutually_exclusive_group(required=True)
2496
- group.add_argument('-l', '--list', metavar='<tarfile>',
2497
- help='Show listing of a tarfile')
2498
- group.add_argument('-e', '--extract', nargs='+',
2499
- metavar=('<tarfile>', '<output_dir>'),
2500
- help='Extract tarfile into target dir')
2501
- group.add_argument('-c', '--create', nargs='+',
2502
- metavar=('<name>', '<file>'),
2503
- help='Create tarfile from sources')
2504
- group.add_argument('-t', '--test', metavar='<tarfile>',
2505
- help='Test if a tarfile is valid')
2506
- args = parser.parse_args()
2507
-
2508
- if args.test is not None:
2509
- src = args.test
2510
- if is_tarfile(src):
2511
- with open(src, 'r') as tar:
2512
- tar.getmembers()
2513
- print(tar.getmembers(), file=sys.stderr)
2514
- if args.verbose:
2515
- print('{!r} is a tar archive.'.format(src))
2516
- else:
2517
- parser.exit(1, '{!r} is not a tar archive.\n'.format(src))
2518
-
2519
- elif args.list is not None:
2520
- src = args.list
2521
- if is_tarfile(src):
2522
- with TarFile.open(src, 'r:*') as tf:
2523
- tf.list(verbose=args.verbose)
2524
- else:
2525
- parser.exit(1, '{!r} is not a tar archive.\n'.format(src))
2526
-
2527
- elif args.extract is not None:
2528
- if len(args.extract) == 1:
2529
- src = args.extract[0]
2530
- curdir = os.curdir
2531
- elif len(args.extract) == 2:
2532
- src, curdir = args.extract
2533
- else:
2534
- parser.exit(1, parser.format_help())
2535
-
2536
- if is_tarfile(src):
2537
- with TarFile.open(src, 'r:*') as tf:
2538
- tf.extractall(path=curdir)
2539
- if args.verbose:
2540
- if curdir == '.':
2541
- msg = '{!r} file is extracted.'.format(src)
2542
- else:
2543
- msg = ('{!r} file is extracted '
2544
- 'into {!r} directory.').format(src, curdir)
2545
- print(msg)
2546
- else:
2547
- parser.exit(1, '{!r} is not a tar archive.\n'.format(src))
2548
-
2549
- elif args.create is not None:
2550
- tar_name = args.create.pop(0)
2551
- _, ext = os.path.splitext(tar_name)
2552
- compressions = {
2553
- # gz
2554
- '.gz': 'gz',
2555
- '.tgz': 'gz',
2556
- # xz
2557
- '.xz': 'xz',
2558
- '.txz': 'xz',
2559
- # bz2
2560
- '.bz2': 'bz2',
2561
- '.tbz': 'bz2',
2562
- '.tbz2': 'bz2',
2563
- '.tb2': 'bz2',
2564
- }
2565
- tar_mode = 'w:' + compressions[ext] if ext in compressions else 'w'
2566
- tar_files = args.create
2567
-
2568
- with TarFile.open(tar_name, tar_mode) as tf:
2569
- for file_name in tar_files:
2570
- tf.add(file_name)
2571
-
2572
- if args.verbose:
2573
- print('{!r} file created.'.format(tar_name))
2574
-
2575
- if __name__ == '__main__':
2576
- main()