@debugmcp/codelldb-linux-arm64 0.0.0-stage → 1.12.3

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 (980) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +21 -2
  3. package/adapter/codelldb +0 -0
  4. package/adapter/scripts/codelldb/__init__.py +7 -0
  5. package/adapter/scripts/codelldb/api.py +125 -0
  6. package/adapter/scripts/codelldb/commands/__init__.py +7 -0
  7. package/adapter/scripts/codelldb/commands/debug_info.py +63 -0
  8. package/adapter/scripts/codelldb/commands/nofail.py +8 -0
  9. package/adapter/scripts/codelldb/event.py +19 -0
  10. package/adapter/scripts/codelldb/interface.py +423 -0
  11. package/adapter/scripts/codelldb/value.py +364 -0
  12. package/adapter/scripts/codelldb/webview.py +57 -0
  13. package/adapter/scripts/console.py +23 -0
  14. package/adapter/scripts/debugger.py +1 -0
  15. package/lang_support/__init__.py +23 -0
  16. package/lang_support/rust.py +87 -0
  17. package/lldb/bin/lldb +0 -0
  18. package/lldb/bin/lldb-argdumper +0 -0
  19. package/lldb/bin/lldb-server +0 -0
  20. package/lldb/lib/liblldb.so +4 -0
  21. package/lldb/lib/libpython312.so +0 -0
  22. package/lldb/lib/lldb-python/lldb/__init__.py +19655 -0
  23. package/lldb/lib/lldb-python/lldb/embedded_interpreter.py +97 -0
  24. package/lldb/lib/lldb-python/lldb/formatters/Logger.py +133 -0
  25. package/lldb/lib/lldb-python/lldb/formatters/__init__.py +11 -0
  26. package/lldb/lib/lldb-python/lldb/formatters/attrib_fromdict.py +41 -0
  27. package/lldb/lib/lldb-python/lldb/formatters/cache.py +35 -0
  28. package/lldb/lib/lldb-python/lldb/formatters/cpp/__init__.py +11 -0
  29. package/lldb/lib/lldb-python/lldb/formatters/cpp/gnu_libstdcpp.py +939 -0
  30. package/lldb/lib/lldb-python/lldb/formatters/cpp/libcxx.py +987 -0
  31. package/lldb/lib/lldb-python/lldb/formatters/metrics.py +119 -0
  32. package/lldb/lib/lldb-python/lldb/formatters/synth.py +59 -0
  33. package/lldb/lib/lldb-python/lldb/lldb-argdumper +0 -0
  34. package/lldb/lib/lldb-python/lldb/native/__init__.py +11 -0
  35. package/lldb/lib/lldb-python/lldb/plugins/__init__.py +11 -0
  36. package/lldb/lib/lldb-python/lldb/plugins/operating_system.py +103 -0
  37. package/lldb/lib/lldb-python/lldb/plugins/parsed_cmd.py +463 -0
  38. package/lldb/lib/lldb-python/lldb/plugins/scripted_frame_provider.py +188 -0
  39. package/lldb/lib/lldb-python/lldb/plugins/scripted_platform.py +96 -0
  40. package/lldb/lib/lldb-python/lldb/plugins/scripted_process.py +1475 -0
  41. package/lldb/lib/lldb-python/lldb/plugins/scripted_thread_plan.py +70 -0
  42. package/lldb/lib/lldb-python/lldb/utils/__init__.py +11 -0
  43. package/lldb/lib/lldb-python/lldb/utils/in_call_stack.py +24 -0
  44. package/lldb/lib/lldb-python/lldb/utils/symbolication.py +810 -0
  45. package/lldb/lib/python3.12/__future__.py +147 -0
  46. package/lldb/lib/python3.12/__hello__.py +16 -0
  47. package/lldb/lib/python3.12/__phello__/__init__.py +7 -0
  48. package/lldb/lib/python3.12/__phello__/spam.py +7 -0
  49. package/lldb/lib/python3.12/_aix_support.py +108 -0
  50. package/lldb/lib/python3.12/_collections_abc.py +1173 -0
  51. package/lldb/lib/python3.12/_compat_pickle.py +252 -0
  52. package/lldb/lib/python3.12/_compression.py +162 -0
  53. package/lldb/lib/python3.12/_markupbase.py +396 -0
  54. package/lldb/lib/python3.12/_osx_support.py +579 -0
  55. package/lldb/lib/python3.12/_py_abc.py +147 -0
  56. package/lldb/lib/python3.12/_pydatetime.py +2645 -0
  57. package/lldb/lib/python3.12/_pydecimal.py +6339 -0
  58. package/lldb/lib/python3.12/_pyio.py +2698 -0
  59. package/lldb/lib/python3.12/_pylong.py +329 -0
  60. package/lldb/lib/python3.12/_sitebuiltins.py +103 -0
  61. package/lldb/lib/python3.12/_strptime.py +565 -0
  62. package/lldb/lib/python3.12/_sysconfigdata__linux_aarch64-linux-gnu.py +1230 -0
  63. package/lldb/lib/python3.12/_threading_local.py +242 -0
  64. package/lldb/lib/python3.12/_weakrefset.py +205 -0
  65. package/lldb/lib/python3.12/abc.py +188 -0
  66. package/lldb/lib/python3.12/aifc.py +984 -0
  67. package/lldb/lib/python3.12/antigravity.py +17 -0
  68. package/lldb/lib/python3.12/argparse.py +2672 -0
  69. package/lldb/lib/python3.12/ast.py +1835 -0
  70. package/lldb/lib/python3.12/asyncio/__init__.py +47 -0
  71. package/lldb/lib/python3.12/asyncio/__main__.py +126 -0
  72. package/lldb/lib/python3.12/asyncio/base_events.py +2011 -0
  73. package/lldb/lib/python3.12/asyncio/base_futures.py +67 -0
  74. package/lldb/lib/python3.12/asyncio/base_subprocess.py +285 -0
  75. package/lldb/lib/python3.12/asyncio/base_tasks.py +94 -0
  76. package/lldb/lib/python3.12/asyncio/constants.py +41 -0
  77. package/lldb/lib/python3.12/asyncio/coroutines.py +109 -0
  78. package/lldb/lib/python3.12/asyncio/events.py +868 -0
  79. package/lldb/lib/python3.12/asyncio/exceptions.py +62 -0
  80. package/lldb/lib/python3.12/asyncio/format_helpers.py +76 -0
  81. package/lldb/lib/python3.12/asyncio/futures.py +432 -0
  82. package/lldb/lib/python3.12/asyncio/locks.py +586 -0
  83. package/lldb/lib/python3.12/asyncio/log.py +7 -0
  84. package/lldb/lib/python3.12/asyncio/mixins.py +21 -0
  85. package/lldb/lib/python3.12/asyncio/proactor_events.py +897 -0
  86. package/lldb/lib/python3.12/asyncio/protocols.py +216 -0
  87. package/lldb/lib/python3.12/asyncio/queues.py +244 -0
  88. package/lldb/lib/python3.12/asyncio/runners.py +215 -0
  89. package/lldb/lib/python3.12/asyncio/selector_events.py +1321 -0
  90. package/lldb/lib/python3.12/asyncio/sslproto.py +926 -0
  91. package/lldb/lib/python3.12/asyncio/staggered.py +138 -0
  92. package/lldb/lib/python3.12/asyncio/streams.py +770 -0
  93. package/lldb/lib/python3.12/asyncio/subprocess.py +229 -0
  94. package/lldb/lib/python3.12/asyncio/taskgroups.py +240 -0
  95. package/lldb/lib/python3.12/asyncio/tasks.py +1065 -0
  96. package/lldb/lib/python3.12/asyncio/threads.py +25 -0
  97. package/lldb/lib/python3.12/asyncio/timeouts.py +168 -0
  98. package/lldb/lib/python3.12/asyncio/transports.py +335 -0
  99. package/lldb/lib/python3.12/asyncio/trsock.py +98 -0
  100. package/lldb/lib/python3.12/asyncio/unix_events.py +1500 -0
  101. package/lldb/lib/python3.12/asyncio/windows_events.py +901 -0
  102. package/lldb/lib/python3.12/asyncio/windows_utils.py +173 -0
  103. package/lldb/lib/python3.12/base64.py +586 -0
  104. package/lldb/lib/python3.12/bdb.py +899 -0
  105. package/lldb/lib/python3.12/bisect.py +118 -0
  106. package/lldb/lib/python3.12/bz2.py +344 -0
  107. package/lldb/lib/python3.12/cProfile.py +195 -0
  108. package/lldb/lib/python3.12/calendar.py +798 -0
  109. package/lldb/lib/python3.12/cgi.py +1013 -0
  110. package/lldb/lib/python3.12/cgitb.py +332 -0
  111. package/lldb/lib/python3.12/chunk.py +173 -0
  112. package/lldb/lib/python3.12/cmd.py +401 -0
  113. package/lldb/lib/python3.12/code.py +324 -0
  114. package/lldb/lib/python3.12/codecs.py +1129 -0
  115. package/lldb/lib/python3.12/codeop.py +161 -0
  116. package/lldb/lib/python3.12/collections/__init__.py +1592 -0
  117. package/lldb/lib/python3.12/collections/abc.py +3 -0
  118. package/lldb/lib/python3.12/colorsys.py +166 -0
  119. package/lldb/lib/python3.12/compileall.py +469 -0
  120. package/lldb/lib/python3.12/concurrent/__init__.py +1 -0
  121. package/lldb/lib/python3.12/concurrent/futures/__init__.py +54 -0
  122. package/lldb/lib/python3.12/concurrent/futures/_base.py +654 -0
  123. package/lldb/lib/python3.12/concurrent/futures/process.py +884 -0
  124. package/lldb/lib/python3.12/concurrent/futures/thread.py +239 -0
  125. package/lldb/lib/python3.12/configparser.py +1333 -0
  126. package/lldb/lib/python3.12/contextlib.py +800 -0
  127. package/lldb/lib/python3.12/contextvars.py +4 -0
  128. package/lldb/lib/python3.12/copy.py +292 -0
  129. package/lldb/lib/python3.12/copyreg.py +217 -0
  130. package/lldb/lib/python3.12/crypt.py +124 -0
  131. package/lldb/lib/python3.12/csv.py +451 -0
  132. package/lldb/lib/python3.12/ctypes/__init__.py +582 -0
  133. package/lldb/lib/python3.12/ctypes/_aix.py +327 -0
  134. package/lldb/lib/python3.12/ctypes/_endian.py +78 -0
  135. package/lldb/lib/python3.12/ctypes/macholib/__init__.py +9 -0
  136. package/lldb/lib/python3.12/ctypes/macholib/dyld.py +165 -0
  137. package/lldb/lib/python3.12/ctypes/macholib/dylib.py +42 -0
  138. package/lldb/lib/python3.12/ctypes/macholib/framework.py +42 -0
  139. package/lldb/lib/python3.12/ctypes/util.py +379 -0
  140. package/lldb/lib/python3.12/ctypes/wintypes.py +202 -0
  141. package/lldb/lib/python3.12/dataclasses.py +1588 -0
  142. package/lldb/lib/python3.12/datetime.py +9 -0
  143. package/lldb/lib/python3.12/dbm/__init__.py +190 -0
  144. package/lldb/lib/python3.12/dbm/dumb.py +317 -0
  145. package/lldb/lib/python3.12/dbm/gnu.py +3 -0
  146. package/lldb/lib/python3.12/dbm/ndbm.py +3 -0
  147. package/lldb/lib/python3.12/decimal.py +108 -0
  148. package/lldb/lib/python3.12/difflib.py +2056 -0
  149. package/lldb/lib/python3.12/dis.py +805 -0
  150. package/lldb/lib/python3.12/doctest.py +2845 -0
  151. package/lldb/lib/python3.12/email/__init__.py +61 -0
  152. package/lldb/lib/python3.12/email/_encoded_words.py +233 -0
  153. package/lldb/lib/python3.12/email/_header_value_parser.py +3078 -0
  154. package/lldb/lib/python3.12/email/_parseaddr.py +557 -0
  155. package/lldb/lib/python3.12/email/_policybase.py +382 -0
  156. package/lldb/lib/python3.12/email/base64mime.py +115 -0
  157. package/lldb/lib/python3.12/email/charset.py +398 -0
  158. package/lldb/lib/python3.12/email/contentmanager.py +251 -0
  159. package/lldb/lib/python3.12/email/encoders.py +65 -0
  160. package/lldb/lib/python3.12/email/errors.py +117 -0
  161. package/lldb/lib/python3.12/email/feedparser.py +534 -0
  162. package/lldb/lib/python3.12/email/generator.py +520 -0
  163. package/lldb/lib/python3.12/email/header.py +573 -0
  164. package/lldb/lib/python3.12/email/headerregistry.py +604 -0
  165. package/lldb/lib/python3.12/email/iterators.py +68 -0
  166. package/lldb/lib/python3.12/email/message.py +1205 -0
  167. package/lldb/lib/python3.12/email/mime/__init__.py +0 -0
  168. package/lldb/lib/python3.12/email/mime/application.py +37 -0
  169. package/lldb/lib/python3.12/email/mime/audio.py +100 -0
  170. package/lldb/lib/python3.12/email/mime/base.py +29 -0
  171. package/lldb/lib/python3.12/email/mime/image.py +152 -0
  172. package/lldb/lib/python3.12/email/mime/message.py +33 -0
  173. package/lldb/lib/python3.12/email/mime/multipart.py +47 -0
  174. package/lldb/lib/python3.12/email/mime/nonmultipart.py +21 -0
  175. package/lldb/lib/python3.12/email/mime/text.py +40 -0
  176. package/lldb/lib/python3.12/email/parser.py +127 -0
  177. package/lldb/lib/python3.12/email/policy.py +232 -0
  178. package/lldb/lib/python3.12/email/quoprimime.py +300 -0
  179. package/lldb/lib/python3.12/email/utils.py +486 -0
  180. package/lldb/lib/python3.12/encodings/__init__.py +174 -0
  181. package/lldb/lib/python3.12/encodings/aliases.py +551 -0
  182. package/lldb/lib/python3.12/encodings/ascii.py +50 -0
  183. package/lldb/lib/python3.12/encodings/base64_codec.py +55 -0
  184. package/lldb/lib/python3.12/encodings/big5.py +39 -0
  185. package/lldb/lib/python3.12/encodings/big5hkscs.py +39 -0
  186. package/lldb/lib/python3.12/encodings/bz2_codec.py +78 -0
  187. package/lldb/lib/python3.12/encodings/charmap.py +69 -0
  188. package/lldb/lib/python3.12/encodings/cp037.py +307 -0
  189. package/lldb/lib/python3.12/encodings/cp1006.py +307 -0
  190. package/lldb/lib/python3.12/encodings/cp1026.py +307 -0
  191. package/lldb/lib/python3.12/encodings/cp1125.py +698 -0
  192. package/lldb/lib/python3.12/encodings/cp1140.py +307 -0
  193. package/lldb/lib/python3.12/encodings/cp1250.py +307 -0
  194. package/lldb/lib/python3.12/encodings/cp1251.py +307 -0
  195. package/lldb/lib/python3.12/encodings/cp1252.py +307 -0
  196. package/lldb/lib/python3.12/encodings/cp1253.py +307 -0
  197. package/lldb/lib/python3.12/encodings/cp1254.py +307 -0
  198. package/lldb/lib/python3.12/encodings/cp1255.py +307 -0
  199. package/lldb/lib/python3.12/encodings/cp1256.py +307 -0
  200. package/lldb/lib/python3.12/encodings/cp1257.py +307 -0
  201. package/lldb/lib/python3.12/encodings/cp1258.py +307 -0
  202. package/lldb/lib/python3.12/encodings/cp273.py +307 -0
  203. package/lldb/lib/python3.12/encodings/cp424.py +307 -0
  204. package/lldb/lib/python3.12/encodings/cp437.py +698 -0
  205. package/lldb/lib/python3.12/encodings/cp500.py +307 -0
  206. package/lldb/lib/python3.12/encodings/cp720.py +309 -0
  207. package/lldb/lib/python3.12/encodings/cp737.py +698 -0
  208. package/lldb/lib/python3.12/encodings/cp775.py +697 -0
  209. package/lldb/lib/python3.12/encodings/cp850.py +698 -0
  210. package/lldb/lib/python3.12/encodings/cp852.py +698 -0
  211. package/lldb/lib/python3.12/encodings/cp855.py +698 -0
  212. package/lldb/lib/python3.12/encodings/cp856.py +307 -0
  213. package/lldb/lib/python3.12/encodings/cp857.py +694 -0
  214. package/lldb/lib/python3.12/encodings/cp858.py +698 -0
  215. package/lldb/lib/python3.12/encodings/cp860.py +698 -0
  216. package/lldb/lib/python3.12/encodings/cp861.py +698 -0
  217. package/lldb/lib/python3.12/encodings/cp862.py +698 -0
  218. package/lldb/lib/python3.12/encodings/cp863.py +698 -0
  219. package/lldb/lib/python3.12/encodings/cp864.py +690 -0
  220. package/lldb/lib/python3.12/encodings/cp865.py +698 -0
  221. package/lldb/lib/python3.12/encodings/cp866.py +698 -0
  222. package/lldb/lib/python3.12/encodings/cp869.py +689 -0
  223. package/lldb/lib/python3.12/encodings/cp874.py +307 -0
  224. package/lldb/lib/python3.12/encodings/cp875.py +307 -0
  225. package/lldb/lib/python3.12/encodings/cp932.py +39 -0
  226. package/lldb/lib/python3.12/encodings/cp949.py +39 -0
  227. package/lldb/lib/python3.12/encodings/cp950.py +39 -0
  228. package/lldb/lib/python3.12/encodings/euc_jis_2004.py +39 -0
  229. package/lldb/lib/python3.12/encodings/euc_jisx0213.py +39 -0
  230. package/lldb/lib/python3.12/encodings/euc_jp.py +39 -0
  231. package/lldb/lib/python3.12/encodings/euc_kr.py +39 -0
  232. package/lldb/lib/python3.12/encodings/gb18030.py +39 -0
  233. package/lldb/lib/python3.12/encodings/gb2312.py +39 -0
  234. package/lldb/lib/python3.12/encodings/gbk.py +39 -0
  235. package/lldb/lib/python3.12/encodings/hex_codec.py +55 -0
  236. package/lldb/lib/python3.12/encodings/hp_roman8.py +314 -0
  237. package/lldb/lib/python3.12/encodings/hz.py +39 -0
  238. package/lldb/lib/python3.12/encodings/idna.py +317 -0
  239. package/lldb/lib/python3.12/encodings/iso2022_jp.py +39 -0
  240. package/lldb/lib/python3.12/encodings/iso2022_jp_1.py +39 -0
  241. package/lldb/lib/python3.12/encodings/iso2022_jp_2.py +39 -0
  242. package/lldb/lib/python3.12/encodings/iso2022_jp_2004.py +39 -0
  243. package/lldb/lib/python3.12/encodings/iso2022_jp_3.py +39 -0
  244. package/lldb/lib/python3.12/encodings/iso2022_jp_ext.py +39 -0
  245. package/lldb/lib/python3.12/encodings/iso2022_kr.py +39 -0
  246. package/lldb/lib/python3.12/encodings/iso8859_1.py +307 -0
  247. package/lldb/lib/python3.12/encodings/iso8859_10.py +307 -0
  248. package/lldb/lib/python3.12/encodings/iso8859_11.py +307 -0
  249. package/lldb/lib/python3.12/encodings/iso8859_13.py +307 -0
  250. package/lldb/lib/python3.12/encodings/iso8859_14.py +307 -0
  251. package/lldb/lib/python3.12/encodings/iso8859_15.py +307 -0
  252. package/lldb/lib/python3.12/encodings/iso8859_16.py +307 -0
  253. package/lldb/lib/python3.12/encodings/iso8859_2.py +307 -0
  254. package/lldb/lib/python3.12/encodings/iso8859_3.py +307 -0
  255. package/lldb/lib/python3.12/encodings/iso8859_4.py +307 -0
  256. package/lldb/lib/python3.12/encodings/iso8859_5.py +307 -0
  257. package/lldb/lib/python3.12/encodings/iso8859_6.py +307 -0
  258. package/lldb/lib/python3.12/encodings/iso8859_7.py +307 -0
  259. package/lldb/lib/python3.12/encodings/iso8859_8.py +307 -0
  260. package/lldb/lib/python3.12/encodings/iso8859_9.py +307 -0
  261. package/lldb/lib/python3.12/encodings/johab.py +39 -0
  262. package/lldb/lib/python3.12/encodings/koi8_r.py +307 -0
  263. package/lldb/lib/python3.12/encodings/koi8_t.py +308 -0
  264. package/lldb/lib/python3.12/encodings/koi8_u.py +307 -0
  265. package/lldb/lib/python3.12/encodings/kz1048.py +307 -0
  266. package/lldb/lib/python3.12/encodings/latin_1.py +50 -0
  267. package/lldb/lib/python3.12/encodings/mac_arabic.py +698 -0
  268. package/lldb/lib/python3.12/encodings/mac_croatian.py +307 -0
  269. package/lldb/lib/python3.12/encodings/mac_cyrillic.py +307 -0
  270. package/lldb/lib/python3.12/encodings/mac_farsi.py +307 -0
  271. package/lldb/lib/python3.12/encodings/mac_greek.py +307 -0
  272. package/lldb/lib/python3.12/encodings/mac_iceland.py +307 -0
  273. package/lldb/lib/python3.12/encodings/mac_latin2.py +312 -0
  274. package/lldb/lib/python3.12/encodings/mac_roman.py +307 -0
  275. package/lldb/lib/python3.12/encodings/mac_romanian.py +307 -0
  276. package/lldb/lib/python3.12/encodings/mac_turkish.py +307 -0
  277. package/lldb/lib/python3.12/encodings/mbcs.py +47 -0
  278. package/lldb/lib/python3.12/encodings/oem.py +41 -0
  279. package/lldb/lib/python3.12/encodings/palmos.py +308 -0
  280. package/lldb/lib/python3.12/encodings/ptcp154.py +312 -0
  281. package/lldb/lib/python3.12/encodings/punycode.py +237 -0
  282. package/lldb/lib/python3.12/encodings/quopri_codec.py +56 -0
  283. package/lldb/lib/python3.12/encodings/raw_unicode_escape.py +46 -0
  284. package/lldb/lib/python3.12/encodings/rot_13.py +113 -0
  285. package/lldb/lib/python3.12/encodings/shift_jis.py +39 -0
  286. package/lldb/lib/python3.12/encodings/shift_jis_2004.py +39 -0
  287. package/lldb/lib/python3.12/encodings/shift_jisx0213.py +39 -0
  288. package/lldb/lib/python3.12/encodings/tis_620.py +307 -0
  289. package/lldb/lib/python3.12/encodings/undefined.py +49 -0
  290. package/lldb/lib/python3.12/encodings/unicode_escape.py +46 -0
  291. package/lldb/lib/python3.12/encodings/utf_16.py +155 -0
  292. package/lldb/lib/python3.12/encodings/utf_16_be.py +42 -0
  293. package/lldb/lib/python3.12/encodings/utf_16_le.py +42 -0
  294. package/lldb/lib/python3.12/encodings/utf_32.py +150 -0
  295. package/lldb/lib/python3.12/encodings/utf_32_be.py +37 -0
  296. package/lldb/lib/python3.12/encodings/utf_32_le.py +37 -0
  297. package/lldb/lib/python3.12/encodings/utf_7.py +38 -0
  298. package/lldb/lib/python3.12/encodings/utf_8.py +42 -0
  299. package/lldb/lib/python3.12/encodings/utf_8_sig.py +130 -0
  300. package/lldb/lib/python3.12/encodings/uu_codec.py +103 -0
  301. package/lldb/lib/python3.12/encodings/zlib_codec.py +77 -0
  302. package/lldb/lib/python3.12/ensurepip/__init__.py +291 -0
  303. package/lldb/lib/python3.12/ensurepip/__main__.py +5 -0
  304. package/lldb/lib/python3.12/ensurepip/_uninstall.py +31 -0
  305. package/lldb/lib/python3.12/enum.py +2109 -0
  306. package/lldb/lib/python3.12/filecmp.py +315 -0
  307. package/lldb/lib/python3.12/fileinput.py +442 -0
  308. package/lldb/lib/python3.12/fnmatch.py +185 -0
  309. package/lldb/lib/python3.12/fractions.py +990 -0
  310. package/lldb/lib/python3.12/ftplib.py +966 -0
  311. package/lldb/lib/python3.12/functools.py +1004 -0
  312. package/lldb/lib/python3.12/genericpath.py +167 -0
  313. package/lldb/lib/python3.12/getopt.py +215 -0
  314. package/lldb/lib/python3.12/getpass.py +185 -0
  315. package/lldb/lib/python3.12/gettext.py +646 -0
  316. package/lldb/lib/python3.12/glob.py +252 -0
  317. package/lldb/lib/python3.12/graphlib.py +250 -0
  318. package/lldb/lib/python3.12/gzip.py +694 -0
  319. package/lldb/lib/python3.12/hashlib.py +253 -0
  320. package/lldb/lib/python3.12/heapq.py +603 -0
  321. package/lldb/lib/python3.12/hmac.py +219 -0
  322. package/lldb/lib/python3.12/html/__init__.py +132 -0
  323. package/lldb/lib/python3.12/html/entities.py +2513 -0
  324. package/lldb/lib/python3.12/html/parser.py +456 -0
  325. package/lldb/lib/python3.12/http/__init__.py +200 -0
  326. package/lldb/lib/python3.12/http/client.py +1548 -0
  327. package/lldb/lib/python3.12/http/cookiejar.py +2121 -0
  328. package/lldb/lib/python3.12/http/cookies.py +594 -0
  329. package/lldb/lib/python3.12/http/server.py +1320 -0
  330. package/lldb/lib/python3.12/imaplib.py +1632 -0
  331. package/lldb/lib/python3.12/imghdr.py +180 -0
  332. package/lldb/lib/python3.12/importlib/__init__.py +138 -0
  333. package/lldb/lib/python3.12/importlib/_abc.py +39 -0
  334. package/lldb/lib/python3.12/importlib/_bootstrap.py +1551 -0
  335. package/lldb/lib/python3.12/importlib/_bootstrap_external.py +1745 -0
  336. package/lldb/lib/python3.12/importlib/abc.py +239 -0
  337. package/lldb/lib/python3.12/importlib/machinery.py +20 -0
  338. package/lldb/lib/python3.12/importlib/metadata/__init__.py +966 -0
  339. package/lldb/lib/python3.12/importlib/metadata/_adapters.py +89 -0
  340. package/lldb/lib/python3.12/importlib/metadata/_collections.py +30 -0
  341. package/lldb/lib/python3.12/importlib/metadata/_functools.py +104 -0
  342. package/lldb/lib/python3.12/importlib/metadata/_itertools.py +73 -0
  343. package/lldb/lib/python3.12/importlib/metadata/_meta.py +63 -0
  344. package/lldb/lib/python3.12/importlib/metadata/_text.py +99 -0
  345. package/lldb/lib/python3.12/importlib/readers.py +12 -0
  346. package/lldb/lib/python3.12/importlib/resources/__init__.py +36 -0
  347. package/lldb/lib/python3.12/importlib/resources/_adapters.py +168 -0
  348. package/lldb/lib/python3.12/importlib/resources/_common.py +207 -0
  349. package/lldb/lib/python3.12/importlib/resources/_itertools.py +38 -0
  350. package/lldb/lib/python3.12/importlib/resources/_legacy.py +120 -0
  351. package/lldb/lib/python3.12/importlib/resources/abc.py +173 -0
  352. package/lldb/lib/python3.12/importlib/resources/readers.py +146 -0
  353. package/lldb/lib/python3.12/importlib/resources/simple.py +106 -0
  354. package/lldb/lib/python3.12/importlib/simple.py +14 -0
  355. package/lldb/lib/python3.12/importlib/util.py +270 -0
  356. package/lldb/lib/python3.12/inspect.py +3426 -0
  357. package/lldb/lib/python3.12/io.py +99 -0
  358. package/lldb/lib/python3.12/ipaddress.py +2380 -0
  359. package/lldb/lib/python3.12/json/__init__.py +359 -0
  360. package/lldb/lib/python3.12/json/decoder.py +356 -0
  361. package/lldb/lib/python3.12/json/encoder.py +443 -0
  362. package/lldb/lib/python3.12/json/scanner.py +73 -0
  363. package/lldb/lib/python3.12/json/tool.py +85 -0
  364. package/lldb/lib/python3.12/keyword.py +64 -0
  365. package/lldb/lib/python3.12/linecache.py +182 -0
  366. package/lldb/lib/python3.12/locale.py +1779 -0
  367. package/lldb/lib/python3.12/logging/__init__.py +2345 -0
  368. package/lldb/lib/python3.12/logging/config.py +1078 -0
  369. package/lldb/lib/python3.12/logging/handlers.py +1608 -0
  370. package/lldb/lib/python3.12/lzma.py +356 -0
  371. package/lldb/lib/python3.12/mailbox.py +2153 -0
  372. package/lldb/lib/python3.12/mailcap.py +302 -0
  373. package/lldb/lib/python3.12/mimetypes.py +653 -0
  374. package/lldb/lib/python3.12/modulefinder.py +666 -0
  375. package/lldb/lib/python3.12/multiprocessing/__init__.py +37 -0
  376. package/lldb/lib/python3.12/multiprocessing/connection.py +1178 -0
  377. package/lldb/lib/python3.12/multiprocessing/context.py +377 -0
  378. package/lldb/lib/python3.12/multiprocessing/dummy/__init__.py +126 -0
  379. package/lldb/lib/python3.12/multiprocessing/dummy/connection.py +75 -0
  380. package/lldb/lib/python3.12/multiprocessing/forkserver.py +348 -0
  381. package/lldb/lib/python3.12/multiprocessing/heap.py +337 -0
  382. package/lldb/lib/python3.12/multiprocessing/managers.py +1380 -0
  383. package/lldb/lib/python3.12/multiprocessing/pool.py +957 -0
  384. package/lldb/lib/python3.12/multiprocessing/popen_fork.py +83 -0
  385. package/lldb/lib/python3.12/multiprocessing/popen_forkserver.py +74 -0
  386. package/lldb/lib/python3.12/multiprocessing/popen_spawn_posix.py +72 -0
  387. package/lldb/lib/python3.12/multiprocessing/popen_spawn_win32.py +145 -0
  388. package/lldb/lib/python3.12/multiprocessing/process.py +439 -0
  389. package/lldb/lib/python3.12/multiprocessing/queues.py +401 -0
  390. package/lldb/lib/python3.12/multiprocessing/reduction.py +281 -0
  391. package/lldb/lib/python3.12/multiprocessing/resource_sharer.py +154 -0
  392. package/lldb/lib/python3.12/multiprocessing/resource_tracker.py +269 -0
  393. package/lldb/lib/python3.12/multiprocessing/shared_memory.py +534 -0
  394. package/lldb/lib/python3.12/multiprocessing/sharedctypes.py +240 -0
  395. package/lldb/lib/python3.12/multiprocessing/spawn.py +307 -0
  396. package/lldb/lib/python3.12/multiprocessing/synchronize.py +404 -0
  397. package/lldb/lib/python3.12/multiprocessing/util.py +494 -0
  398. package/lldb/lib/python3.12/netrc.py +192 -0
  399. package/lldb/lib/python3.12/nntplib.py +1093 -0
  400. package/lldb/lib/python3.12/ntpath.py +889 -0
  401. package/lldb/lib/python3.12/nturl2path.py +81 -0
  402. package/lldb/lib/python3.12/numbers.py +418 -0
  403. package/lldb/lib/python3.12/opcode.py +493 -0
  404. package/lldb/lib/python3.12/operator.py +467 -0
  405. package/lldb/lib/python3.12/optparse.py +1681 -0
  406. package/lldb/lib/python3.12/os.py +1159 -0
  407. package/lldb/lib/python3.12/pathlib.py +1435 -0
  408. package/lldb/lib/python3.12/pdb.py +1987 -0
  409. package/lldb/lib/python3.12/pickle.py +1865 -0
  410. package/lldb/lib/python3.12/pickletools.py +2901 -0
  411. package/lldb/lib/python3.12/pipes.py +250 -0
  412. package/lldb/lib/python3.12/pkgutil.py +529 -0
  413. package/lldb/lib/python3.12/platform.py +1358 -0
  414. package/lldb/lib/python3.12/plistlib.py +911 -0
  415. package/lldb/lib/python3.12/poplib.py +467 -0
  416. package/lldb/lib/python3.12/posixpath.py +573 -0
  417. package/lldb/lib/python3.12/pprint.py +658 -0
  418. package/lldb/lib/python3.12/profile.py +615 -0
  419. package/lldb/lib/python3.12/pstats.py +778 -0
  420. package/lldb/lib/python3.12/pty.py +211 -0
  421. package/lldb/lib/python3.12/py_compile.py +212 -0
  422. package/lldb/lib/python3.12/pyclbr.py +314 -0
  423. package/lldb/lib/python3.12/pydoc.py +2941 -0
  424. package/lldb/lib/python3.12/pydoc_data/__init__.py +0 -0
  425. package/lldb/lib/python3.12/pydoc_data/topics.py +16777 -0
  426. package/lldb/lib/python3.12/queue.py +326 -0
  427. package/lldb/lib/python3.12/quopri.py +237 -0
  428. package/lldb/lib/python3.12/random.py +996 -0
  429. package/lldb/lib/python3.12/re/__init__.py +385 -0
  430. package/lldb/lib/python3.12/re/_casefix.py +106 -0
  431. package/lldb/lib/python3.12/re/_compiler.py +765 -0
  432. package/lldb/lib/python3.12/re/_constants.py +220 -0
  433. package/lldb/lib/python3.12/re/_parser.py +1080 -0
  434. package/lldb/lib/python3.12/reprlib.py +193 -0
  435. package/lldb/lib/python3.12/rlcompleter.py +219 -0
  436. package/lldb/lib/python3.12/runpy.py +319 -0
  437. package/lldb/lib/python3.12/sched.py +167 -0
  438. package/lldb/lib/python3.12/secrets.py +71 -0
  439. package/lldb/lib/python3.12/selectors.py +623 -0
  440. package/lldb/lib/python3.12/shelve.py +243 -0
  441. package/lldb/lib/python3.12/shlex.py +345 -0
  442. package/lldb/lib/python3.12/shutil.py +1566 -0
  443. package/lldb/lib/python3.12/signal.py +94 -0
  444. package/lldb/lib/python3.12/site-packages/pip/__init__.py +13 -0
  445. package/lldb/lib/python3.12/site-packages/pip/__main__.py +24 -0
  446. package/lldb/lib/python3.12/site-packages/pip/__pip-runner__.py +50 -0
  447. package/lldb/lib/python3.12/site-packages/pip/_internal/__init__.py +18 -0
  448. package/lldb/lib/python3.12/site-packages/pip/_internal/build_env.py +314 -0
  449. package/lldb/lib/python3.12/site-packages/pip/_internal/cache.py +290 -0
  450. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/__init__.py +4 -0
  451. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/autocompletion.py +176 -0
  452. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/base_command.py +234 -0
  453. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/cmdoptions.py +1074 -0
  454. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/command_context.py +27 -0
  455. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/index_command.py +172 -0
  456. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/main.py +80 -0
  457. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/main_parser.py +134 -0
  458. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/parser.py +294 -0
  459. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/progress_bars.py +94 -0
  460. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/req_command.py +329 -0
  461. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/spinners.py +159 -0
  462. package/lldb/lib/python3.12/site-packages/pip/_internal/cli/status_codes.py +6 -0
  463. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/__init__.py +132 -0
  464. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/cache.py +225 -0
  465. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/check.py +52 -0
  466. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/completion.py +130 -0
  467. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/configuration.py +280 -0
  468. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/debug.py +201 -0
  469. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/download.py +146 -0
  470. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/freeze.py +108 -0
  471. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/hash.py +59 -0
  472. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/help.py +41 -0
  473. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/index.py +139 -0
  474. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/inspect.py +92 -0
  475. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/install.py +777 -0
  476. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/list.py +375 -0
  477. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/search.py +172 -0
  478. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/show.py +217 -0
  479. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/uninstall.py +114 -0
  480. package/lldb/lib/python3.12/site-packages/pip/_internal/commands/wheel.py +182 -0
  481. package/lldb/lib/python3.12/site-packages/pip/_internal/configuration.py +383 -0
  482. package/lldb/lib/python3.12/site-packages/pip/_internal/distributions/__init__.py +21 -0
  483. package/lldb/lib/python3.12/site-packages/pip/_internal/distributions/base.py +53 -0
  484. package/lldb/lib/python3.12/site-packages/pip/_internal/distributions/installed.py +29 -0
  485. package/lldb/lib/python3.12/site-packages/pip/_internal/distributions/sdist.py +158 -0
  486. package/lldb/lib/python3.12/site-packages/pip/_internal/distributions/wheel.py +42 -0
  487. package/lldb/lib/python3.12/site-packages/pip/_internal/exceptions.py +777 -0
  488. package/lldb/lib/python3.12/site-packages/pip/_internal/index/__init__.py +2 -0
  489. package/lldb/lib/python3.12/site-packages/pip/_internal/index/collector.py +494 -0
  490. package/lldb/lib/python3.12/site-packages/pip/_internal/index/package_finder.py +1021 -0
  491. package/lldb/lib/python3.12/site-packages/pip/_internal/index/sources.py +285 -0
  492. package/lldb/lib/python3.12/site-packages/pip/_internal/locations/__init__.py +456 -0
  493. package/lldb/lib/python3.12/site-packages/pip/_internal/locations/_distutils.py +172 -0
  494. package/lldb/lib/python3.12/site-packages/pip/_internal/locations/_sysconfig.py +214 -0
  495. package/lldb/lib/python3.12/site-packages/pip/_internal/locations/base.py +81 -0
  496. package/lldb/lib/python3.12/site-packages/pip/_internal/main.py +12 -0
  497. package/lldb/lib/python3.12/site-packages/pip/_internal/metadata/__init__.py +128 -0
  498. package/lldb/lib/python3.12/site-packages/pip/_internal/metadata/_json.py +84 -0
  499. package/lldb/lib/python3.12/site-packages/pip/_internal/metadata/base.py +688 -0
  500. package/lldb/lib/python3.12/site-packages/pip/_internal/metadata/importlib/__init__.py +6 -0
  501. package/lldb/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_compat.py +55 -0
  502. package/lldb/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_dists.py +228 -0
  503. package/lldb/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py +189 -0
  504. package/lldb/lib/python3.12/site-packages/pip/_internal/metadata/pkg_resources.py +301 -0
  505. package/lldb/lib/python3.12/site-packages/pip/_internal/models/__init__.py +2 -0
  506. package/lldb/lib/python3.12/site-packages/pip/_internal/models/candidate.py +25 -0
  507. package/lldb/lib/python3.12/site-packages/pip/_internal/models/direct_url.py +224 -0
  508. package/lldb/lib/python3.12/site-packages/pip/_internal/models/format_control.py +78 -0
  509. package/lldb/lib/python3.12/site-packages/pip/_internal/models/index.py +28 -0
  510. package/lldb/lib/python3.12/site-packages/pip/_internal/models/installation_report.py +56 -0
  511. package/lldb/lib/python3.12/site-packages/pip/_internal/models/link.py +590 -0
  512. package/lldb/lib/python3.12/site-packages/pip/_internal/models/scheme.py +25 -0
  513. package/lldb/lib/python3.12/site-packages/pip/_internal/models/search_scope.py +127 -0
  514. package/lldb/lib/python3.12/site-packages/pip/_internal/models/selection_prefs.py +53 -0
  515. package/lldb/lib/python3.12/site-packages/pip/_internal/models/target_python.py +121 -0
  516. package/lldb/lib/python3.12/site-packages/pip/_internal/models/wheel.py +93 -0
  517. package/lldb/lib/python3.12/site-packages/pip/_internal/network/__init__.py +2 -0
  518. package/lldb/lib/python3.12/site-packages/pip/_internal/network/auth.py +562 -0
  519. package/lldb/lib/python3.12/site-packages/pip/_internal/network/cache.py +106 -0
  520. package/lldb/lib/python3.12/site-packages/pip/_internal/network/download.py +187 -0
  521. package/lldb/lib/python3.12/site-packages/pip/_internal/network/lazy_wheel.py +210 -0
  522. package/lldb/lib/python3.12/site-packages/pip/_internal/network/session.py +522 -0
  523. package/lldb/lib/python3.12/site-packages/pip/_internal/network/utils.py +96 -0
  524. package/lldb/lib/python3.12/site-packages/pip/_internal/network/xmlrpc.py +62 -0
  525. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/__init__.py +0 -0
  526. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/build/__init__.py +0 -0
  527. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/build/build_tracker.py +138 -0
  528. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/build/metadata.py +39 -0
  529. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/build/metadata_editable.py +41 -0
  530. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/build/metadata_legacy.py +74 -0
  531. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/build/wheel.py +37 -0
  532. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/build/wheel_editable.py +46 -0
  533. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/build/wheel_legacy.py +102 -0
  534. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/check.py +149 -0
  535. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/freeze.py +258 -0
  536. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/install/__init__.py +2 -0
  537. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/install/editable_legacy.py +47 -0
  538. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/install/wheel.py +735 -0
  539. package/lldb/lib/python3.12/site-packages/pip/_internal/operations/prepare.py +732 -0
  540. package/lldb/lib/python3.12/site-packages/pip/_internal/pyproject.py +179 -0
  541. package/lldb/lib/python3.12/site-packages/pip/_internal/req/__init__.py +90 -0
  542. package/lldb/lib/python3.12/site-packages/pip/_internal/req/constructors.py +560 -0
  543. package/lldb/lib/python3.12/site-packages/pip/_internal/req/req_file.py +551 -0
  544. package/lldb/lib/python3.12/site-packages/pip/_internal/req/req_install.py +918 -0
  545. package/lldb/lib/python3.12/site-packages/pip/_internal/req/req_set.py +82 -0
  546. package/lldb/lib/python3.12/site-packages/pip/_internal/req/req_uninstall.py +633 -0
  547. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/__init__.py +0 -0
  548. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/base.py +20 -0
  549. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/legacy/__init__.py +0 -0
  550. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/legacy/resolver.py +597 -0
  551. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/__init__.py +0 -0
  552. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/base.py +139 -0
  553. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py +569 -0
  554. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/factory.py +816 -0
  555. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py +174 -0
  556. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/provider.py +258 -0
  557. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/reporter.py +80 -0
  558. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/requirements.py +245 -0
  559. package/lldb/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/resolver.py +317 -0
  560. package/lldb/lib/python3.12/site-packages/pip/_internal/self_outdated_check.py +248 -0
  561. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/__init__.py +0 -0
  562. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/_jaraco_text.py +109 -0
  563. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/_log.py +38 -0
  564. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/appdirs.py +52 -0
  565. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/compat.py +79 -0
  566. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/compatibility_tags.py +165 -0
  567. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/datetime.py +11 -0
  568. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/deprecation.py +124 -0
  569. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/direct_url_helpers.py +87 -0
  570. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/egg_link.py +80 -0
  571. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/encoding.py +36 -0
  572. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/entrypoints.py +84 -0
  573. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/filesystem.py +153 -0
  574. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/filetypes.py +27 -0
  575. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/glibc.py +91 -0
  576. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/hashes.py +147 -0
  577. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/logging.py +347 -0
  578. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/misc.py +780 -0
  579. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/packaging.py +57 -0
  580. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/setuptools_build.py +146 -0
  581. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/subprocess.py +245 -0
  582. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/temp_dir.py +296 -0
  583. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/unpacking.py +337 -0
  584. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/urls.py +55 -0
  585. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/virtualenv.py +104 -0
  586. package/lldb/lib/python3.12/site-packages/pip/_internal/utils/wheel.py +134 -0
  587. package/lldb/lib/python3.12/site-packages/pip/_internal/vcs/__init__.py +15 -0
  588. package/lldb/lib/python3.12/site-packages/pip/_internal/vcs/bazaar.py +112 -0
  589. package/lldb/lib/python3.12/site-packages/pip/_internal/vcs/git.py +527 -0
  590. package/lldb/lib/python3.12/site-packages/pip/_internal/vcs/mercurial.py +163 -0
  591. package/lldb/lib/python3.12/site-packages/pip/_internal/vcs/subversion.py +324 -0
  592. package/lldb/lib/python3.12/site-packages/pip/_internal/vcs/versioncontrol.py +688 -0
  593. package/lldb/lib/python3.12/site-packages/pip/_internal/wheel_builder.py +354 -0
  594. package/lldb/lib/python3.12/site-packages/pip/_vendor/__init__.py +116 -0
  595. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/__init__.py +28 -0
  596. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/_cmd.py +70 -0
  597. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/adapter.py +161 -0
  598. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/cache.py +74 -0
  599. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/caches/__init__.py +8 -0
  600. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/caches/file_cache.py +182 -0
  601. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/caches/redis_cache.py +48 -0
  602. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/controller.py +499 -0
  603. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/filewrapper.py +119 -0
  604. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/heuristics.py +154 -0
  605. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/serialize.py +146 -0
  606. package/lldb/lib/python3.12/site-packages/pip/_vendor/cachecontrol/wrapper.py +43 -0
  607. package/lldb/lib/python3.12/site-packages/pip/_vendor/certifi/__init__.py +4 -0
  608. package/lldb/lib/python3.12/site-packages/pip/_vendor/certifi/__main__.py +12 -0
  609. package/lldb/lib/python3.12/site-packages/pip/_vendor/certifi/cacert.pem +4814 -0
  610. package/lldb/lib/python3.12/site-packages/pip/_vendor/certifi/core.py +114 -0
  611. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/__init__.py +33 -0
  612. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/compat.py +1138 -0
  613. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/database.py +1359 -0
  614. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/index.py +508 -0
  615. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/locators.py +1303 -0
  616. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/manifest.py +384 -0
  617. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/markers.py +167 -0
  618. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/metadata.py +1068 -0
  619. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/resources.py +358 -0
  620. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/scripts.py +466 -0
  621. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/t32.exe +0 -0
  622. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/t64-arm.exe +0 -0
  623. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/t64.exe +0 -0
  624. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/util.py +2025 -0
  625. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/version.py +751 -0
  626. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/w32.exe +0 -0
  627. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/w64-arm.exe +0 -0
  628. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/w64.exe +0 -0
  629. package/lldb/lib/python3.12/site-packages/pip/_vendor/distlib/wheel.py +1099 -0
  630. package/lldb/lib/python3.12/site-packages/pip/_vendor/distro/__init__.py +54 -0
  631. package/lldb/lib/python3.12/site-packages/pip/_vendor/distro/__main__.py +4 -0
  632. package/lldb/lib/python3.12/site-packages/pip/_vendor/distro/distro.py +1403 -0
  633. package/lldb/lib/python3.12/site-packages/pip/_vendor/idna/__init__.py +44 -0
  634. package/lldb/lib/python3.12/site-packages/pip/_vendor/idna/codec.py +118 -0
  635. package/lldb/lib/python3.12/site-packages/pip/_vendor/idna/compat.py +13 -0
  636. package/lldb/lib/python3.12/site-packages/pip/_vendor/idna/core.py +395 -0
  637. package/lldb/lib/python3.12/site-packages/pip/_vendor/idna/idnadata.py +4245 -0
  638. package/lldb/lib/python3.12/site-packages/pip/_vendor/idna/intranges.py +54 -0
  639. package/lldb/lib/python3.12/site-packages/pip/_vendor/idna/package_data.py +2 -0
  640. package/lldb/lib/python3.12/site-packages/pip/_vendor/idna/uts46data.py +8598 -0
  641. package/lldb/lib/python3.12/site-packages/pip/_vendor/msgpack/__init__.py +55 -0
  642. package/lldb/lib/python3.12/site-packages/pip/_vendor/msgpack/exceptions.py +48 -0
  643. package/lldb/lib/python3.12/site-packages/pip/_vendor/msgpack/ext.py +168 -0
  644. package/lldb/lib/python3.12/site-packages/pip/_vendor/msgpack/fallback.py +951 -0
  645. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/__init__.py +15 -0
  646. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/_elffile.py +110 -0
  647. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/_manylinux.py +262 -0
  648. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/_musllinux.py +85 -0
  649. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/_parser.py +354 -0
  650. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/_structures.py +61 -0
  651. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/_tokenizer.py +194 -0
  652. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/markers.py +325 -0
  653. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/metadata.py +804 -0
  654. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/requirements.py +91 -0
  655. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/specifiers.py +1009 -0
  656. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/tags.py +568 -0
  657. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/utils.py +174 -0
  658. package/lldb/lib/python3.12/site-packages/pip/_vendor/packaging/version.py +563 -0
  659. package/lldb/lib/python3.12/site-packages/pip/_vendor/pkg_resources/__init__.py +3325 -0
  660. package/lldb/lib/python3.12/site-packages/pip/_vendor/platformdirs/__init__.py +627 -0
  661. package/lldb/lib/python3.12/site-packages/pip/_vendor/platformdirs/__main__.py +55 -0
  662. package/lldb/lib/python3.12/site-packages/pip/_vendor/platformdirs/android.py +222 -0
  663. package/lldb/lib/python3.12/site-packages/pip/_vendor/platformdirs/api.py +292 -0
  664. package/lldb/lib/python3.12/site-packages/pip/_vendor/platformdirs/macos.py +130 -0
  665. package/lldb/lib/python3.12/site-packages/pip/_vendor/platformdirs/unix.py +275 -0
  666. package/lldb/lib/python3.12/site-packages/pip/_vendor/platformdirs/version.py +16 -0
  667. package/lldb/lib/python3.12/site-packages/pip/_vendor/platformdirs/windows.py +272 -0
  668. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/__init__.py +82 -0
  669. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/__main__.py +17 -0
  670. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/cmdline.py +668 -0
  671. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/console.py +70 -0
  672. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/filter.py +71 -0
  673. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/filters/__init__.py +940 -0
  674. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatter.py +124 -0
  675. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/__init__.py +158 -0
  676. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/_mapping.py +23 -0
  677. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/bbcode.py +108 -0
  678. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/groff.py +170 -0
  679. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/html.py +990 -0
  680. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/img.py +684 -0
  681. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/irc.py +154 -0
  682. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/latex.py +521 -0
  683. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/other.py +161 -0
  684. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/pangomarkup.py +83 -0
  685. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/rtf.py +146 -0
  686. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/svg.py +188 -0
  687. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/terminal.py +127 -0
  688. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/formatters/terminal256.py +338 -0
  689. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/lexer.py +961 -0
  690. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/lexers/__init__.py +363 -0
  691. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/lexers/_mapping.py +580 -0
  692. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/lexers/python.py +1198 -0
  693. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/modeline.py +43 -0
  694. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/plugin.py +88 -0
  695. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/regexopt.py +91 -0
  696. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/scanner.py +104 -0
  697. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/sphinxext.py +239 -0
  698. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/style.py +203 -0
  699. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/styles/__init__.py +61 -0
  700. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/styles/_mapping.py +53 -0
  701. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/token.py +214 -0
  702. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/unistring.py +153 -0
  703. package/lldb/lib/python3.12/site-packages/pip/_vendor/pygments/util.py +330 -0
  704. package/lldb/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/__init__.py +23 -0
  705. package/lldb/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_compat.py +8 -0
  706. package/lldb/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_impl.py +330 -0
  707. package/lldb/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/__init__.py +18 -0
  708. package/lldb/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py +353 -0
  709. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/__init__.py +179 -0
  710. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/__version__.py +14 -0
  711. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/_internal_utils.py +50 -0
  712. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/adapters.py +719 -0
  713. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/api.py +157 -0
  714. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/auth.py +314 -0
  715. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/certs.py +24 -0
  716. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/compat.py +78 -0
  717. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/cookies.py +561 -0
  718. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/exceptions.py +151 -0
  719. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/help.py +127 -0
  720. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/hooks.py +33 -0
  721. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/models.py +1037 -0
  722. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/packages.py +25 -0
  723. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/sessions.py +831 -0
  724. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/status_codes.py +128 -0
  725. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/structures.py +99 -0
  726. package/lldb/lib/python3.12/site-packages/pip/_vendor/requests/utils.py +1096 -0
  727. package/lldb/lib/python3.12/site-packages/pip/_vendor/resolvelib/__init__.py +26 -0
  728. package/lldb/lib/python3.12/site-packages/pip/_vendor/resolvelib/compat/__init__.py +0 -0
  729. package/lldb/lib/python3.12/site-packages/pip/_vendor/resolvelib/compat/collections_abc.py +6 -0
  730. package/lldb/lib/python3.12/site-packages/pip/_vendor/resolvelib/providers.py +133 -0
  731. package/lldb/lib/python3.12/site-packages/pip/_vendor/resolvelib/reporters.py +43 -0
  732. package/lldb/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py +547 -0
  733. package/lldb/lib/python3.12/site-packages/pip/_vendor/resolvelib/structs.py +170 -0
  734. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/__init__.py +177 -0
  735. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/__main__.py +273 -0
  736. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_cell_widths.py +454 -0
  737. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_emoji_codes.py +3610 -0
  738. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_emoji_replace.py +32 -0
  739. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_export_format.py +76 -0
  740. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_extension.py +10 -0
  741. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_fileno.py +24 -0
  742. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_inspect.py +270 -0
  743. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_log_render.py +94 -0
  744. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_loop.py +43 -0
  745. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_null_file.py +69 -0
  746. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_palettes.py +309 -0
  747. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_pick.py +17 -0
  748. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_ratio.py +159 -0
  749. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_spinners.py +482 -0
  750. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_stack.py +16 -0
  751. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_timer.py +19 -0
  752. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_win32_console.py +662 -0
  753. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_windows.py +71 -0
  754. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_windows_renderer.py +56 -0
  755. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/_wrap.py +93 -0
  756. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/abc.py +33 -0
  757. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/align.py +311 -0
  758. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/ansi.py +240 -0
  759. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/bar.py +93 -0
  760. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/box.py +480 -0
  761. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/cells.py +167 -0
  762. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/color.py +621 -0
  763. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/color_triplet.py +38 -0
  764. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/columns.py +187 -0
  765. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/console.py +2633 -0
  766. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/constrain.py +37 -0
  767. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/containers.py +167 -0
  768. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/control.py +225 -0
  769. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/default_styles.py +190 -0
  770. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/diagnose.py +37 -0
  771. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/emoji.py +96 -0
  772. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/errors.py +34 -0
  773. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/file_proxy.py +57 -0
  774. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/filesize.py +89 -0
  775. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/highlighter.py +232 -0
  776. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/json.py +139 -0
  777. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/jupyter.py +101 -0
  778. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/layout.py +442 -0
  779. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/live.py +375 -0
  780. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/live_render.py +112 -0
  781. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/logging.py +289 -0
  782. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/markup.py +251 -0
  783. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/measure.py +151 -0
  784. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/padding.py +141 -0
  785. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/pager.py +34 -0
  786. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/palette.py +100 -0
  787. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/panel.py +312 -0
  788. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/pretty.py +995 -0
  789. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/progress.py +1699 -0
  790. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/progress_bar.py +223 -0
  791. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/prompt.py +375 -0
  792. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/protocol.py +42 -0
  793. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/region.py +10 -0
  794. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/repr.py +149 -0
  795. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/rule.py +130 -0
  796. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/scope.py +86 -0
  797. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/screen.py +54 -0
  798. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/segment.py +738 -0
  799. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/spinner.py +137 -0
  800. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/status.py +131 -0
  801. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/style.py +796 -0
  802. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/styled.py +42 -0
  803. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/syntax.py +958 -0
  804. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/table.py +1000 -0
  805. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/terminal_theme.py +153 -0
  806. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/text.py +1357 -0
  807. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/theme.py +115 -0
  808. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/themes.py +5 -0
  809. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/traceback.py +753 -0
  810. package/lldb/lib/python3.12/site-packages/pip/_vendor/rich/tree.py +249 -0
  811. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/__init__.py +608 -0
  812. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/_asyncio.py +94 -0
  813. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/_utils.py +76 -0
  814. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/after.py +51 -0
  815. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/before.py +46 -0
  816. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/before_sleep.py +71 -0
  817. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/nap.py +43 -0
  818. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/retry.py +272 -0
  819. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/stop.py +103 -0
  820. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/tornadoweb.py +59 -0
  821. package/lldb/lib/python3.12/site-packages/pip/_vendor/tenacity/wait.py +228 -0
  822. package/lldb/lib/python3.12/site-packages/pip/_vendor/tomli/__init__.py +11 -0
  823. package/lldb/lib/python3.12/site-packages/pip/_vendor/tomli/_parser.py +691 -0
  824. package/lldb/lib/python3.12/site-packages/pip/_vendor/tomli/_re.py +107 -0
  825. package/lldb/lib/python3.12/site-packages/pip/_vendor/tomli/_types.py +10 -0
  826. package/lldb/lib/python3.12/site-packages/pip/_vendor/truststore/__init__.py +13 -0
  827. package/lldb/lib/python3.12/site-packages/pip/_vendor/truststore/_api.py +313 -0
  828. package/lldb/lib/python3.12/site-packages/pip/_vendor/truststore/_macos.py +499 -0
  829. package/lldb/lib/python3.12/site-packages/pip/_vendor/truststore/_openssl.py +66 -0
  830. package/lldb/lib/python3.12/site-packages/pip/_vendor/truststore/_ssl_constants.py +31 -0
  831. package/lldb/lib/python3.12/site-packages/pip/_vendor/truststore/_windows.py +564 -0
  832. package/lldb/lib/python3.12/site-packages/pip/_vendor/typing_extensions.py +3332 -0
  833. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/__init__.py +102 -0
  834. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/_collections.py +355 -0
  835. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/_version.py +2 -0
  836. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/connection.py +572 -0
  837. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/connectionpool.py +1137 -0
  838. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/contrib/__init__.py +0 -0
  839. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/contrib/_appengine_environ.py +36 -0
  840. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/contrib/_securetransport/__init__.py +0 -0
  841. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/contrib/_securetransport/bindings.py +519 -0
  842. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/contrib/_securetransport/low_level.py +397 -0
  843. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/contrib/appengine.py +314 -0
  844. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/contrib/ntlmpool.py +130 -0
  845. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.py +518 -0
  846. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/contrib/securetransport.py +920 -0
  847. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/contrib/socks.py +216 -0
  848. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/exceptions.py +323 -0
  849. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/fields.py +274 -0
  850. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/filepost.py +98 -0
  851. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/packages/__init__.py +0 -0
  852. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/packages/backports/__init__.py +0 -0
  853. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/packages/backports/makefile.py +51 -0
  854. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/packages/backports/weakref_finalize.py +155 -0
  855. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/packages/six.py +1076 -0
  856. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/poolmanager.py +540 -0
  857. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/request.py +191 -0
  858. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py +879 -0
  859. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/__init__.py +49 -0
  860. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/connection.py +149 -0
  861. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/proxy.py +57 -0
  862. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/queue.py +22 -0
  863. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/request.py +137 -0
  864. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/response.py +107 -0
  865. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/retry.py +620 -0
  866. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/ssl_.py +495 -0
  867. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/ssl_match_hostname.py +159 -0
  868. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/ssltransport.py +221 -0
  869. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/timeout.py +271 -0
  870. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/url.py +435 -0
  871. package/lldb/lib/python3.12/site-packages/pip/_vendor/urllib3/util/wait.py +152 -0
  872. package/lldb/lib/python3.12/site.py +692 -0
  873. package/lldb/lib/python3.12/smtplib.py +1109 -0
  874. package/lldb/lib/python3.12/sndhdr.py +271 -0
  875. package/lldb/lib/python3.12/socket.py +981 -0
  876. package/lldb/lib/python3.12/socketserver.py +858 -0
  877. package/lldb/lib/python3.12/sre_compile.py +7 -0
  878. package/lldb/lib/python3.12/sre_constants.py +7 -0
  879. package/lldb/lib/python3.12/sre_parse.py +7 -0
  880. package/lldb/lib/python3.12/ssl.py +1476 -0
  881. package/lldb/lib/python3.12/stat.py +195 -0
  882. package/lldb/lib/python3.12/statistics.py +1454 -0
  883. package/lldb/lib/python3.12/string.py +309 -0
  884. package/lldb/lib/python3.12/stringprep.py +272 -0
  885. package/lldb/lib/python3.12/struct.py +15 -0
  886. package/lldb/lib/python3.12/subprocess.py +2216 -0
  887. package/lldb/lib/python3.12/sunau.py +533 -0
  888. package/lldb/lib/python3.12/symtable.py +362 -0
  889. package/lldb/lib/python3.12/sysconfig.py +876 -0
  890. package/lldb/lib/python3.12/tabnanny.py +340 -0
  891. package/lldb/lib/python3.12/tarfile.py +2933 -0
  892. package/lldb/lib/python3.12/telnetlib.py +680 -0
  893. package/lldb/lib/python3.12/tempfile.py +952 -0
  894. package/lldb/lib/python3.12/textwrap.py +491 -0
  895. package/lldb/lib/python3.12/this.py +28 -0
  896. package/lldb/lib/python3.12/threading.py +1708 -0
  897. package/lldb/lib/python3.12/timeit.py +381 -0
  898. package/lldb/lib/python3.12/token.py +142 -0
  899. package/lldb/lib/python3.12/tokenize.py +586 -0
  900. package/lldb/lib/python3.12/tomllib/__init__.py +10 -0
  901. package/lldb/lib/python3.12/tomllib/_parser.py +691 -0
  902. package/lldb/lib/python3.12/tomllib/_re.py +107 -0
  903. package/lldb/lib/python3.12/tomllib/_types.py +10 -0
  904. package/lldb/lib/python3.12/trace.py +748 -0
  905. package/lldb/lib/python3.12/traceback.py +1187 -0
  906. package/lldb/lib/python3.12/tracemalloc.py +560 -0
  907. package/lldb/lib/python3.12/tty.py +73 -0
  908. package/lldb/lib/python3.12/turtle.py +4207 -0
  909. package/lldb/lib/python3.12/types.py +333 -0
  910. package/lldb/lib/python3.12/typing.py +3489 -0
  911. package/lldb/lib/python3.12/unittest/__init__.py +85 -0
  912. package/lldb/lib/python3.12/unittest/__main__.py +18 -0
  913. package/lldb/lib/python3.12/unittest/_log.py +86 -0
  914. package/lldb/lib/python3.12/unittest/async_case.py +142 -0
  915. package/lldb/lib/python3.12/unittest/case.py +1456 -0
  916. package/lldb/lib/python3.12/unittest/loader.py +497 -0
  917. package/lldb/lib/python3.12/unittest/main.py +291 -0
  918. package/lldb/lib/python3.12/unittest/mock.py +3045 -0
  919. package/lldb/lib/python3.12/unittest/result.py +256 -0
  920. package/lldb/lib/python3.12/unittest/runner.py +292 -0
  921. package/lldb/lib/python3.12/unittest/signals.py +71 -0
  922. package/lldb/lib/python3.12/unittest/suite.py +379 -0
  923. package/lldb/lib/python3.12/unittest/util.py +170 -0
  924. package/lldb/lib/python3.12/urllib/__init__.py +0 -0
  925. package/lldb/lib/python3.12/urllib/error.py +74 -0
  926. package/lldb/lib/python3.12/urllib/parse.py +1246 -0
  927. package/lldb/lib/python3.12/urllib/request.py +2796 -0
  928. package/lldb/lib/python3.12/urllib/response.py +84 -0
  929. package/lldb/lib/python3.12/urllib/robotparser.py +273 -0
  930. package/lldb/lib/python3.12/uu.py +216 -0
  931. package/lldb/lib/python3.12/uuid.py +793 -0
  932. package/lldb/lib/python3.12/warnings.py +598 -0
  933. package/lldb/lib/python3.12/wave.py +653 -0
  934. package/lldb/lib/python3.12/weakref.py +674 -0
  935. package/lldb/lib/python3.12/webbrowser.py +689 -0
  936. package/lldb/lib/python3.12/wsgiref/__init__.py +25 -0
  937. package/lldb/lib/python3.12/wsgiref/handlers.py +573 -0
  938. package/lldb/lib/python3.12/wsgiref/headers.py +184 -0
  939. package/lldb/lib/python3.12/wsgiref/simple_server.py +165 -0
  940. package/lldb/lib/python3.12/wsgiref/types.py +54 -0
  941. package/lldb/lib/python3.12/wsgiref/util.py +159 -0
  942. package/lldb/lib/python3.12/wsgiref/validate.py +438 -0
  943. package/lldb/lib/python3.12/xdrlib.py +242 -0
  944. package/lldb/lib/python3.12/xml/__init__.py +20 -0
  945. package/lldb/lib/python3.12/xml/dom/NodeFilter.py +27 -0
  946. package/lldb/lib/python3.12/xml/dom/__init__.py +140 -0
  947. package/lldb/lib/python3.12/xml/dom/domreg.py +99 -0
  948. package/lldb/lib/python3.12/xml/dom/expatbuilder.py +962 -0
  949. package/lldb/lib/python3.12/xml/dom/minicompat.py +109 -0
  950. package/lldb/lib/python3.12/xml/dom/minidom.py +2013 -0
  951. package/lldb/lib/python3.12/xml/dom/pulldom.py +336 -0
  952. package/lldb/lib/python3.12/xml/dom/xmlbuilder.py +387 -0
  953. package/lldb/lib/python3.12/xml/etree/ElementInclude.py +186 -0
  954. package/lldb/lib/python3.12/xml/etree/ElementPath.py +423 -0
  955. package/lldb/lib/python3.12/xml/etree/ElementTree.py +2085 -0
  956. package/lldb/lib/python3.12/xml/etree/__init__.py +33 -0
  957. package/lldb/lib/python3.12/xml/etree/cElementTree.py +3 -0
  958. package/lldb/lib/python3.12/xml/parsers/__init__.py +8 -0
  959. package/lldb/lib/python3.12/xml/parsers/expat.py +8 -0
  960. package/lldb/lib/python3.12/xml/sax/__init__.py +94 -0
  961. package/lldb/lib/python3.12/xml/sax/_exceptions.py +127 -0
  962. package/lldb/lib/python3.12/xml/sax/expatreader.py +454 -0
  963. package/lldb/lib/python3.12/xml/sax/handler.py +387 -0
  964. package/lldb/lib/python3.12/xml/sax/saxutils.py +369 -0
  965. package/lldb/lib/python3.12/xml/sax/xmlreader.py +378 -0
  966. package/lldb/lib/python3.12/xmlrpc/__init__.py +1 -0
  967. package/lldb/lib/python3.12/xmlrpc/client.py +1529 -0
  968. package/lldb/lib/python3.12/xmlrpc/server.py +1002 -0
  969. package/lldb/lib/python3.12/zipapp.py +206 -0
  970. package/lldb/lib/python3.12/zipfile/__init__.py +2314 -0
  971. package/lldb/lib/python3.12/zipfile/__main__.py +4 -0
  972. package/lldb/lib/python3.12/zipfile/_path/__init__.py +412 -0
  973. package/lldb/lib/python3.12/zipfile/_path/glob.py +53 -0
  974. package/lldb/lib/python3.12/zipimport.py +712 -0
  975. package/lldb/lib/python3.12/zoneinfo/__init__.py +31 -0
  976. package/lldb/lib/python3.12/zoneinfo/_common.py +164 -0
  977. package/lldb/lib/python3.12/zoneinfo/_tzpath.py +181 -0
  978. package/lldb/lib/python3.12/zoneinfo/_zoneinfo.py +772 -0
  979. package/package.json +28 -4
  980. package/version.json +4 -0
@@ -0,0 +1,3078 @@
1
+ """Header value parser implementing various email-related RFC parsing rules.
2
+
3
+ The parsing methods defined in this module implement various email related
4
+ parsing rules. Principal among them is RFC 5322, which is the followon
5
+ to RFC 2822 and primarily a clarification of the former. It also implements
6
+ RFC 2047 encoded word decoding.
7
+
8
+ RFC 5322 goes to considerable trouble to maintain backward compatibility with
9
+ RFC 822 in the parse phase, while cleaning up the structure on the generation
10
+ phase. This parser supports correct RFC 5322 generation by tagging white space
11
+ as folding white space only when folding is allowed in the non-obsolete rule
12
+ sets. Actually, the parser is even more generous when accepting input than RFC
13
+ 5322 mandates, following the spirit of Postel's Law, which RFC 5322 encourages.
14
+ Where possible deviations from the standard are annotated on the 'defects'
15
+ attribute of tokens that deviate.
16
+
17
+ The general structure of the parser follows RFC 5322, and uses its terminology
18
+ where there is a direct correspondence. Where the implementation requires a
19
+ somewhat different structure than that used by the formal grammar, new terms
20
+ that mimic the closest existing terms are used. Thus, it really helps to have
21
+ a copy of RFC 5322 handy when studying this code.
22
+
23
+ Input to the parser is a string that has already been unfolded according to
24
+ RFC 5322 rules. According to the RFC this unfolding is the very first step, and
25
+ this parser leaves the unfolding step to a higher level message parser, which
26
+ will have already detected the line breaks that need unfolding while
27
+ determining the beginning and end of each header.
28
+
29
+ The output of the parser is a TokenList object, which is a list subclass. A
30
+ TokenList is a recursive data structure. The terminal nodes of the structure
31
+ are Terminal objects, which are subclasses of str. These do not correspond
32
+ directly to terminal objects in the formal grammar, but are instead more
33
+ practical higher level combinations of true terminals.
34
+
35
+ All TokenList and Terminal objects have a 'value' attribute, which produces the
36
+ semantically meaningful value of that part of the parse subtree. The value of
37
+ all whitespace tokens (no matter how many sub-tokens they may contain) is a
38
+ single space, as per the RFC rules. This includes 'CFWS', which is herein
39
+ included in the general class of whitespace tokens. There is one exception to
40
+ the rule that whitespace tokens are collapsed into single spaces in values: in
41
+ the value of a 'bare-quoted-string' (a quoted-string with no leading or
42
+ trailing whitespace), any whitespace that appeared between the quotation marks
43
+ is preserved in the returned value. Note that in all Terminal strings quoted
44
+ pairs are turned into their unquoted values.
45
+
46
+ All TokenList and Terminal objects also have a string value, which attempts to
47
+ be a "canonical" representation of the RFC-compliant form of the substring that
48
+ produced the parsed subtree, including minimal use of quoted pair quoting.
49
+ Whitespace runs are not collapsed.
50
+
51
+ Comment tokens also have a 'content' attribute providing the string found
52
+ between the parens (including any nested comments) with whitespace preserved.
53
+
54
+ All TokenList and Terminal objects have a 'defects' attribute which is a
55
+ possibly empty list all of the defects found while creating the token. Defects
56
+ may appear on any token in the tree, and a composite list of all defects in the
57
+ subtree is available through the 'all_defects' attribute of any node. (For
58
+ Terminal notes x.defects == x.all_defects.)
59
+
60
+ Each object in a parse tree is called a 'token', and each has a 'token_type'
61
+ attribute that gives the name from the RFC 5322 grammar that it represents.
62
+ Not all RFC 5322 nodes are produced, and there is one non-RFC 5322 node that
63
+ may be produced: 'ptext'. A 'ptext' is a string of printable ascii characters.
64
+ It is returned in place of lists of (ctext/quoted-pair) and
65
+ (qtext/quoted-pair).
66
+
67
+ XXX: provide complete list of token types.
68
+ """
69
+
70
+ import re
71
+ import sys
72
+ import urllib # For urllib.parse.unquote
73
+ from string import hexdigits
74
+ from operator import itemgetter
75
+ from email import _encoded_words as _ew
76
+ from email import errors
77
+ from email import utils
78
+
79
+ #
80
+ # Useful constants and functions
81
+ #
82
+
83
+ WSP = set(' \t')
84
+ CFWS_LEADER = WSP | set('(')
85
+ SPECIALS = set(r'()<>@,:;.\"[]')
86
+ ATOM_ENDS = SPECIALS | WSP
87
+ DOT_ATOM_ENDS = ATOM_ENDS - set('.')
88
+ # '.', '"', and '(' do not end phrases in order to support obs-phrase
89
+ PHRASE_ENDS = SPECIALS - set('."(')
90
+ TSPECIALS = (SPECIALS | set('/?=')) - set('.')
91
+ TOKEN_ENDS = TSPECIALS | WSP
92
+ ASPECIALS = TSPECIALS | set("*'%")
93
+ ATTRIBUTE_ENDS = ASPECIALS | WSP
94
+ EXTENDED_ATTRIBUTE_ENDS = ATTRIBUTE_ENDS - set('%')
95
+ NLSET = {'\n', '\r'}
96
+ SPECIALSNL = SPECIALS | NLSET
97
+
98
+ def quote_string(value):
99
+ return '"'+str(value).replace('\\', '\\\\').replace('"', r'\"')+'"'
100
+
101
+ # Match a RFC 2047 word, looks like =?utf-8?q?someword?=
102
+ rfc2047_matcher = re.compile(r'''
103
+ =\? # literal =?
104
+ [^?]* # charset
105
+ \? # literal ?
106
+ [qQbB] # literal 'q' or 'b', case insensitive
107
+ \? # literal ?
108
+ .*? # encoded word
109
+ \?= # literal ?=
110
+ ''', re.VERBOSE | re.MULTILINE)
111
+
112
+
113
+ #
114
+ # TokenList and its subclasses
115
+ #
116
+
117
+ class TokenList(list):
118
+
119
+ token_type = None
120
+ syntactic_break = True
121
+ ew_combine_allowed = True
122
+
123
+ def __init__(self, *args, **kw):
124
+ super().__init__(*args, **kw)
125
+ self.defects = []
126
+
127
+ def __str__(self):
128
+ return ''.join(str(x) for x in self)
129
+
130
+ def __repr__(self):
131
+ return '{}({})'.format(self.__class__.__name__,
132
+ super().__repr__())
133
+
134
+ @property
135
+ def value(self):
136
+ return ''.join(x.value for x in self if x.value)
137
+
138
+ @property
139
+ def all_defects(self):
140
+ return sum((x.all_defects for x in self), self.defects)
141
+
142
+ def startswith_fws(self):
143
+ return self[0].startswith_fws()
144
+
145
+ @property
146
+ def as_ew_allowed(self):
147
+ """True if all top level tokens of this part may be RFC2047 encoded."""
148
+ return all(part.as_ew_allowed for part in self)
149
+
150
+ @property
151
+ def comments(self):
152
+ comments = []
153
+ for token in self:
154
+ comments.extend(token.comments)
155
+ return comments
156
+
157
+ def fold(self, *, policy):
158
+ return _refold_parse_tree(self, policy=policy)
159
+
160
+ def pprint(self, indent=''):
161
+ print(self.ppstr(indent=indent))
162
+
163
+ def ppstr(self, indent=''):
164
+ return '\n'.join(self._pp(indent=indent))
165
+
166
+ def _pp(self, indent=''):
167
+ yield '{}{}/{}('.format(
168
+ indent,
169
+ self.__class__.__name__,
170
+ self.token_type)
171
+ for token in self:
172
+ if not hasattr(token, '_pp'):
173
+ yield (indent + ' !! invalid element in token '
174
+ 'list: {!r}'.format(token))
175
+ else:
176
+ yield from token._pp(indent+' ')
177
+ if self.defects:
178
+ extra = ' Defects: {}'.format(self.defects)
179
+ else:
180
+ extra = ''
181
+ yield '{}){}'.format(indent, extra)
182
+
183
+
184
+ class WhiteSpaceTokenList(TokenList):
185
+
186
+ @property
187
+ def value(self):
188
+ return ' '
189
+
190
+ @property
191
+ def comments(self):
192
+ return [x.content for x in self if x.token_type=='comment']
193
+
194
+
195
+ class UnstructuredTokenList(TokenList):
196
+ token_type = 'unstructured'
197
+
198
+
199
+ class Phrase(TokenList):
200
+ token_type = 'phrase'
201
+
202
+ class Word(TokenList):
203
+ token_type = 'word'
204
+
205
+
206
+ class CFWSList(WhiteSpaceTokenList):
207
+ token_type = 'cfws'
208
+
209
+
210
+ class Atom(TokenList):
211
+ token_type = 'atom'
212
+
213
+
214
+ class Token(TokenList):
215
+ token_type = 'token'
216
+ encode_as_ew = False
217
+
218
+
219
+ class EncodedWord(TokenList):
220
+ token_type = 'encoded-word'
221
+ cte = None
222
+ charset = None
223
+ lang = None
224
+
225
+
226
+ class QuotedString(TokenList):
227
+
228
+ token_type = 'quoted-string'
229
+
230
+ @property
231
+ def content(self):
232
+ for x in self:
233
+ if x.token_type == 'bare-quoted-string':
234
+ return x.value
235
+
236
+ @property
237
+ def quoted_value(self):
238
+ res = []
239
+ for x in self:
240
+ if x.token_type == 'bare-quoted-string':
241
+ res.append(str(x))
242
+ else:
243
+ res.append(x.value)
244
+ return ''.join(res)
245
+
246
+ @property
247
+ def stripped_value(self):
248
+ for token in self:
249
+ if token.token_type == 'bare-quoted-string':
250
+ return token.value
251
+
252
+
253
+ class BareQuotedString(QuotedString):
254
+
255
+ token_type = 'bare-quoted-string'
256
+
257
+ def __str__(self):
258
+ return quote_string(''.join(str(x) for x in self))
259
+
260
+ @property
261
+ def value(self):
262
+ return ''.join(str(x) for x in self)
263
+
264
+
265
+ class Comment(WhiteSpaceTokenList):
266
+
267
+ token_type = 'comment'
268
+
269
+ def __str__(self):
270
+ return ''.join(sum([
271
+ ["("],
272
+ [self.quote(x) for x in self],
273
+ [")"],
274
+ ], []))
275
+
276
+ def quote(self, value):
277
+ if value.token_type == 'comment':
278
+ return str(value)
279
+ return str(value).replace('\\', '\\\\').replace(
280
+ '(', r'\(').replace(
281
+ ')', r'\)')
282
+
283
+ @property
284
+ def content(self):
285
+ return ''.join(str(x) for x in self)
286
+
287
+ @property
288
+ def comments(self):
289
+ return [self.content]
290
+
291
+ class AddressList(TokenList):
292
+
293
+ token_type = 'address-list'
294
+
295
+ @property
296
+ def addresses(self):
297
+ return [x for x in self if x.token_type=='address']
298
+
299
+ @property
300
+ def mailboxes(self):
301
+ return sum((x.mailboxes
302
+ for x in self if x.token_type=='address'), [])
303
+
304
+ @property
305
+ def all_mailboxes(self):
306
+ return sum((x.all_mailboxes
307
+ for x in self if x.token_type=='address'), [])
308
+
309
+
310
+ class Address(TokenList):
311
+
312
+ token_type = 'address'
313
+
314
+ @property
315
+ def display_name(self):
316
+ if self[0].token_type == 'group':
317
+ return self[0].display_name
318
+
319
+ @property
320
+ def mailboxes(self):
321
+ if self[0].token_type == 'mailbox':
322
+ return [self[0]]
323
+ elif self[0].token_type == 'invalid-mailbox':
324
+ return []
325
+ return self[0].mailboxes
326
+
327
+ @property
328
+ def all_mailboxes(self):
329
+ if self[0].token_type == 'mailbox':
330
+ return [self[0]]
331
+ elif self[0].token_type == 'invalid-mailbox':
332
+ return [self[0]]
333
+ return self[0].all_mailboxes
334
+
335
+ class MailboxList(TokenList):
336
+
337
+ token_type = 'mailbox-list'
338
+
339
+ @property
340
+ def mailboxes(self):
341
+ return [x for x in self if x.token_type=='mailbox']
342
+
343
+ @property
344
+ def all_mailboxes(self):
345
+ return [x for x in self
346
+ if x.token_type in ('mailbox', 'invalid-mailbox')]
347
+
348
+
349
+ class GroupList(TokenList):
350
+
351
+ token_type = 'group-list'
352
+
353
+ @property
354
+ def mailboxes(self):
355
+ if not self or self[0].token_type != 'mailbox-list':
356
+ return []
357
+ return self[0].mailboxes
358
+
359
+ @property
360
+ def all_mailboxes(self):
361
+ if not self or self[0].token_type != 'mailbox-list':
362
+ return []
363
+ return self[0].all_mailboxes
364
+
365
+
366
+ class Group(TokenList):
367
+
368
+ token_type = "group"
369
+
370
+ @property
371
+ def mailboxes(self):
372
+ if self[2].token_type != 'group-list':
373
+ return []
374
+ return self[2].mailboxes
375
+
376
+ @property
377
+ def all_mailboxes(self):
378
+ if self[2].token_type != 'group-list':
379
+ return []
380
+ return self[2].all_mailboxes
381
+
382
+ @property
383
+ def display_name(self):
384
+ return self[0].display_name
385
+
386
+
387
+ class NameAddr(TokenList):
388
+
389
+ token_type = 'name-addr'
390
+
391
+ @property
392
+ def display_name(self):
393
+ if len(self) == 1:
394
+ return None
395
+ return self[0].display_name
396
+
397
+ @property
398
+ def local_part(self):
399
+ return self[-1].local_part
400
+
401
+ @property
402
+ def domain(self):
403
+ return self[-1].domain
404
+
405
+ @property
406
+ def route(self):
407
+ return self[-1].route
408
+
409
+ @property
410
+ def addr_spec(self):
411
+ return self[-1].addr_spec
412
+
413
+
414
+ class AngleAddr(TokenList):
415
+
416
+ token_type = 'angle-addr'
417
+
418
+ @property
419
+ def local_part(self):
420
+ for x in self:
421
+ if x.token_type == 'addr-spec':
422
+ return x.local_part
423
+
424
+ @property
425
+ def domain(self):
426
+ for x in self:
427
+ if x.token_type == 'addr-spec':
428
+ return x.domain
429
+
430
+ @property
431
+ def route(self):
432
+ for x in self:
433
+ if x.token_type == 'obs-route':
434
+ return x.domains
435
+
436
+ @property
437
+ def addr_spec(self):
438
+ for x in self:
439
+ if x.token_type == 'addr-spec':
440
+ if x.local_part:
441
+ return x.addr_spec
442
+ else:
443
+ return quote_string(x.local_part) + x.addr_spec
444
+ else:
445
+ return '<>'
446
+
447
+
448
+ class ObsRoute(TokenList):
449
+
450
+ token_type = 'obs-route'
451
+
452
+ @property
453
+ def domains(self):
454
+ return [x.domain for x in self if x.token_type == 'domain']
455
+
456
+
457
+ class Mailbox(TokenList):
458
+
459
+ token_type = 'mailbox'
460
+
461
+ @property
462
+ def display_name(self):
463
+ if self[0].token_type == 'name-addr':
464
+ return self[0].display_name
465
+
466
+ @property
467
+ def local_part(self):
468
+ return self[0].local_part
469
+
470
+ @property
471
+ def domain(self):
472
+ return self[0].domain
473
+
474
+ @property
475
+ def route(self):
476
+ if self[0].token_type == 'name-addr':
477
+ return self[0].route
478
+
479
+ @property
480
+ def addr_spec(self):
481
+ return self[0].addr_spec
482
+
483
+
484
+ class InvalidMailbox(TokenList):
485
+
486
+ token_type = 'invalid-mailbox'
487
+
488
+ @property
489
+ def display_name(self):
490
+ return None
491
+
492
+ local_part = domain = route = addr_spec = display_name
493
+
494
+
495
+ class Domain(TokenList):
496
+
497
+ token_type = 'domain'
498
+ as_ew_allowed = False
499
+
500
+ @property
501
+ def domain(self):
502
+ return ''.join(super().value.split())
503
+
504
+
505
+ class DotAtom(TokenList):
506
+ token_type = 'dot-atom'
507
+
508
+
509
+ class DotAtomText(TokenList):
510
+ token_type = 'dot-atom-text'
511
+ as_ew_allowed = True
512
+
513
+
514
+ class NoFoldLiteral(TokenList):
515
+ token_type = 'no-fold-literal'
516
+ as_ew_allowed = False
517
+
518
+
519
+ class AddrSpec(TokenList):
520
+
521
+ token_type = 'addr-spec'
522
+ as_ew_allowed = False
523
+
524
+ @property
525
+ def local_part(self):
526
+ return self[0].local_part
527
+
528
+ @property
529
+ def domain(self):
530
+ if len(self) < 3:
531
+ return None
532
+ return self[-1].domain
533
+
534
+ @property
535
+ def value(self):
536
+ if len(self) < 3:
537
+ return self[0].value
538
+ return self[0].value.rstrip()+self[1].value+self[2].value.lstrip()
539
+
540
+ @property
541
+ def addr_spec(self):
542
+ nameset = set(self.local_part)
543
+ if len(nameset) > len(nameset-DOT_ATOM_ENDS):
544
+ lp = quote_string(self.local_part)
545
+ else:
546
+ lp = self.local_part
547
+ if self.domain is not None:
548
+ return lp + '@' + self.domain
549
+ return lp
550
+
551
+
552
+ class ObsLocalPart(TokenList):
553
+
554
+ token_type = 'obs-local-part'
555
+ as_ew_allowed = False
556
+
557
+
558
+ class DisplayName(Phrase):
559
+
560
+ token_type = 'display-name'
561
+ ew_combine_allowed = False
562
+
563
+ @property
564
+ def display_name(self):
565
+ res = TokenList(self)
566
+ if len(res) == 0:
567
+ return res.value
568
+ if res[0].token_type == 'cfws':
569
+ res.pop(0)
570
+ else:
571
+ if (isinstance(res[0], TokenList) and
572
+ res[0][0].token_type == 'cfws'):
573
+ res[0] = TokenList(res[0][1:])
574
+ if res[-1].token_type == 'cfws':
575
+ res.pop()
576
+ else:
577
+ if (isinstance(res[-1], TokenList) and
578
+ res[-1][-1].token_type == 'cfws'):
579
+ res[-1] = TokenList(res[-1][:-1])
580
+ return res.value
581
+
582
+ @property
583
+ def value(self):
584
+ quote = False
585
+ if self.defects:
586
+ quote = True
587
+ else:
588
+ for x in self:
589
+ if x.token_type == 'quoted-string':
590
+ quote = True
591
+ if len(self) != 0 and quote:
592
+ pre = post = ''
593
+ if (self[0].token_type == 'cfws' or
594
+ isinstance(self[0], TokenList) and
595
+ self[0][0].token_type == 'cfws'):
596
+ pre = ' '
597
+ if (self[-1].token_type == 'cfws' or
598
+ isinstance(self[-1], TokenList) and
599
+ self[-1][-1].token_type == 'cfws'):
600
+ post = ' '
601
+ return pre+quote_string(self.display_name)+post
602
+ else:
603
+ return super().value
604
+
605
+
606
+ class LocalPart(TokenList):
607
+
608
+ token_type = 'local-part'
609
+ as_ew_allowed = False
610
+
611
+ @property
612
+ def value(self):
613
+ if self[0].token_type == "quoted-string":
614
+ return self[0].quoted_value
615
+ else:
616
+ return self[0].value
617
+
618
+ @property
619
+ def local_part(self):
620
+ # Strip whitespace from front, back, and around dots.
621
+ res = [DOT]
622
+ last = DOT
623
+ last_is_tl = False
624
+ for tok in self[0] + [DOT]:
625
+ if tok.token_type == 'cfws':
626
+ continue
627
+ if (last_is_tl and tok.token_type == 'dot' and
628
+ last[-1].token_type == 'cfws'):
629
+ res[-1] = TokenList(last[:-1])
630
+ is_tl = isinstance(tok, TokenList)
631
+ if (is_tl and last.token_type == 'dot' and
632
+ tok[0].token_type == 'cfws'):
633
+ res.append(TokenList(tok[1:]))
634
+ else:
635
+ res.append(tok)
636
+ last = res[-1]
637
+ last_is_tl = is_tl
638
+ res = TokenList(res[1:-1])
639
+ return res.value
640
+
641
+
642
+ class DomainLiteral(TokenList):
643
+
644
+ token_type = 'domain-literal'
645
+ as_ew_allowed = False
646
+
647
+ @property
648
+ def domain(self):
649
+ return ''.join(super().value.split())
650
+
651
+ @property
652
+ def ip(self):
653
+ for x in self:
654
+ if x.token_type == 'ptext':
655
+ return x.value
656
+
657
+
658
+ class MIMEVersion(TokenList):
659
+
660
+ token_type = 'mime-version'
661
+ major = None
662
+ minor = None
663
+
664
+
665
+ class Parameter(TokenList):
666
+
667
+ token_type = 'parameter'
668
+ sectioned = False
669
+ extended = False
670
+ charset = 'us-ascii'
671
+
672
+ @property
673
+ def section_number(self):
674
+ # Because the first token, the attribute (name) eats CFWS, the second
675
+ # token is always the section if there is one.
676
+ return self[1].number if self.sectioned else 0
677
+
678
+ @property
679
+ def param_value(self):
680
+ # This is part of the "handle quoted extended parameters" hack.
681
+ for token in self:
682
+ if token.token_type == 'value':
683
+ return token.stripped_value
684
+ if token.token_type == 'quoted-string':
685
+ for token in token:
686
+ if token.token_type == 'bare-quoted-string':
687
+ for token in token:
688
+ if token.token_type == 'value':
689
+ return token.stripped_value
690
+ return ''
691
+
692
+
693
+ class InvalidParameter(Parameter):
694
+
695
+ token_type = 'invalid-parameter'
696
+
697
+
698
+ class Attribute(TokenList):
699
+
700
+ token_type = 'attribute'
701
+
702
+ @property
703
+ def stripped_value(self):
704
+ for token in self:
705
+ if token.token_type.endswith('attrtext'):
706
+ return token.value
707
+
708
+ class Section(TokenList):
709
+
710
+ token_type = 'section'
711
+ number = None
712
+
713
+
714
+ class Value(TokenList):
715
+
716
+ token_type = 'value'
717
+
718
+ @property
719
+ def stripped_value(self):
720
+ token = self[0]
721
+ if token.token_type == 'cfws':
722
+ token = self[1]
723
+ if token.token_type.endswith(
724
+ ('quoted-string', 'attribute', 'extended-attribute')):
725
+ return token.stripped_value
726
+ return self.value
727
+
728
+
729
+ class MimeParameters(TokenList):
730
+
731
+ token_type = 'mime-parameters'
732
+ syntactic_break = False
733
+
734
+ @property
735
+ def params(self):
736
+ # The RFC specifically states that the ordering of parameters is not
737
+ # guaranteed and may be reordered by the transport layer. So we have
738
+ # to assume the RFC 2231 pieces can come in any order. However, we
739
+ # output them in the order that we first see a given name, which gives
740
+ # us a stable __str__.
741
+ params = {} # Using order preserving dict from Python 3.7+
742
+ for token in self:
743
+ if not token.token_type.endswith('parameter'):
744
+ continue
745
+ if token[0].token_type != 'attribute':
746
+ continue
747
+ name = token[0].value.strip()
748
+ if name not in params:
749
+ params[name] = []
750
+ params[name].append((token.section_number, token))
751
+ for name, parts in params.items():
752
+ parts = sorted(parts, key=itemgetter(0))
753
+ first_param = parts[0][1]
754
+ charset = first_param.charset
755
+ # Our arbitrary error recovery is to ignore duplicate parameters,
756
+ # to use appearance order if there are duplicate rfc 2231 parts,
757
+ # and to ignore gaps. This mimics the error recovery of get_param.
758
+ if not first_param.extended and len(parts) > 1:
759
+ if parts[1][0] == 0:
760
+ parts[1][1].defects.append(errors.InvalidHeaderDefect(
761
+ 'duplicate parameter name; duplicate(s) ignored'))
762
+ parts = parts[:1]
763
+ # Else assume the *0* was missing...note that this is different
764
+ # from get_param, but we registered a defect for this earlier.
765
+ value_parts = []
766
+ i = 0
767
+ for section_number, param in parts:
768
+ if section_number != i:
769
+ # We could get fancier here and look for a complete
770
+ # duplicate extended parameter and ignore the second one
771
+ # seen. But we're not doing that. The old code didn't.
772
+ if not param.extended:
773
+ param.defects.append(errors.InvalidHeaderDefect(
774
+ 'duplicate parameter name; duplicate ignored'))
775
+ continue
776
+ else:
777
+ param.defects.append(errors.InvalidHeaderDefect(
778
+ "inconsistent RFC2231 parameter numbering"))
779
+ i += 1
780
+ value = param.param_value
781
+ if param.extended:
782
+ try:
783
+ value = urllib.parse.unquote_to_bytes(value)
784
+ except UnicodeEncodeError:
785
+ # source had surrogate escaped bytes. What we do now
786
+ # is a bit of an open question. I'm not sure this is
787
+ # the best choice, but it is what the old algorithm did
788
+ value = urllib.parse.unquote(value, encoding='latin-1')
789
+ else:
790
+ try:
791
+ value = value.decode(charset, 'surrogateescape')
792
+ except (LookupError, UnicodeEncodeError):
793
+ # XXX: there should really be a custom defect for
794
+ # unknown character set to make it easy to find,
795
+ # because otherwise unknown charset is a silent
796
+ # failure.
797
+ value = value.decode('us-ascii', 'surrogateescape')
798
+ if utils._has_surrogates(value):
799
+ param.defects.append(errors.UndecodableBytesDefect())
800
+ value_parts.append(value)
801
+ value = ''.join(value_parts)
802
+ yield name, value
803
+
804
+ def __str__(self):
805
+ params = []
806
+ for name, value in self.params:
807
+ if value:
808
+ params.append('{}={}'.format(name, quote_string(value)))
809
+ else:
810
+ params.append(name)
811
+ params = '; '.join(params)
812
+ return ' ' + params if params else ''
813
+
814
+
815
+ class ParameterizedHeaderValue(TokenList):
816
+
817
+ # Set this false so that the value doesn't wind up on a new line even
818
+ # if it and the parameters would fit there but not on the first line.
819
+ syntactic_break = False
820
+
821
+ @property
822
+ def params(self):
823
+ for token in reversed(self):
824
+ if token.token_type == 'mime-parameters':
825
+ return token.params
826
+ return {}
827
+
828
+
829
+ class ContentType(ParameterizedHeaderValue):
830
+ token_type = 'content-type'
831
+ as_ew_allowed = False
832
+ maintype = 'text'
833
+ subtype = 'plain'
834
+
835
+
836
+ class ContentDisposition(ParameterizedHeaderValue):
837
+ token_type = 'content-disposition'
838
+ as_ew_allowed = False
839
+ content_disposition = None
840
+
841
+
842
+ class ContentTransferEncoding(TokenList):
843
+ token_type = 'content-transfer-encoding'
844
+ as_ew_allowed = False
845
+ cte = '7bit'
846
+
847
+
848
+ class HeaderLabel(TokenList):
849
+ token_type = 'header-label'
850
+ as_ew_allowed = False
851
+
852
+
853
+ class MsgID(TokenList):
854
+ token_type = 'msg-id'
855
+ as_ew_allowed = False
856
+
857
+ def fold(self, policy):
858
+ # message-id tokens may not be folded.
859
+ return str(self) + policy.linesep
860
+
861
+
862
+ class MessageID(MsgID):
863
+ token_type = 'message-id'
864
+
865
+
866
+ class InvalidMessageID(MessageID):
867
+ token_type = 'invalid-message-id'
868
+
869
+
870
+ class Header(TokenList):
871
+ token_type = 'header'
872
+
873
+
874
+ #
875
+ # Terminal classes and instances
876
+ #
877
+
878
+ class Terminal(str):
879
+
880
+ as_ew_allowed = True
881
+ ew_combine_allowed = True
882
+ syntactic_break = True
883
+
884
+ def __new__(cls, value, token_type):
885
+ self = super().__new__(cls, value)
886
+ self.token_type = token_type
887
+ self.defects = []
888
+ return self
889
+
890
+ def __repr__(self):
891
+ return "{}({})".format(self.__class__.__name__, super().__repr__())
892
+
893
+ def pprint(self):
894
+ print(self.__class__.__name__ + '/' + self.token_type)
895
+
896
+ @property
897
+ def all_defects(self):
898
+ return list(self.defects)
899
+
900
+ def _pp(self, indent=''):
901
+ return ["{}{}/{}({}){}".format(
902
+ indent,
903
+ self.__class__.__name__,
904
+ self.token_type,
905
+ super().__repr__(),
906
+ '' if not self.defects else ' {}'.format(self.defects),
907
+ )]
908
+
909
+ def pop_trailing_ws(self):
910
+ # This terminates the recursion.
911
+ return None
912
+
913
+ @property
914
+ def comments(self):
915
+ return []
916
+
917
+ def __getnewargs__(self):
918
+ return(str(self), self.token_type)
919
+
920
+
921
+ class WhiteSpaceTerminal(Terminal):
922
+
923
+ @property
924
+ def value(self):
925
+ return ' '
926
+
927
+ def startswith_fws(self):
928
+ return True
929
+
930
+
931
+ class ValueTerminal(Terminal):
932
+
933
+ @property
934
+ def value(self):
935
+ return self
936
+
937
+ def startswith_fws(self):
938
+ return False
939
+
940
+
941
+ class EWWhiteSpaceTerminal(WhiteSpaceTerminal):
942
+
943
+ @property
944
+ def value(self):
945
+ return ''
946
+
947
+ def __str__(self):
948
+ return ''
949
+
950
+
951
+ class _InvalidEwError(errors.HeaderParseError):
952
+ """Invalid encoded word found while parsing headers."""
953
+
954
+
955
+ # XXX these need to become classes and used as instances so
956
+ # that a program can't change them in a parse tree and screw
957
+ # up other parse trees. Maybe should have tests for that, too.
958
+ DOT = ValueTerminal('.', 'dot')
959
+ ListSeparator = ValueTerminal(',', 'list-separator')
960
+ ListSeparator.as_ew_allowed = False
961
+ ListSeparator.syntactic_break = False
962
+ RouteComponentMarker = ValueTerminal('@', 'route-component-marker')
963
+
964
+ #
965
+ # Parser
966
+ #
967
+
968
+ # Parse strings according to RFC822/2047/2822/5322 rules.
969
+ #
970
+ # This is a stateless parser. Each get_XXX function accepts a string and
971
+ # returns either a Terminal or a TokenList representing the RFC object named
972
+ # by the method and a string containing the remaining unparsed characters
973
+ # from the input. Thus a parser method consumes the next syntactic construct
974
+ # of a given type and returns a token representing the construct plus the
975
+ # unparsed remainder of the input string.
976
+ #
977
+ # For example, if the first element of a structured header is a 'phrase',
978
+ # then:
979
+ #
980
+ # phrase, value = get_phrase(value)
981
+ #
982
+ # returns the complete phrase from the start of the string value, plus any
983
+ # characters left in the string after the phrase is removed.
984
+
985
+ _wsp_splitter = re.compile(r'([{}]+)'.format(''.join(WSP))).split
986
+ _non_atom_end_matcher = re.compile(r"[^{}]+".format(
987
+ re.escape(''.join(ATOM_ENDS)))).match
988
+ _non_printable_finder = re.compile(r"[\x00-\x20\x7F]").findall
989
+ _non_token_end_matcher = re.compile(r"[^{}]+".format(
990
+ re.escape(''.join(TOKEN_ENDS)))).match
991
+ _non_attribute_end_matcher = re.compile(r"[^{}]+".format(
992
+ re.escape(''.join(ATTRIBUTE_ENDS)))).match
993
+ _non_extended_attribute_end_matcher = re.compile(r"[^{}]+".format(
994
+ re.escape(''.join(EXTENDED_ATTRIBUTE_ENDS)))).match
995
+
996
+ def _validate_xtext(xtext):
997
+ """If input token contains ASCII non-printables, register a defect."""
998
+
999
+ non_printables = _non_printable_finder(xtext)
1000
+ if non_printables:
1001
+ xtext.defects.append(errors.NonPrintableDefect(non_printables))
1002
+ if utils._has_surrogates(xtext):
1003
+ xtext.defects.append(errors.UndecodableBytesDefect(
1004
+ "Non-ASCII characters found in header token"))
1005
+
1006
+ def _get_ptext_to_endchars(value, endchars):
1007
+ """Scan printables/quoted-pairs until endchars and return unquoted ptext.
1008
+
1009
+ This function turns a run of qcontent, ccontent-without-comments, or
1010
+ dtext-with-quoted-printables into a single string by unquoting any
1011
+ quoted printables. It returns the string, the remaining value, and
1012
+ a flag that is True iff there were any quoted printables decoded.
1013
+
1014
+ """
1015
+ fragment, *remainder = _wsp_splitter(value, 1)
1016
+ vchars = []
1017
+ escape = False
1018
+ had_qp = False
1019
+ for pos in range(len(fragment)):
1020
+ if fragment[pos] == '\\':
1021
+ if escape:
1022
+ escape = False
1023
+ had_qp = True
1024
+ else:
1025
+ escape = True
1026
+ continue
1027
+ if escape:
1028
+ escape = False
1029
+ elif fragment[pos] in endchars:
1030
+ break
1031
+ vchars.append(fragment[pos])
1032
+ else:
1033
+ pos = pos + 1
1034
+ return ''.join(vchars), ''.join([fragment[pos:]] + remainder), had_qp
1035
+
1036
+ def get_fws(value):
1037
+ """FWS = 1*WSP
1038
+
1039
+ This isn't the RFC definition. We're using fws to represent tokens where
1040
+ folding can be done, but when we are parsing the *un*folding has already
1041
+ been done so we don't need to watch out for CRLF.
1042
+
1043
+ """
1044
+ newvalue = value.lstrip()
1045
+ fws = WhiteSpaceTerminal(value[:len(value)-len(newvalue)], 'fws')
1046
+ return fws, newvalue
1047
+
1048
+ def get_encoded_word(value):
1049
+ """ encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
1050
+
1051
+ """
1052
+ ew = EncodedWord()
1053
+ if not value.startswith('=?'):
1054
+ raise errors.HeaderParseError(
1055
+ "expected encoded word but found {}".format(value))
1056
+ tok, *remainder = value[2:].split('?=', 1)
1057
+ if tok == value[2:]:
1058
+ raise errors.HeaderParseError(
1059
+ "expected encoded word but found {}".format(value))
1060
+ remstr = ''.join(remainder)
1061
+ if (len(remstr) > 1 and
1062
+ remstr[0] in hexdigits and
1063
+ remstr[1] in hexdigits and
1064
+ tok.count('?') < 2):
1065
+ # The ? after the CTE was followed by an encoded word escape (=XX).
1066
+ rest, *remainder = remstr.split('?=', 1)
1067
+ tok = tok + '?=' + rest
1068
+ if len(tok.split()) > 1:
1069
+ ew.defects.append(errors.InvalidHeaderDefect(
1070
+ "whitespace inside encoded word"))
1071
+ ew.cte = value
1072
+ value = ''.join(remainder)
1073
+ try:
1074
+ text, charset, lang, defects = _ew.decode('=?' + tok + '?=')
1075
+ except (ValueError, KeyError):
1076
+ raise _InvalidEwError(
1077
+ "encoded word format invalid: '{}'".format(ew.cte))
1078
+ ew.charset = charset
1079
+ ew.lang = lang
1080
+ ew.defects.extend(defects)
1081
+ while text:
1082
+ if text[0] in WSP:
1083
+ token, text = get_fws(text)
1084
+ ew.append(token)
1085
+ continue
1086
+ chars, *remainder = _wsp_splitter(text, 1)
1087
+ vtext = ValueTerminal(chars, 'vtext')
1088
+ _validate_xtext(vtext)
1089
+ ew.append(vtext)
1090
+ text = ''.join(remainder)
1091
+ # Encoded words should be followed by a WS
1092
+ if value and value[0] not in WSP:
1093
+ ew.defects.append(errors.InvalidHeaderDefect(
1094
+ "missing trailing whitespace after encoded-word"))
1095
+ return ew, value
1096
+
1097
+ def get_unstructured(value):
1098
+ """unstructured = (*([FWS] vchar) *WSP) / obs-unstruct
1099
+ obs-unstruct = *((*LF *CR *(obs-utext) *LF *CR)) / FWS)
1100
+ obs-utext = %d0 / obs-NO-WS-CTL / LF / CR
1101
+
1102
+ obs-NO-WS-CTL is control characters except WSP/CR/LF.
1103
+
1104
+ So, basically, we have printable runs, plus control characters or nulls in
1105
+ the obsolete syntax, separated by whitespace. Since RFC 2047 uses the
1106
+ obsolete syntax in its specification, but requires whitespace on either
1107
+ side of the encoded words, I can see no reason to need to separate the
1108
+ non-printable-non-whitespace from the printable runs if they occur, so we
1109
+ parse this into xtext tokens separated by WSP tokens.
1110
+
1111
+ Because an 'unstructured' value must by definition constitute the entire
1112
+ value, this 'get' routine does not return a remaining value, only the
1113
+ parsed TokenList.
1114
+
1115
+ """
1116
+ # XXX: but what about bare CR and LF? They might signal the start or
1117
+ # end of an encoded word. YAGNI for now, since our current parsers
1118
+ # will never send us strings with bare CR or LF.
1119
+
1120
+ unstructured = UnstructuredTokenList()
1121
+ while value:
1122
+ if value[0] in WSP:
1123
+ token, value = get_fws(value)
1124
+ unstructured.append(token)
1125
+ continue
1126
+ valid_ew = True
1127
+ if value.startswith('=?'):
1128
+ try:
1129
+ token, value = get_encoded_word(value)
1130
+ except _InvalidEwError:
1131
+ valid_ew = False
1132
+ except errors.HeaderParseError:
1133
+ # XXX: Need to figure out how to register defects when
1134
+ # appropriate here.
1135
+ pass
1136
+ else:
1137
+ have_ws = True
1138
+ if len(unstructured) > 0:
1139
+ if unstructured[-1].token_type != 'fws':
1140
+ unstructured.defects.append(errors.InvalidHeaderDefect(
1141
+ "missing whitespace before encoded word"))
1142
+ have_ws = False
1143
+ if have_ws and len(unstructured) > 1:
1144
+ if unstructured[-2].token_type == 'encoded-word':
1145
+ unstructured[-1] = EWWhiteSpaceTerminal(
1146
+ unstructured[-1], 'fws')
1147
+ unstructured.append(token)
1148
+ continue
1149
+ tok, *remainder = _wsp_splitter(value, 1)
1150
+ # Split in the middle of an atom if there is a rfc2047 encoded word
1151
+ # which does not have WSP on both sides. The defect will be registered
1152
+ # the next time through the loop.
1153
+ # This needs to only be performed when the encoded word is valid;
1154
+ # otherwise, performing it on an invalid encoded word can cause
1155
+ # the parser to go in an infinite loop.
1156
+ if valid_ew and rfc2047_matcher.search(tok):
1157
+ tok, *remainder = value.partition('=?')
1158
+ vtext = ValueTerminal(tok, 'vtext')
1159
+ _validate_xtext(vtext)
1160
+ unstructured.append(vtext)
1161
+ value = ''.join(remainder)
1162
+ return unstructured
1163
+
1164
+ def get_qp_ctext(value):
1165
+ r"""ctext = <printable ascii except \ ( )>
1166
+
1167
+ This is not the RFC ctext, since we are handling nested comments in comment
1168
+ and unquoting quoted-pairs here. We allow anything except the '()'
1169
+ characters, but if we find any ASCII other than the RFC defined printable
1170
+ ASCII, a NonPrintableDefect is added to the token's defects list. Since
1171
+ quoted pairs are converted to their unquoted values, what is returned is
1172
+ a 'ptext' token. In this case it is a WhiteSpaceTerminal, so it's value
1173
+ is ' '.
1174
+
1175
+ """
1176
+ ptext, value, _ = _get_ptext_to_endchars(value, '()')
1177
+ ptext = WhiteSpaceTerminal(ptext, 'ptext')
1178
+ _validate_xtext(ptext)
1179
+ return ptext, value
1180
+
1181
+ def get_qcontent(value):
1182
+ """qcontent = qtext / quoted-pair
1183
+
1184
+ We allow anything except the DQUOTE character, but if we find any ASCII
1185
+ other than the RFC defined printable ASCII, a NonPrintableDefect is
1186
+ added to the token's defects list. Any quoted pairs are converted to their
1187
+ unquoted values, so what is returned is a 'ptext' token. In this case it
1188
+ is a ValueTerminal.
1189
+
1190
+ """
1191
+ ptext, value, _ = _get_ptext_to_endchars(value, '"')
1192
+ ptext = ValueTerminal(ptext, 'ptext')
1193
+ _validate_xtext(ptext)
1194
+ return ptext, value
1195
+
1196
+ def get_atext(value):
1197
+ """atext = <matches _atext_matcher>
1198
+
1199
+ We allow any non-ATOM_ENDS in atext, but add an InvalidATextDefect to
1200
+ the token's defects list if we find non-atext characters.
1201
+ """
1202
+ m = _non_atom_end_matcher(value)
1203
+ if not m:
1204
+ raise errors.HeaderParseError(
1205
+ "expected atext but found '{}'".format(value))
1206
+ atext = m.group()
1207
+ value = value[len(atext):]
1208
+ atext = ValueTerminal(atext, 'atext')
1209
+ _validate_xtext(atext)
1210
+ return atext, value
1211
+
1212
+ def get_bare_quoted_string(value):
1213
+ """bare-quoted-string = DQUOTE *([FWS] qcontent) [FWS] DQUOTE
1214
+
1215
+ A quoted-string without the leading or trailing white space. Its
1216
+ value is the text between the quote marks, with whitespace
1217
+ preserved and quoted pairs decoded.
1218
+ """
1219
+ if not value or value[0] != '"':
1220
+ raise errors.HeaderParseError(
1221
+ "expected '\"' but found '{}'".format(value))
1222
+ bare_quoted_string = BareQuotedString()
1223
+ value = value[1:]
1224
+ if value and value[0] == '"':
1225
+ token, value = get_qcontent(value)
1226
+ bare_quoted_string.append(token)
1227
+ while value and value[0] != '"':
1228
+ if value[0] in WSP:
1229
+ token, value = get_fws(value)
1230
+ elif value[:2] == '=?':
1231
+ valid_ew = False
1232
+ try:
1233
+ token, value = get_encoded_word(value)
1234
+ bare_quoted_string.defects.append(errors.InvalidHeaderDefect(
1235
+ "encoded word inside quoted string"))
1236
+ valid_ew = True
1237
+ except errors.HeaderParseError:
1238
+ token, value = get_qcontent(value)
1239
+ # Collapse the whitespace between two encoded words that occur in a
1240
+ # bare-quoted-string.
1241
+ if valid_ew and len(bare_quoted_string) > 1:
1242
+ if (bare_quoted_string[-1].token_type == 'fws' and
1243
+ bare_quoted_string[-2].token_type == 'encoded-word'):
1244
+ bare_quoted_string[-1] = EWWhiteSpaceTerminal(
1245
+ bare_quoted_string[-1], 'fws')
1246
+ else:
1247
+ token, value = get_qcontent(value)
1248
+ bare_quoted_string.append(token)
1249
+ if not value:
1250
+ bare_quoted_string.defects.append(errors.InvalidHeaderDefect(
1251
+ "end of header inside quoted string"))
1252
+ return bare_quoted_string, value
1253
+ return bare_quoted_string, value[1:]
1254
+
1255
+ def get_comment(value):
1256
+ """comment = "(" *([FWS] ccontent) [FWS] ")"
1257
+ ccontent = ctext / quoted-pair / comment
1258
+
1259
+ We handle nested comments here, and quoted-pair in our qp-ctext routine.
1260
+ """
1261
+ if value and value[0] != '(':
1262
+ raise errors.HeaderParseError(
1263
+ "expected '(' but found '{}'".format(value))
1264
+ comment = Comment()
1265
+ value = value[1:]
1266
+ while value and value[0] != ")":
1267
+ if value[0] in WSP:
1268
+ token, value = get_fws(value)
1269
+ elif value[0] == '(':
1270
+ token, value = get_comment(value)
1271
+ else:
1272
+ token, value = get_qp_ctext(value)
1273
+ comment.append(token)
1274
+ if not value:
1275
+ comment.defects.append(errors.InvalidHeaderDefect(
1276
+ "end of header inside comment"))
1277
+ return comment, value
1278
+ return comment, value[1:]
1279
+
1280
+ def get_cfws(value):
1281
+ """CFWS = (1*([FWS] comment) [FWS]) / FWS
1282
+
1283
+ """
1284
+ cfws = CFWSList()
1285
+ while value and value[0] in CFWS_LEADER:
1286
+ if value[0] in WSP:
1287
+ token, value = get_fws(value)
1288
+ else:
1289
+ token, value = get_comment(value)
1290
+ cfws.append(token)
1291
+ return cfws, value
1292
+
1293
+ def get_quoted_string(value):
1294
+ """quoted-string = [CFWS] <bare-quoted-string> [CFWS]
1295
+
1296
+ 'bare-quoted-string' is an intermediate class defined by this
1297
+ parser and not by the RFC grammar. It is the quoted string
1298
+ without any attached CFWS.
1299
+ """
1300
+ quoted_string = QuotedString()
1301
+ if value and value[0] in CFWS_LEADER:
1302
+ token, value = get_cfws(value)
1303
+ quoted_string.append(token)
1304
+ token, value = get_bare_quoted_string(value)
1305
+ quoted_string.append(token)
1306
+ if value and value[0] in CFWS_LEADER:
1307
+ token, value = get_cfws(value)
1308
+ quoted_string.append(token)
1309
+ return quoted_string, value
1310
+
1311
+ def get_atom(value):
1312
+ """atom = [CFWS] 1*atext [CFWS]
1313
+
1314
+ An atom could be an rfc2047 encoded word.
1315
+ """
1316
+ atom = Atom()
1317
+ if value and value[0] in CFWS_LEADER:
1318
+ token, value = get_cfws(value)
1319
+ atom.append(token)
1320
+ if value and value[0] in ATOM_ENDS:
1321
+ raise errors.HeaderParseError(
1322
+ "expected atom but found '{}'".format(value))
1323
+ if value.startswith('=?'):
1324
+ try:
1325
+ token, value = get_encoded_word(value)
1326
+ except errors.HeaderParseError:
1327
+ # XXX: need to figure out how to register defects when
1328
+ # appropriate here.
1329
+ token, value = get_atext(value)
1330
+ else:
1331
+ token, value = get_atext(value)
1332
+ atom.append(token)
1333
+ if value and value[0] in CFWS_LEADER:
1334
+ token, value = get_cfws(value)
1335
+ atom.append(token)
1336
+ return atom, value
1337
+
1338
+ def get_dot_atom_text(value):
1339
+ """ dot-text = 1*atext *("." 1*atext)
1340
+
1341
+ """
1342
+ dot_atom_text = DotAtomText()
1343
+ if not value or value[0] in ATOM_ENDS:
1344
+ raise errors.HeaderParseError("expected atom at a start of "
1345
+ "dot-atom-text but found '{}'".format(value))
1346
+ while value and value[0] not in ATOM_ENDS:
1347
+ token, value = get_atext(value)
1348
+ dot_atom_text.append(token)
1349
+ if value and value[0] == '.':
1350
+ dot_atom_text.append(DOT)
1351
+ value = value[1:]
1352
+ if dot_atom_text[-1] is DOT:
1353
+ raise errors.HeaderParseError("expected atom at end of dot-atom-text "
1354
+ "but found '{}'".format('.'+value))
1355
+ return dot_atom_text, value
1356
+
1357
+ def get_dot_atom(value):
1358
+ """ dot-atom = [CFWS] dot-atom-text [CFWS]
1359
+
1360
+ Any place we can have a dot atom, we could instead have an rfc2047 encoded
1361
+ word.
1362
+ """
1363
+ dot_atom = DotAtom()
1364
+ if value[0] in CFWS_LEADER:
1365
+ token, value = get_cfws(value)
1366
+ dot_atom.append(token)
1367
+ if value.startswith('=?'):
1368
+ try:
1369
+ token, value = get_encoded_word(value)
1370
+ except errors.HeaderParseError:
1371
+ # XXX: need to figure out how to register defects when
1372
+ # appropriate here.
1373
+ token, value = get_dot_atom_text(value)
1374
+ else:
1375
+ token, value = get_dot_atom_text(value)
1376
+ dot_atom.append(token)
1377
+ if value and value[0] in CFWS_LEADER:
1378
+ token, value = get_cfws(value)
1379
+ dot_atom.append(token)
1380
+ return dot_atom, value
1381
+
1382
+ def get_word(value):
1383
+ """word = atom / quoted-string
1384
+
1385
+ Either atom or quoted-string may start with CFWS. We have to peel off this
1386
+ CFWS first to determine which type of word to parse. Afterward we splice
1387
+ the leading CFWS, if any, into the parsed sub-token.
1388
+
1389
+ If neither an atom or a quoted-string is found before the next special, a
1390
+ HeaderParseError is raised.
1391
+
1392
+ The token returned is either an Atom or a QuotedString, as appropriate.
1393
+ This means the 'word' level of the formal grammar is not represented in the
1394
+ parse tree; this is because having that extra layer when manipulating the
1395
+ parse tree is more confusing than it is helpful.
1396
+
1397
+ """
1398
+ if value[0] in CFWS_LEADER:
1399
+ leader, value = get_cfws(value)
1400
+ else:
1401
+ leader = None
1402
+ if not value:
1403
+ raise errors.HeaderParseError(
1404
+ "Expected 'atom' or 'quoted-string' but found nothing.")
1405
+ if value[0]=='"':
1406
+ token, value = get_quoted_string(value)
1407
+ elif value[0] in SPECIALS:
1408
+ raise errors.HeaderParseError("Expected 'atom' or 'quoted-string' "
1409
+ "but found '{}'".format(value))
1410
+ else:
1411
+ token, value = get_atom(value)
1412
+ if leader is not None:
1413
+ token[:0] = [leader]
1414
+ return token, value
1415
+
1416
+ def get_phrase(value):
1417
+ """ phrase = 1*word / obs-phrase
1418
+ obs-phrase = word *(word / "." / CFWS)
1419
+
1420
+ This means a phrase can be a sequence of words, periods, and CFWS in any
1421
+ order as long as it starts with at least one word. If anything other than
1422
+ words is detected, an ObsoleteHeaderDefect is added to the token's defect
1423
+ list. We also accept a phrase that starts with CFWS followed by a dot;
1424
+ this is registered as an InvalidHeaderDefect, since it is not supported by
1425
+ even the obsolete grammar.
1426
+
1427
+ """
1428
+ phrase = Phrase()
1429
+ try:
1430
+ token, value = get_word(value)
1431
+ phrase.append(token)
1432
+ except errors.HeaderParseError:
1433
+ phrase.defects.append(errors.InvalidHeaderDefect(
1434
+ "phrase does not start with word"))
1435
+ while value and value[0] not in PHRASE_ENDS:
1436
+ if value[0]=='.':
1437
+ phrase.append(DOT)
1438
+ phrase.defects.append(errors.ObsoleteHeaderDefect(
1439
+ "period in 'phrase'"))
1440
+ value = value[1:]
1441
+ else:
1442
+ try:
1443
+ token, value = get_word(value)
1444
+ except errors.HeaderParseError:
1445
+ if value[0] in CFWS_LEADER:
1446
+ token, value = get_cfws(value)
1447
+ phrase.defects.append(errors.ObsoleteHeaderDefect(
1448
+ "comment found without atom"))
1449
+ else:
1450
+ raise
1451
+ phrase.append(token)
1452
+ return phrase, value
1453
+
1454
+ def get_local_part(value):
1455
+ """ local-part = dot-atom / quoted-string / obs-local-part
1456
+
1457
+ """
1458
+ local_part = LocalPart()
1459
+ leader = None
1460
+ if value and value[0] in CFWS_LEADER:
1461
+ leader, value = get_cfws(value)
1462
+ if not value:
1463
+ raise errors.HeaderParseError(
1464
+ "expected local-part but found '{}'".format(value))
1465
+ try:
1466
+ token, value = get_dot_atom(value)
1467
+ except errors.HeaderParseError:
1468
+ try:
1469
+ token, value = get_word(value)
1470
+ except errors.HeaderParseError:
1471
+ if value[0] != '\\' and value[0] in PHRASE_ENDS:
1472
+ raise
1473
+ token = TokenList()
1474
+ if leader is not None:
1475
+ token[:0] = [leader]
1476
+ local_part.append(token)
1477
+ if value and (value[0]=='\\' or value[0] not in PHRASE_ENDS):
1478
+ obs_local_part, value = get_obs_local_part(str(local_part) + value)
1479
+ if obs_local_part.token_type == 'invalid-obs-local-part':
1480
+ local_part.defects.append(errors.InvalidHeaderDefect(
1481
+ "local-part is not dot-atom, quoted-string, or obs-local-part"))
1482
+ else:
1483
+ local_part.defects.append(errors.ObsoleteHeaderDefect(
1484
+ "local-part is not a dot-atom (contains CFWS)"))
1485
+ local_part[0] = obs_local_part
1486
+ try:
1487
+ local_part.value.encode('ascii')
1488
+ except UnicodeEncodeError:
1489
+ local_part.defects.append(errors.NonASCIILocalPartDefect(
1490
+ "local-part contains non-ASCII characters)"))
1491
+ return local_part, value
1492
+
1493
+ def get_obs_local_part(value):
1494
+ """ obs-local-part = word *("." word)
1495
+ """
1496
+ obs_local_part = ObsLocalPart()
1497
+ last_non_ws_was_dot = False
1498
+ while value and (value[0]=='\\' or value[0] not in PHRASE_ENDS):
1499
+ if value[0] == '.':
1500
+ if last_non_ws_was_dot:
1501
+ obs_local_part.defects.append(errors.InvalidHeaderDefect(
1502
+ "invalid repeated '.'"))
1503
+ obs_local_part.append(DOT)
1504
+ last_non_ws_was_dot = True
1505
+ value = value[1:]
1506
+ continue
1507
+ elif value[0]=='\\':
1508
+ obs_local_part.append(ValueTerminal(value[0],
1509
+ 'misplaced-special'))
1510
+ value = value[1:]
1511
+ obs_local_part.defects.append(errors.InvalidHeaderDefect(
1512
+ "'\\' character outside of quoted-string/ccontent"))
1513
+ last_non_ws_was_dot = False
1514
+ continue
1515
+ if obs_local_part and obs_local_part[-1].token_type != 'dot':
1516
+ obs_local_part.defects.append(errors.InvalidHeaderDefect(
1517
+ "missing '.' between words"))
1518
+ try:
1519
+ token, value = get_word(value)
1520
+ last_non_ws_was_dot = False
1521
+ except errors.HeaderParseError:
1522
+ if value[0] not in CFWS_LEADER:
1523
+ raise
1524
+ token, value = get_cfws(value)
1525
+ obs_local_part.append(token)
1526
+ if not obs_local_part:
1527
+ raise errors.HeaderParseError(
1528
+ "expected obs-local-part but found '{}'".format(value))
1529
+ if (obs_local_part[0].token_type == 'dot' or
1530
+ obs_local_part[0].token_type=='cfws' and
1531
+ len(obs_local_part) > 1 and
1532
+ obs_local_part[1].token_type=='dot'):
1533
+ obs_local_part.defects.append(errors.InvalidHeaderDefect(
1534
+ "Invalid leading '.' in local part"))
1535
+ if (obs_local_part[-1].token_type == 'dot' or
1536
+ obs_local_part[-1].token_type=='cfws' and
1537
+ len(obs_local_part) > 1 and
1538
+ obs_local_part[-2].token_type=='dot'):
1539
+ obs_local_part.defects.append(errors.InvalidHeaderDefect(
1540
+ "Invalid trailing '.' in local part"))
1541
+ if obs_local_part.defects:
1542
+ obs_local_part.token_type = 'invalid-obs-local-part'
1543
+ return obs_local_part, value
1544
+
1545
+ def get_dtext(value):
1546
+ r""" dtext = <printable ascii except \ [ ]> / obs-dtext
1547
+ obs-dtext = obs-NO-WS-CTL / quoted-pair
1548
+
1549
+ We allow anything except the excluded characters, but if we find any
1550
+ ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is
1551
+ added to the token's defects list. Quoted pairs are converted to their
1552
+ unquoted values, so what is returned is a ptext token, in this case a
1553
+ ValueTerminal. If there were quoted-printables, an ObsoleteHeaderDefect is
1554
+ added to the returned token's defect list.
1555
+
1556
+ """
1557
+ ptext, value, had_qp = _get_ptext_to_endchars(value, '[]')
1558
+ ptext = ValueTerminal(ptext, 'ptext')
1559
+ if had_qp:
1560
+ ptext.defects.append(errors.ObsoleteHeaderDefect(
1561
+ "quoted printable found in domain-literal"))
1562
+ _validate_xtext(ptext)
1563
+ return ptext, value
1564
+
1565
+ def _check_for_early_dl_end(value, domain_literal):
1566
+ if value:
1567
+ return False
1568
+ domain_literal.append(errors.InvalidHeaderDefect(
1569
+ "end of input inside domain-literal"))
1570
+ domain_literal.append(ValueTerminal(']', 'domain-literal-end'))
1571
+ return True
1572
+
1573
+ def get_domain_literal(value):
1574
+ """ domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
1575
+
1576
+ """
1577
+ domain_literal = DomainLiteral()
1578
+ if value[0] in CFWS_LEADER:
1579
+ token, value = get_cfws(value)
1580
+ domain_literal.append(token)
1581
+ if not value:
1582
+ raise errors.HeaderParseError("expected domain-literal")
1583
+ if value[0] != '[':
1584
+ raise errors.HeaderParseError("expected '[' at start of domain-literal "
1585
+ "but found '{}'".format(value))
1586
+ value = value[1:]
1587
+ if _check_for_early_dl_end(value, domain_literal):
1588
+ return domain_literal, value
1589
+ domain_literal.append(ValueTerminal('[', 'domain-literal-start'))
1590
+ if value[0] in WSP:
1591
+ token, value = get_fws(value)
1592
+ domain_literal.append(token)
1593
+ token, value = get_dtext(value)
1594
+ domain_literal.append(token)
1595
+ if _check_for_early_dl_end(value, domain_literal):
1596
+ return domain_literal, value
1597
+ if value[0] in WSP:
1598
+ token, value = get_fws(value)
1599
+ domain_literal.append(token)
1600
+ if _check_for_early_dl_end(value, domain_literal):
1601
+ return domain_literal, value
1602
+ if value[0] != ']':
1603
+ raise errors.HeaderParseError("expected ']' at end of domain-literal "
1604
+ "but found '{}'".format(value))
1605
+ domain_literal.append(ValueTerminal(']', 'domain-literal-end'))
1606
+ value = value[1:]
1607
+ if value and value[0] in CFWS_LEADER:
1608
+ token, value = get_cfws(value)
1609
+ domain_literal.append(token)
1610
+ return domain_literal, value
1611
+
1612
+ def get_domain(value):
1613
+ """ domain = dot-atom / domain-literal / obs-domain
1614
+ obs-domain = atom *("." atom))
1615
+
1616
+ """
1617
+ domain = Domain()
1618
+ leader = None
1619
+ if value and value[0] in CFWS_LEADER:
1620
+ leader, value = get_cfws(value)
1621
+ if not value:
1622
+ raise errors.HeaderParseError(
1623
+ "expected domain but found '{}'".format(value))
1624
+ if value[0] == '[':
1625
+ token, value = get_domain_literal(value)
1626
+ if leader is not None:
1627
+ token[:0] = [leader]
1628
+ domain.append(token)
1629
+ return domain, value
1630
+ try:
1631
+ token, value = get_dot_atom(value)
1632
+ except errors.HeaderParseError:
1633
+ token, value = get_atom(value)
1634
+ if value and value[0] == '@':
1635
+ raise errors.HeaderParseError('Invalid Domain')
1636
+ if leader is not None:
1637
+ token[:0] = [leader]
1638
+ domain.append(token)
1639
+ if value and value[0] == '.':
1640
+ domain.defects.append(errors.ObsoleteHeaderDefect(
1641
+ "domain is not a dot-atom (contains CFWS)"))
1642
+ if domain[0].token_type == 'dot-atom':
1643
+ domain[:] = domain[0]
1644
+ while value and value[0] == '.':
1645
+ domain.append(DOT)
1646
+ token, value = get_atom(value[1:])
1647
+ domain.append(token)
1648
+ return domain, value
1649
+
1650
+ def get_addr_spec(value):
1651
+ """ addr-spec = local-part "@" domain
1652
+
1653
+ """
1654
+ addr_spec = AddrSpec()
1655
+ token, value = get_local_part(value)
1656
+ addr_spec.append(token)
1657
+ if not value or value[0] != '@':
1658
+ addr_spec.defects.append(errors.InvalidHeaderDefect(
1659
+ "addr-spec local part with no domain"))
1660
+ return addr_spec, value
1661
+ addr_spec.append(ValueTerminal('@', 'address-at-symbol'))
1662
+ token, value = get_domain(value[1:])
1663
+ addr_spec.append(token)
1664
+ return addr_spec, value
1665
+
1666
+ def get_obs_route(value):
1667
+ """ obs-route = obs-domain-list ":"
1668
+ obs-domain-list = *(CFWS / ",") "@" domain *("," [CFWS] ["@" domain])
1669
+
1670
+ Returns an obs-route token with the appropriate sub-tokens (that is,
1671
+ there is no obs-domain-list in the parse tree).
1672
+ """
1673
+ obs_route = ObsRoute()
1674
+ while value and (value[0]==',' or value[0] in CFWS_LEADER):
1675
+ if value[0] in CFWS_LEADER:
1676
+ token, value = get_cfws(value)
1677
+ obs_route.append(token)
1678
+ elif value[0] == ',':
1679
+ obs_route.append(ListSeparator)
1680
+ value = value[1:]
1681
+ if not value or value[0] != '@':
1682
+ raise errors.HeaderParseError(
1683
+ "expected obs-route domain but found '{}'".format(value))
1684
+ obs_route.append(RouteComponentMarker)
1685
+ token, value = get_domain(value[1:])
1686
+ obs_route.append(token)
1687
+ while value and value[0]==',':
1688
+ obs_route.append(ListSeparator)
1689
+ value = value[1:]
1690
+ if not value:
1691
+ break
1692
+ if value[0] in CFWS_LEADER:
1693
+ token, value = get_cfws(value)
1694
+ obs_route.append(token)
1695
+ if not value:
1696
+ break
1697
+ if value[0] == '@':
1698
+ obs_route.append(RouteComponentMarker)
1699
+ token, value = get_domain(value[1:])
1700
+ obs_route.append(token)
1701
+ if not value:
1702
+ raise errors.HeaderParseError("end of header while parsing obs-route")
1703
+ if value[0] != ':':
1704
+ raise errors.HeaderParseError( "expected ':' marking end of "
1705
+ "obs-route but found '{}'".format(value))
1706
+ obs_route.append(ValueTerminal(':', 'end-of-obs-route-marker'))
1707
+ return obs_route, value[1:]
1708
+
1709
+ def get_angle_addr(value):
1710
+ """ angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr
1711
+ obs-angle-addr = [CFWS] "<" obs-route addr-spec ">" [CFWS]
1712
+
1713
+ """
1714
+ angle_addr = AngleAddr()
1715
+ if value and value[0] in CFWS_LEADER:
1716
+ token, value = get_cfws(value)
1717
+ angle_addr.append(token)
1718
+ if not value or value[0] != '<':
1719
+ raise errors.HeaderParseError(
1720
+ "expected angle-addr but found '{}'".format(value))
1721
+ angle_addr.append(ValueTerminal('<', 'angle-addr-start'))
1722
+ value = value[1:]
1723
+ # Although it is not legal per RFC5322, SMTP uses '<>' in certain
1724
+ # circumstances.
1725
+ if value and value[0] == '>':
1726
+ angle_addr.append(ValueTerminal('>', 'angle-addr-end'))
1727
+ angle_addr.defects.append(errors.InvalidHeaderDefect(
1728
+ "null addr-spec in angle-addr"))
1729
+ value = value[1:]
1730
+ return angle_addr, value
1731
+ try:
1732
+ token, value = get_addr_spec(value)
1733
+ except errors.HeaderParseError:
1734
+ try:
1735
+ token, value = get_obs_route(value)
1736
+ angle_addr.defects.append(errors.ObsoleteHeaderDefect(
1737
+ "obsolete route specification in angle-addr"))
1738
+ except errors.HeaderParseError:
1739
+ raise errors.HeaderParseError(
1740
+ "expected addr-spec or obs-route but found '{}'".format(value))
1741
+ angle_addr.append(token)
1742
+ token, value = get_addr_spec(value)
1743
+ angle_addr.append(token)
1744
+ if value and value[0] == '>':
1745
+ value = value[1:]
1746
+ else:
1747
+ angle_addr.defects.append(errors.InvalidHeaderDefect(
1748
+ "missing trailing '>' on angle-addr"))
1749
+ angle_addr.append(ValueTerminal('>', 'angle-addr-end'))
1750
+ if value and value[0] in CFWS_LEADER:
1751
+ token, value = get_cfws(value)
1752
+ angle_addr.append(token)
1753
+ return angle_addr, value
1754
+
1755
+ def get_display_name(value):
1756
+ """ display-name = phrase
1757
+
1758
+ Because this is simply a name-rule, we don't return a display-name
1759
+ token containing a phrase, but rather a display-name token with
1760
+ the content of the phrase.
1761
+
1762
+ """
1763
+ display_name = DisplayName()
1764
+ token, value = get_phrase(value)
1765
+ display_name.extend(token[:])
1766
+ display_name.defects = token.defects[:]
1767
+ return display_name, value
1768
+
1769
+
1770
+ def get_name_addr(value):
1771
+ """ name-addr = [display-name] angle-addr
1772
+
1773
+ """
1774
+ name_addr = NameAddr()
1775
+ # Both the optional display name and the angle-addr can start with cfws.
1776
+ leader = None
1777
+ if not value:
1778
+ raise errors.HeaderParseError(
1779
+ "expected name-addr but found '{}'".format(value))
1780
+ if value[0] in CFWS_LEADER:
1781
+ leader, value = get_cfws(value)
1782
+ if not value:
1783
+ raise errors.HeaderParseError(
1784
+ "expected name-addr but found '{}'".format(leader))
1785
+ if value[0] != '<':
1786
+ if value[0] in PHRASE_ENDS:
1787
+ raise errors.HeaderParseError(
1788
+ "expected name-addr but found '{}'".format(value))
1789
+ token, value = get_display_name(value)
1790
+ if not value:
1791
+ raise errors.HeaderParseError(
1792
+ "expected name-addr but found '{}'".format(token))
1793
+ if leader is not None:
1794
+ if isinstance(token[0], TokenList):
1795
+ token[0][:0] = [leader]
1796
+ else:
1797
+ token[:0] = [leader]
1798
+ leader = None
1799
+ name_addr.append(token)
1800
+ token, value = get_angle_addr(value)
1801
+ if leader is not None:
1802
+ token[:0] = [leader]
1803
+ name_addr.append(token)
1804
+ return name_addr, value
1805
+
1806
+ def get_mailbox(value):
1807
+ """ mailbox = name-addr / addr-spec
1808
+
1809
+ """
1810
+ # The only way to figure out if we are dealing with a name-addr or an
1811
+ # addr-spec is to try parsing each one.
1812
+ mailbox = Mailbox()
1813
+ try:
1814
+ token, value = get_name_addr(value)
1815
+ except errors.HeaderParseError:
1816
+ try:
1817
+ token, value = get_addr_spec(value)
1818
+ except errors.HeaderParseError:
1819
+ raise errors.HeaderParseError(
1820
+ "expected mailbox but found '{}'".format(value))
1821
+ if any(isinstance(x, errors.InvalidHeaderDefect)
1822
+ for x in token.all_defects):
1823
+ mailbox.token_type = 'invalid-mailbox'
1824
+ mailbox.append(token)
1825
+ return mailbox, value
1826
+
1827
+ def get_invalid_mailbox(value, endchars):
1828
+ """ Read everything up to one of the chars in endchars.
1829
+
1830
+ This is outside the formal grammar. The InvalidMailbox TokenList that is
1831
+ returned acts like a Mailbox, but the data attributes are None.
1832
+
1833
+ """
1834
+ invalid_mailbox = InvalidMailbox()
1835
+ while value and value[0] not in endchars:
1836
+ if value[0] in PHRASE_ENDS:
1837
+ invalid_mailbox.append(ValueTerminal(value[0],
1838
+ 'misplaced-special'))
1839
+ value = value[1:]
1840
+ else:
1841
+ token, value = get_phrase(value)
1842
+ invalid_mailbox.append(token)
1843
+ return invalid_mailbox, value
1844
+
1845
+ def get_mailbox_list(value):
1846
+ """ mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list
1847
+ obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS])
1848
+
1849
+ For this routine we go outside the formal grammar in order to improve error
1850
+ handling. We recognize the end of the mailbox list only at the end of the
1851
+ value or at a ';' (the group terminator). This is so that we can turn
1852
+ invalid mailboxes into InvalidMailbox tokens and continue parsing any
1853
+ remaining valid mailboxes. We also allow all mailbox entries to be null,
1854
+ and this condition is handled appropriately at a higher level.
1855
+
1856
+ """
1857
+ mailbox_list = MailboxList()
1858
+ while value and value[0] != ';':
1859
+ try:
1860
+ token, value = get_mailbox(value)
1861
+ mailbox_list.append(token)
1862
+ except errors.HeaderParseError:
1863
+ leader = None
1864
+ if value[0] in CFWS_LEADER:
1865
+ leader, value = get_cfws(value)
1866
+ if not value or value[0] in ',;':
1867
+ mailbox_list.append(leader)
1868
+ mailbox_list.defects.append(errors.ObsoleteHeaderDefect(
1869
+ "empty element in mailbox-list"))
1870
+ else:
1871
+ token, value = get_invalid_mailbox(value, ',;')
1872
+ if leader is not None:
1873
+ token[:0] = [leader]
1874
+ mailbox_list.append(token)
1875
+ mailbox_list.defects.append(errors.InvalidHeaderDefect(
1876
+ "invalid mailbox in mailbox-list"))
1877
+ elif value[0] == ',':
1878
+ mailbox_list.defects.append(errors.ObsoleteHeaderDefect(
1879
+ "empty element in mailbox-list"))
1880
+ else:
1881
+ token, value = get_invalid_mailbox(value, ',;')
1882
+ if leader is not None:
1883
+ token[:0] = [leader]
1884
+ mailbox_list.append(token)
1885
+ mailbox_list.defects.append(errors.InvalidHeaderDefect(
1886
+ "invalid mailbox in mailbox-list"))
1887
+ if value and value[0] not in ',;':
1888
+ # Crap after mailbox; treat it as an invalid mailbox.
1889
+ # The mailbox info will still be available.
1890
+ mailbox = mailbox_list[-1]
1891
+ mailbox.token_type = 'invalid-mailbox'
1892
+ token, value = get_invalid_mailbox(value, ',;')
1893
+ mailbox.extend(token)
1894
+ mailbox_list.defects.append(errors.InvalidHeaderDefect(
1895
+ "invalid mailbox in mailbox-list"))
1896
+ if value and value[0] == ',':
1897
+ mailbox_list.append(ListSeparator)
1898
+ value = value[1:]
1899
+ return mailbox_list, value
1900
+
1901
+
1902
+ def get_group_list(value):
1903
+ """ group-list = mailbox-list / CFWS / obs-group-list
1904
+ obs-group-list = 1*([CFWS] ",") [CFWS]
1905
+
1906
+ """
1907
+ group_list = GroupList()
1908
+ if not value:
1909
+ group_list.defects.append(errors.InvalidHeaderDefect(
1910
+ "end of header before group-list"))
1911
+ return group_list, value
1912
+ leader = None
1913
+ if value and value[0] in CFWS_LEADER:
1914
+ leader, value = get_cfws(value)
1915
+ if not value:
1916
+ # This should never happen in email parsing, since CFWS-only is a
1917
+ # legal alternative to group-list in a group, which is the only
1918
+ # place group-list appears.
1919
+ group_list.defects.append(errors.InvalidHeaderDefect(
1920
+ "end of header in group-list"))
1921
+ group_list.append(leader)
1922
+ return group_list, value
1923
+ if value[0] == ';':
1924
+ group_list.append(leader)
1925
+ return group_list, value
1926
+ token, value = get_mailbox_list(value)
1927
+ if len(token.all_mailboxes)==0:
1928
+ if leader is not None:
1929
+ group_list.append(leader)
1930
+ group_list.extend(token)
1931
+ group_list.defects.append(errors.ObsoleteHeaderDefect(
1932
+ "group-list with empty entries"))
1933
+ return group_list, value
1934
+ if leader is not None:
1935
+ token[:0] = [leader]
1936
+ group_list.append(token)
1937
+ return group_list, value
1938
+
1939
+ def get_group(value):
1940
+ """ group = display-name ":" [group-list] ";" [CFWS]
1941
+
1942
+ """
1943
+ group = Group()
1944
+ token, value = get_display_name(value)
1945
+ if not value or value[0] != ':':
1946
+ raise errors.HeaderParseError("expected ':' at end of group "
1947
+ "display name but found '{}'".format(value))
1948
+ group.append(token)
1949
+ group.append(ValueTerminal(':', 'group-display-name-terminator'))
1950
+ value = value[1:]
1951
+ if value and value[0] == ';':
1952
+ group.append(ValueTerminal(';', 'group-terminator'))
1953
+ return group, value[1:]
1954
+ token, value = get_group_list(value)
1955
+ group.append(token)
1956
+ if not value:
1957
+ group.defects.append(errors.InvalidHeaderDefect(
1958
+ "end of header in group"))
1959
+ elif value[0] != ';':
1960
+ raise errors.HeaderParseError(
1961
+ "expected ';' at end of group but found {}".format(value))
1962
+ group.append(ValueTerminal(';', 'group-terminator'))
1963
+ value = value[1:]
1964
+ if value and value[0] in CFWS_LEADER:
1965
+ token, value = get_cfws(value)
1966
+ group.append(token)
1967
+ return group, value
1968
+
1969
+ def get_address(value):
1970
+ """ address = mailbox / group
1971
+
1972
+ Note that counter-intuitively, an address can be either a single address or
1973
+ a list of addresses (a group). This is why the returned Address object has
1974
+ a 'mailboxes' attribute which treats a single address as a list of length
1975
+ one. When you need to differentiate between to two cases, extract the single
1976
+ element, which is either a mailbox or a group token.
1977
+
1978
+ """
1979
+ # The formal grammar isn't very helpful when parsing an address. mailbox
1980
+ # and group, especially when allowing for obsolete forms, start off very
1981
+ # similarly. It is only when you reach one of @, <, or : that you know
1982
+ # what you've got. So, we try each one in turn, starting with the more
1983
+ # likely of the two. We could perhaps make this more efficient by looking
1984
+ # for a phrase and then branching based on the next character, but that
1985
+ # would be a premature optimization.
1986
+ address = Address()
1987
+ try:
1988
+ token, value = get_group(value)
1989
+ except errors.HeaderParseError:
1990
+ try:
1991
+ token, value = get_mailbox(value)
1992
+ except errors.HeaderParseError:
1993
+ raise errors.HeaderParseError(
1994
+ "expected address but found '{}'".format(value))
1995
+ address.append(token)
1996
+ return address, value
1997
+
1998
+ def get_address_list(value):
1999
+ """ address_list = (address *("," address)) / obs-addr-list
2000
+ obs-addr-list = *([CFWS] ",") address *("," [address / CFWS])
2001
+
2002
+ We depart from the formal grammar here by continuing to parse until the end
2003
+ of the input, assuming the input to be entirely composed of an
2004
+ address-list. This is always true in email parsing, and allows us
2005
+ to skip invalid addresses to parse additional valid ones.
2006
+
2007
+ """
2008
+ address_list = AddressList()
2009
+ while value:
2010
+ try:
2011
+ token, value = get_address(value)
2012
+ address_list.append(token)
2013
+ except errors.HeaderParseError:
2014
+ leader = None
2015
+ if value[0] in CFWS_LEADER:
2016
+ leader, value = get_cfws(value)
2017
+ if not value or value[0] == ',':
2018
+ address_list.append(leader)
2019
+ address_list.defects.append(errors.ObsoleteHeaderDefect(
2020
+ "address-list entry with no content"))
2021
+ else:
2022
+ token, value = get_invalid_mailbox(value, ',')
2023
+ if leader is not None:
2024
+ token[:0] = [leader]
2025
+ address_list.append(Address([token]))
2026
+ address_list.defects.append(errors.InvalidHeaderDefect(
2027
+ "invalid address in address-list"))
2028
+ elif value[0] == ',':
2029
+ address_list.defects.append(errors.ObsoleteHeaderDefect(
2030
+ "empty element in address-list"))
2031
+ else:
2032
+ token, value = get_invalid_mailbox(value, ',')
2033
+ if leader is not None:
2034
+ token[:0] = [leader]
2035
+ address_list.append(Address([token]))
2036
+ address_list.defects.append(errors.InvalidHeaderDefect(
2037
+ "invalid address in address-list"))
2038
+ if value and value[0] != ',':
2039
+ # Crap after address; treat it as an invalid mailbox.
2040
+ # The mailbox info will still be available.
2041
+ mailbox = address_list[-1][0]
2042
+ mailbox.token_type = 'invalid-mailbox'
2043
+ token, value = get_invalid_mailbox(value, ',')
2044
+ mailbox.extend(token)
2045
+ address_list.defects.append(errors.InvalidHeaderDefect(
2046
+ "invalid address in address-list"))
2047
+ if value: # Must be a , at this point.
2048
+ address_list.append(ListSeparator)
2049
+ value = value[1:]
2050
+ return address_list, value
2051
+
2052
+
2053
+ def get_no_fold_literal(value):
2054
+ """ no-fold-literal = "[" *dtext "]"
2055
+ """
2056
+ no_fold_literal = NoFoldLiteral()
2057
+ if not value:
2058
+ raise errors.HeaderParseError(
2059
+ "expected no-fold-literal but found '{}'".format(value))
2060
+ if value[0] != '[':
2061
+ raise errors.HeaderParseError(
2062
+ "expected '[' at the start of no-fold-literal "
2063
+ "but found '{}'".format(value))
2064
+ no_fold_literal.append(ValueTerminal('[', 'no-fold-literal-start'))
2065
+ value = value[1:]
2066
+ token, value = get_dtext(value)
2067
+ no_fold_literal.append(token)
2068
+ if not value or value[0] != ']':
2069
+ raise errors.HeaderParseError(
2070
+ "expected ']' at the end of no-fold-literal "
2071
+ "but found '{}'".format(value))
2072
+ no_fold_literal.append(ValueTerminal(']', 'no-fold-literal-end'))
2073
+ return no_fold_literal, value[1:]
2074
+
2075
+ def get_msg_id(value):
2076
+ """msg-id = [CFWS] "<" id-left '@' id-right ">" [CFWS]
2077
+ id-left = dot-atom-text / obs-id-left
2078
+ id-right = dot-atom-text / no-fold-literal / obs-id-right
2079
+ no-fold-literal = "[" *dtext "]"
2080
+ """
2081
+ msg_id = MsgID()
2082
+ if value and value[0] in CFWS_LEADER:
2083
+ token, value = get_cfws(value)
2084
+ msg_id.append(token)
2085
+ if not value or value[0] != '<':
2086
+ raise errors.HeaderParseError(
2087
+ "expected msg-id but found '{}'".format(value))
2088
+ msg_id.append(ValueTerminal('<', 'msg-id-start'))
2089
+ value = value[1:]
2090
+ # Parse id-left.
2091
+ try:
2092
+ token, value = get_dot_atom_text(value)
2093
+ except errors.HeaderParseError:
2094
+ try:
2095
+ # obs-id-left is same as local-part of add-spec.
2096
+ token, value = get_obs_local_part(value)
2097
+ msg_id.defects.append(errors.ObsoleteHeaderDefect(
2098
+ "obsolete id-left in msg-id"))
2099
+ except errors.HeaderParseError:
2100
+ raise errors.HeaderParseError(
2101
+ "expected dot-atom-text or obs-id-left"
2102
+ " but found '{}'".format(value))
2103
+ msg_id.append(token)
2104
+ if not value or value[0] != '@':
2105
+ msg_id.defects.append(errors.InvalidHeaderDefect(
2106
+ "msg-id with no id-right"))
2107
+ # Even though there is no id-right, if the local part
2108
+ # ends with `>` let's just parse it too and return
2109
+ # along with the defect.
2110
+ if value and value[0] == '>':
2111
+ msg_id.append(ValueTerminal('>', 'msg-id-end'))
2112
+ value = value[1:]
2113
+ return msg_id, value
2114
+ msg_id.append(ValueTerminal('@', 'address-at-symbol'))
2115
+ value = value[1:]
2116
+ # Parse id-right.
2117
+ try:
2118
+ token, value = get_dot_atom_text(value)
2119
+ except errors.HeaderParseError:
2120
+ try:
2121
+ token, value = get_no_fold_literal(value)
2122
+ except errors.HeaderParseError:
2123
+ try:
2124
+ token, value = get_domain(value)
2125
+ msg_id.defects.append(errors.ObsoleteHeaderDefect(
2126
+ "obsolete id-right in msg-id"))
2127
+ except errors.HeaderParseError:
2128
+ raise errors.HeaderParseError(
2129
+ "expected dot-atom-text, no-fold-literal or obs-id-right"
2130
+ " but found '{}'".format(value))
2131
+ msg_id.append(token)
2132
+ if value and value[0] == '>':
2133
+ value = value[1:]
2134
+ else:
2135
+ msg_id.defects.append(errors.InvalidHeaderDefect(
2136
+ "missing trailing '>' on msg-id"))
2137
+ msg_id.append(ValueTerminal('>', 'msg-id-end'))
2138
+ if value and value[0] in CFWS_LEADER:
2139
+ token, value = get_cfws(value)
2140
+ msg_id.append(token)
2141
+ return msg_id, value
2142
+
2143
+
2144
+ def parse_message_id(value):
2145
+ """message-id = "Message-ID:" msg-id CRLF
2146
+ """
2147
+ message_id = MessageID()
2148
+ try:
2149
+ token, value = get_msg_id(value)
2150
+ message_id.append(token)
2151
+ except errors.HeaderParseError as ex:
2152
+ token = get_unstructured(value)
2153
+ message_id = InvalidMessageID(token)
2154
+ message_id.defects.append(
2155
+ errors.InvalidHeaderDefect("Invalid msg-id: {!r}".format(ex)))
2156
+ else:
2157
+ # Value after parsing a valid msg_id should be None.
2158
+ if value:
2159
+ message_id.defects.append(errors.InvalidHeaderDefect(
2160
+ "Unexpected {!r}".format(value)))
2161
+
2162
+ return message_id
2163
+
2164
+ #
2165
+ # XXX: As I begin to add additional header parsers, I'm realizing we probably
2166
+ # have two level of parser routines: the get_XXX methods that get a token in
2167
+ # the grammar, and parse_XXX methods that parse an entire field value. So
2168
+ # get_address_list above should really be a parse_ method, as probably should
2169
+ # be get_unstructured.
2170
+ #
2171
+
2172
+ def parse_mime_version(value):
2173
+ """ mime-version = [CFWS] 1*digit [CFWS] "." [CFWS] 1*digit [CFWS]
2174
+
2175
+ """
2176
+ # The [CFWS] is implicit in the RFC 2045 BNF.
2177
+ # XXX: This routine is a bit verbose, should factor out a get_int method.
2178
+ mime_version = MIMEVersion()
2179
+ if not value:
2180
+ mime_version.defects.append(errors.HeaderMissingRequiredValue(
2181
+ "Missing MIME version number (eg: 1.0)"))
2182
+ return mime_version
2183
+ if value[0] in CFWS_LEADER:
2184
+ token, value = get_cfws(value)
2185
+ mime_version.append(token)
2186
+ if not value:
2187
+ mime_version.defects.append(errors.HeaderMissingRequiredValue(
2188
+ "Expected MIME version number but found only CFWS"))
2189
+ digits = ''
2190
+ while value and value[0] != '.' and value[0] not in CFWS_LEADER:
2191
+ digits += value[0]
2192
+ value = value[1:]
2193
+ if not digits.isdigit():
2194
+ mime_version.defects.append(errors.InvalidHeaderDefect(
2195
+ "Expected MIME major version number but found {!r}".format(digits)))
2196
+ mime_version.append(ValueTerminal(digits, 'xtext'))
2197
+ else:
2198
+ mime_version.major = int(digits)
2199
+ mime_version.append(ValueTerminal(digits, 'digits'))
2200
+ if value and value[0] in CFWS_LEADER:
2201
+ token, value = get_cfws(value)
2202
+ mime_version.append(token)
2203
+ if not value or value[0] != '.':
2204
+ if mime_version.major is not None:
2205
+ mime_version.defects.append(errors.InvalidHeaderDefect(
2206
+ "Incomplete MIME version; found only major number"))
2207
+ if value:
2208
+ mime_version.append(ValueTerminal(value, 'xtext'))
2209
+ return mime_version
2210
+ mime_version.append(ValueTerminal('.', 'version-separator'))
2211
+ value = value[1:]
2212
+ if value and value[0] in CFWS_LEADER:
2213
+ token, value = get_cfws(value)
2214
+ mime_version.append(token)
2215
+ if not value:
2216
+ if mime_version.major is not None:
2217
+ mime_version.defects.append(errors.InvalidHeaderDefect(
2218
+ "Incomplete MIME version; found only major number"))
2219
+ return mime_version
2220
+ digits = ''
2221
+ while value and value[0] not in CFWS_LEADER:
2222
+ digits += value[0]
2223
+ value = value[1:]
2224
+ if not digits.isdigit():
2225
+ mime_version.defects.append(errors.InvalidHeaderDefect(
2226
+ "Expected MIME minor version number but found {!r}".format(digits)))
2227
+ mime_version.append(ValueTerminal(digits, 'xtext'))
2228
+ else:
2229
+ mime_version.minor = int(digits)
2230
+ mime_version.append(ValueTerminal(digits, 'digits'))
2231
+ if value and value[0] in CFWS_LEADER:
2232
+ token, value = get_cfws(value)
2233
+ mime_version.append(token)
2234
+ if value:
2235
+ mime_version.defects.append(errors.InvalidHeaderDefect(
2236
+ "Excess non-CFWS text after MIME version"))
2237
+ mime_version.append(ValueTerminal(value, 'xtext'))
2238
+ return mime_version
2239
+
2240
+ def get_invalid_parameter(value):
2241
+ """ Read everything up to the next ';'.
2242
+
2243
+ This is outside the formal grammar. The InvalidParameter TokenList that is
2244
+ returned acts like a Parameter, but the data attributes are None.
2245
+
2246
+ """
2247
+ invalid_parameter = InvalidParameter()
2248
+ while value and value[0] != ';':
2249
+ if value[0] in PHRASE_ENDS:
2250
+ invalid_parameter.append(ValueTerminal(value[0],
2251
+ 'misplaced-special'))
2252
+ value = value[1:]
2253
+ else:
2254
+ token, value = get_phrase(value)
2255
+ invalid_parameter.append(token)
2256
+ return invalid_parameter, value
2257
+
2258
+ def get_ttext(value):
2259
+ """ttext = <matches _ttext_matcher>
2260
+
2261
+ We allow any non-TOKEN_ENDS in ttext, but add defects to the token's
2262
+ defects list if we find non-ttext characters. We also register defects for
2263
+ *any* non-printables even though the RFC doesn't exclude all of them,
2264
+ because we follow the spirit of RFC 5322.
2265
+
2266
+ """
2267
+ m = _non_token_end_matcher(value)
2268
+ if not m:
2269
+ raise errors.HeaderParseError(
2270
+ "expected ttext but found '{}'".format(value))
2271
+ ttext = m.group()
2272
+ value = value[len(ttext):]
2273
+ ttext = ValueTerminal(ttext, 'ttext')
2274
+ _validate_xtext(ttext)
2275
+ return ttext, value
2276
+
2277
+ def get_token(value):
2278
+ """token = [CFWS] 1*ttext [CFWS]
2279
+
2280
+ The RFC equivalent of ttext is any US-ASCII chars except space, ctls, or
2281
+ tspecials. We also exclude tabs even though the RFC doesn't.
2282
+
2283
+ The RFC implies the CFWS but is not explicit about it in the BNF.
2284
+
2285
+ """
2286
+ mtoken = Token()
2287
+ if value and value[0] in CFWS_LEADER:
2288
+ token, value = get_cfws(value)
2289
+ mtoken.append(token)
2290
+ if value and value[0] in TOKEN_ENDS:
2291
+ raise errors.HeaderParseError(
2292
+ "expected token but found '{}'".format(value))
2293
+ token, value = get_ttext(value)
2294
+ mtoken.append(token)
2295
+ if value and value[0] in CFWS_LEADER:
2296
+ token, value = get_cfws(value)
2297
+ mtoken.append(token)
2298
+ return mtoken, value
2299
+
2300
+ def get_attrtext(value):
2301
+ """attrtext = 1*(any non-ATTRIBUTE_ENDS character)
2302
+
2303
+ We allow any non-ATTRIBUTE_ENDS in attrtext, but add defects to the
2304
+ token's defects list if we find non-attrtext characters. We also register
2305
+ defects for *any* non-printables even though the RFC doesn't exclude all of
2306
+ them, because we follow the spirit of RFC 5322.
2307
+
2308
+ """
2309
+ m = _non_attribute_end_matcher(value)
2310
+ if not m:
2311
+ raise errors.HeaderParseError(
2312
+ "expected attrtext but found {!r}".format(value))
2313
+ attrtext = m.group()
2314
+ value = value[len(attrtext):]
2315
+ attrtext = ValueTerminal(attrtext, 'attrtext')
2316
+ _validate_xtext(attrtext)
2317
+ return attrtext, value
2318
+
2319
+ def get_attribute(value):
2320
+ """ [CFWS] 1*attrtext [CFWS]
2321
+
2322
+ This version of the BNF makes the CFWS explicit, and as usual we use a
2323
+ value terminal for the actual run of characters. The RFC equivalent of
2324
+ attrtext is the token characters, with the subtraction of '*', "'", and '%'.
2325
+ We include tab in the excluded set just as we do for token.
2326
+
2327
+ """
2328
+ attribute = Attribute()
2329
+ if value and value[0] in CFWS_LEADER:
2330
+ token, value = get_cfws(value)
2331
+ attribute.append(token)
2332
+ if value and value[0] in ATTRIBUTE_ENDS:
2333
+ raise errors.HeaderParseError(
2334
+ "expected token but found '{}'".format(value))
2335
+ token, value = get_attrtext(value)
2336
+ attribute.append(token)
2337
+ if value and value[0] in CFWS_LEADER:
2338
+ token, value = get_cfws(value)
2339
+ attribute.append(token)
2340
+ return attribute, value
2341
+
2342
+ def get_extended_attrtext(value):
2343
+ """attrtext = 1*(any non-ATTRIBUTE_ENDS character plus '%')
2344
+
2345
+ This is a special parsing routine so that we get a value that
2346
+ includes % escapes as a single string (which we decode as a single
2347
+ string later).
2348
+
2349
+ """
2350
+ m = _non_extended_attribute_end_matcher(value)
2351
+ if not m:
2352
+ raise errors.HeaderParseError(
2353
+ "expected extended attrtext but found {!r}".format(value))
2354
+ attrtext = m.group()
2355
+ value = value[len(attrtext):]
2356
+ attrtext = ValueTerminal(attrtext, 'extended-attrtext')
2357
+ _validate_xtext(attrtext)
2358
+ return attrtext, value
2359
+
2360
+ def get_extended_attribute(value):
2361
+ """ [CFWS] 1*extended_attrtext [CFWS]
2362
+
2363
+ This is like the non-extended version except we allow % characters, so that
2364
+ we can pick up an encoded value as a single string.
2365
+
2366
+ """
2367
+ # XXX: should we have an ExtendedAttribute TokenList?
2368
+ attribute = Attribute()
2369
+ if value and value[0] in CFWS_LEADER:
2370
+ token, value = get_cfws(value)
2371
+ attribute.append(token)
2372
+ if value and value[0] in EXTENDED_ATTRIBUTE_ENDS:
2373
+ raise errors.HeaderParseError(
2374
+ "expected token but found '{}'".format(value))
2375
+ token, value = get_extended_attrtext(value)
2376
+ attribute.append(token)
2377
+ if value and value[0] in CFWS_LEADER:
2378
+ token, value = get_cfws(value)
2379
+ attribute.append(token)
2380
+ return attribute, value
2381
+
2382
+ def get_section(value):
2383
+ """ '*' digits
2384
+
2385
+ The formal BNF is more complicated because leading 0s are not allowed. We
2386
+ check for that and add a defect. We also assume no CFWS is allowed between
2387
+ the '*' and the digits, though the RFC is not crystal clear on that.
2388
+ The caller should already have dealt with leading CFWS.
2389
+
2390
+ """
2391
+ section = Section()
2392
+ if not value or value[0] != '*':
2393
+ raise errors.HeaderParseError("Expected section but found {}".format(
2394
+ value))
2395
+ section.append(ValueTerminal('*', 'section-marker'))
2396
+ value = value[1:]
2397
+ if not value or not value[0].isdigit():
2398
+ raise errors.HeaderParseError("Expected section number but "
2399
+ "found {}".format(value))
2400
+ digits = ''
2401
+ while value and value[0].isdigit():
2402
+ digits += value[0]
2403
+ value = value[1:]
2404
+ if digits[0] == '0' and digits != '0':
2405
+ section.defects.append(errors.InvalidHeaderDefect(
2406
+ "section number has an invalid leading 0"))
2407
+ section.number = int(digits)
2408
+ section.append(ValueTerminal(digits, 'digits'))
2409
+ return section, value
2410
+
2411
+
2412
+ def get_value(value):
2413
+ """ quoted-string / attribute
2414
+
2415
+ """
2416
+ v = Value()
2417
+ if not value:
2418
+ raise errors.HeaderParseError("Expected value but found end of string")
2419
+ leader = None
2420
+ if value[0] in CFWS_LEADER:
2421
+ leader, value = get_cfws(value)
2422
+ if not value:
2423
+ raise errors.HeaderParseError("Expected value but found "
2424
+ "only {}".format(leader))
2425
+ if value[0] == '"':
2426
+ token, value = get_quoted_string(value)
2427
+ else:
2428
+ token, value = get_extended_attribute(value)
2429
+ if leader is not None:
2430
+ token[:0] = [leader]
2431
+ v.append(token)
2432
+ return v, value
2433
+
2434
+ def get_parameter(value):
2435
+ """ attribute [section] ["*"] [CFWS] "=" value
2436
+
2437
+ The CFWS is implied by the RFC but not made explicit in the BNF. This
2438
+ simplified form of the BNF from the RFC is made to conform with the RFC BNF
2439
+ through some extra checks. We do it this way because it makes both error
2440
+ recovery and working with the resulting parse tree easier.
2441
+ """
2442
+ # It is possible CFWS would also be implicitly allowed between the section
2443
+ # and the 'extended-attribute' marker (the '*') , but we've never seen that
2444
+ # in the wild and we will therefore ignore the possibility.
2445
+ param = Parameter()
2446
+ token, value = get_attribute(value)
2447
+ param.append(token)
2448
+ if not value or value[0] == ';':
2449
+ param.defects.append(errors.InvalidHeaderDefect("Parameter contains "
2450
+ "name ({}) but no value".format(token)))
2451
+ return param, value
2452
+ if value[0] == '*':
2453
+ try:
2454
+ token, value = get_section(value)
2455
+ param.sectioned = True
2456
+ param.append(token)
2457
+ except errors.HeaderParseError:
2458
+ pass
2459
+ if not value:
2460
+ raise errors.HeaderParseError("Incomplete parameter")
2461
+ if value[0] == '*':
2462
+ param.append(ValueTerminal('*', 'extended-parameter-marker'))
2463
+ value = value[1:]
2464
+ param.extended = True
2465
+ if value[0] != '=':
2466
+ raise errors.HeaderParseError("Parameter not followed by '='")
2467
+ param.append(ValueTerminal('=', 'parameter-separator'))
2468
+ value = value[1:]
2469
+ if value and value[0] in CFWS_LEADER:
2470
+ token, value = get_cfws(value)
2471
+ param.append(token)
2472
+ remainder = None
2473
+ appendto = param
2474
+ if param.extended and value and value[0] == '"':
2475
+ # Now for some serious hackery to handle the common invalid case of
2476
+ # double quotes around an extended value. We also accept (with defect)
2477
+ # a value marked as encoded that isn't really.
2478
+ qstring, remainder = get_quoted_string(value)
2479
+ inner_value = qstring.stripped_value
2480
+ semi_valid = False
2481
+ if param.section_number == 0:
2482
+ if inner_value and inner_value[0] == "'":
2483
+ semi_valid = True
2484
+ else:
2485
+ token, rest = get_attrtext(inner_value)
2486
+ if rest and rest[0] == "'":
2487
+ semi_valid = True
2488
+ else:
2489
+ try:
2490
+ token, rest = get_extended_attrtext(inner_value)
2491
+ except:
2492
+ pass
2493
+ else:
2494
+ if not rest:
2495
+ semi_valid = True
2496
+ if semi_valid:
2497
+ param.defects.append(errors.InvalidHeaderDefect(
2498
+ "Quoted string value for extended parameter is invalid"))
2499
+ param.append(qstring)
2500
+ for t in qstring:
2501
+ if t.token_type == 'bare-quoted-string':
2502
+ t[:] = []
2503
+ appendto = t
2504
+ break
2505
+ value = inner_value
2506
+ else:
2507
+ remainder = None
2508
+ param.defects.append(errors.InvalidHeaderDefect(
2509
+ "Parameter marked as extended but appears to have a "
2510
+ "quoted string value that is non-encoded"))
2511
+ if value and value[0] == "'":
2512
+ token = None
2513
+ else:
2514
+ token, value = get_value(value)
2515
+ if not param.extended or param.section_number > 0:
2516
+ if not value or value[0] != "'":
2517
+ appendto.append(token)
2518
+ if remainder is not None:
2519
+ assert not value, value
2520
+ value = remainder
2521
+ return param, value
2522
+ param.defects.append(errors.InvalidHeaderDefect(
2523
+ "Apparent initial-extended-value but attribute "
2524
+ "was not marked as extended or was not initial section"))
2525
+ if not value:
2526
+ # Assume the charset/lang is missing and the token is the value.
2527
+ param.defects.append(errors.InvalidHeaderDefect(
2528
+ "Missing required charset/lang delimiters"))
2529
+ appendto.append(token)
2530
+ if remainder is None:
2531
+ return param, value
2532
+ else:
2533
+ if token is not None:
2534
+ for t in token:
2535
+ if t.token_type == 'extended-attrtext':
2536
+ break
2537
+ t.token_type == 'attrtext'
2538
+ appendto.append(t)
2539
+ param.charset = t.value
2540
+ if value[0] != "'":
2541
+ raise errors.HeaderParseError("Expected RFC2231 char/lang encoding "
2542
+ "delimiter, but found {!r}".format(value))
2543
+ appendto.append(ValueTerminal("'", 'RFC2231-delimiter'))
2544
+ value = value[1:]
2545
+ if value and value[0] != "'":
2546
+ token, value = get_attrtext(value)
2547
+ appendto.append(token)
2548
+ param.lang = token.value
2549
+ if not value or value[0] != "'":
2550
+ raise errors.HeaderParseError("Expected RFC2231 char/lang encoding "
2551
+ "delimiter, but found {}".format(value))
2552
+ appendto.append(ValueTerminal("'", 'RFC2231-delimiter'))
2553
+ value = value[1:]
2554
+ if remainder is not None:
2555
+ # Treat the rest of value as bare quoted string content.
2556
+ v = Value()
2557
+ while value:
2558
+ if value[0] in WSP:
2559
+ token, value = get_fws(value)
2560
+ elif value[0] == '"':
2561
+ token = ValueTerminal('"', 'DQUOTE')
2562
+ value = value[1:]
2563
+ else:
2564
+ token, value = get_qcontent(value)
2565
+ v.append(token)
2566
+ token = v
2567
+ else:
2568
+ token, value = get_value(value)
2569
+ appendto.append(token)
2570
+ if remainder is not None:
2571
+ assert not value, value
2572
+ value = remainder
2573
+ return param, value
2574
+
2575
+ def parse_mime_parameters(value):
2576
+ """ parameter *( ";" parameter )
2577
+
2578
+ That BNF is meant to indicate this routine should only be called after
2579
+ finding and handling the leading ';'. There is no corresponding rule in
2580
+ the formal RFC grammar, but it is more convenient for us for the set of
2581
+ parameters to be treated as its own TokenList.
2582
+
2583
+ This is 'parse' routine because it consumes the remaining value, but it
2584
+ would never be called to parse a full header. Instead it is called to
2585
+ parse everything after the non-parameter value of a specific MIME header.
2586
+
2587
+ """
2588
+ mime_parameters = MimeParameters()
2589
+ while value:
2590
+ try:
2591
+ token, value = get_parameter(value)
2592
+ mime_parameters.append(token)
2593
+ except errors.HeaderParseError:
2594
+ leader = None
2595
+ if value[0] in CFWS_LEADER:
2596
+ leader, value = get_cfws(value)
2597
+ if not value:
2598
+ mime_parameters.append(leader)
2599
+ return mime_parameters
2600
+ if value[0] == ';':
2601
+ if leader is not None:
2602
+ mime_parameters.append(leader)
2603
+ mime_parameters.defects.append(errors.InvalidHeaderDefect(
2604
+ "parameter entry with no content"))
2605
+ else:
2606
+ token, value = get_invalid_parameter(value)
2607
+ if leader:
2608
+ token[:0] = [leader]
2609
+ mime_parameters.append(token)
2610
+ mime_parameters.defects.append(errors.InvalidHeaderDefect(
2611
+ "invalid parameter {!r}".format(token)))
2612
+ if value and value[0] != ';':
2613
+ # Junk after the otherwise valid parameter. Mark it as
2614
+ # invalid, but it will have a value.
2615
+ param = mime_parameters[-1]
2616
+ param.token_type = 'invalid-parameter'
2617
+ token, value = get_invalid_parameter(value)
2618
+ param.extend(token)
2619
+ mime_parameters.defects.append(errors.InvalidHeaderDefect(
2620
+ "parameter with invalid trailing text {!r}".format(token)))
2621
+ if value:
2622
+ # Must be a ';' at this point.
2623
+ mime_parameters.append(ValueTerminal(';', 'parameter-separator'))
2624
+ value = value[1:]
2625
+ return mime_parameters
2626
+
2627
+ def _find_mime_parameters(tokenlist, value):
2628
+ """Do our best to find the parameters in an invalid MIME header
2629
+
2630
+ """
2631
+ while value and value[0] != ';':
2632
+ if value[0] in PHRASE_ENDS:
2633
+ tokenlist.append(ValueTerminal(value[0], 'misplaced-special'))
2634
+ value = value[1:]
2635
+ else:
2636
+ token, value = get_phrase(value)
2637
+ tokenlist.append(token)
2638
+ if not value:
2639
+ return
2640
+ tokenlist.append(ValueTerminal(';', 'parameter-separator'))
2641
+ tokenlist.append(parse_mime_parameters(value[1:]))
2642
+
2643
+ def parse_content_type_header(value):
2644
+ """ maintype "/" subtype *( ";" parameter )
2645
+
2646
+ The maintype and substype are tokens. Theoretically they could
2647
+ be checked against the official IANA list + x-token, but we
2648
+ don't do that.
2649
+ """
2650
+ ctype = ContentType()
2651
+ if not value:
2652
+ ctype.defects.append(errors.HeaderMissingRequiredValue(
2653
+ "Missing content type specification"))
2654
+ return ctype
2655
+ try:
2656
+ token, value = get_token(value)
2657
+ except errors.HeaderParseError:
2658
+ ctype.defects.append(errors.InvalidHeaderDefect(
2659
+ "Expected content maintype but found {!r}".format(value)))
2660
+ _find_mime_parameters(ctype, value)
2661
+ return ctype
2662
+ ctype.append(token)
2663
+ # XXX: If we really want to follow the formal grammar we should make
2664
+ # mantype and subtype specialized TokenLists here. Probably not worth it.
2665
+ if not value or value[0] != '/':
2666
+ ctype.defects.append(errors.InvalidHeaderDefect(
2667
+ "Invalid content type"))
2668
+ if value:
2669
+ _find_mime_parameters(ctype, value)
2670
+ return ctype
2671
+ ctype.maintype = token.value.strip().lower()
2672
+ ctype.append(ValueTerminal('/', 'content-type-separator'))
2673
+ value = value[1:]
2674
+ try:
2675
+ token, value = get_token(value)
2676
+ except errors.HeaderParseError:
2677
+ ctype.defects.append(errors.InvalidHeaderDefect(
2678
+ "Expected content subtype but found {!r}".format(value)))
2679
+ _find_mime_parameters(ctype, value)
2680
+ return ctype
2681
+ ctype.append(token)
2682
+ ctype.subtype = token.value.strip().lower()
2683
+ if not value:
2684
+ return ctype
2685
+ if value[0] != ';':
2686
+ ctype.defects.append(errors.InvalidHeaderDefect(
2687
+ "Only parameters are valid after content type, but "
2688
+ "found {!r}".format(value)))
2689
+ # The RFC requires that a syntactically invalid content-type be treated
2690
+ # as text/plain. Perhaps we should postel this, but we should probably
2691
+ # only do that if we were checking the subtype value against IANA.
2692
+ del ctype.maintype, ctype.subtype
2693
+ _find_mime_parameters(ctype, value)
2694
+ return ctype
2695
+ ctype.append(ValueTerminal(';', 'parameter-separator'))
2696
+ ctype.append(parse_mime_parameters(value[1:]))
2697
+ return ctype
2698
+
2699
+ def parse_content_disposition_header(value):
2700
+ """ disposition-type *( ";" parameter )
2701
+
2702
+ """
2703
+ disp_header = ContentDisposition()
2704
+ if not value:
2705
+ disp_header.defects.append(errors.HeaderMissingRequiredValue(
2706
+ "Missing content disposition"))
2707
+ return disp_header
2708
+ try:
2709
+ token, value = get_token(value)
2710
+ except errors.HeaderParseError:
2711
+ disp_header.defects.append(errors.InvalidHeaderDefect(
2712
+ "Expected content disposition but found {!r}".format(value)))
2713
+ _find_mime_parameters(disp_header, value)
2714
+ return disp_header
2715
+ disp_header.append(token)
2716
+ disp_header.content_disposition = token.value.strip().lower()
2717
+ if not value:
2718
+ return disp_header
2719
+ if value[0] != ';':
2720
+ disp_header.defects.append(errors.InvalidHeaderDefect(
2721
+ "Only parameters are valid after content disposition, but "
2722
+ "found {!r}".format(value)))
2723
+ _find_mime_parameters(disp_header, value)
2724
+ return disp_header
2725
+ disp_header.append(ValueTerminal(';', 'parameter-separator'))
2726
+ disp_header.append(parse_mime_parameters(value[1:]))
2727
+ return disp_header
2728
+
2729
+ def parse_content_transfer_encoding_header(value):
2730
+ """ mechanism
2731
+
2732
+ """
2733
+ # We should probably validate the values, since the list is fixed.
2734
+ cte_header = ContentTransferEncoding()
2735
+ if not value:
2736
+ cte_header.defects.append(errors.HeaderMissingRequiredValue(
2737
+ "Missing content transfer encoding"))
2738
+ return cte_header
2739
+ try:
2740
+ token, value = get_token(value)
2741
+ except errors.HeaderParseError:
2742
+ cte_header.defects.append(errors.InvalidHeaderDefect(
2743
+ "Expected content transfer encoding but found {!r}".format(value)))
2744
+ else:
2745
+ cte_header.append(token)
2746
+ cte_header.cte = token.value.strip().lower()
2747
+ if not value:
2748
+ return cte_header
2749
+ while value:
2750
+ cte_header.defects.append(errors.InvalidHeaderDefect(
2751
+ "Extra text after content transfer encoding"))
2752
+ if value[0] in PHRASE_ENDS:
2753
+ cte_header.append(ValueTerminal(value[0], 'misplaced-special'))
2754
+ value = value[1:]
2755
+ else:
2756
+ token, value = get_phrase(value)
2757
+ cte_header.append(token)
2758
+ return cte_header
2759
+
2760
+
2761
+ #
2762
+ # Header folding
2763
+ #
2764
+ # Header folding is complex, with lots of rules and corner cases. The
2765
+ # following code does its best to obey the rules and handle the corner
2766
+ # cases, but you can be sure there are few bugs:)
2767
+ #
2768
+ # This folder generally canonicalizes as it goes, preferring the stringified
2769
+ # version of each token. The tokens contain information that supports the
2770
+ # folder, including which tokens can be encoded in which ways.
2771
+ #
2772
+ # Folded text is accumulated in a simple list of strings ('lines'), each
2773
+ # one of which should be less than policy.max_line_length ('maxlen').
2774
+ #
2775
+
2776
+ def _steal_trailing_WSP_if_exists(lines):
2777
+ wsp = ''
2778
+ if lines and lines[-1] and lines[-1][-1] in WSP:
2779
+ wsp = lines[-1][-1]
2780
+ lines[-1] = lines[-1][:-1]
2781
+ return wsp
2782
+
2783
+ def _refold_parse_tree(parse_tree, *, policy):
2784
+ """Return string of contents of parse_tree folded according to RFC rules.
2785
+
2786
+ """
2787
+ # max_line_length 0/None means no limit, ie: infinitely long.
2788
+ maxlen = policy.max_line_length or sys.maxsize
2789
+ encoding = 'utf-8' if policy.utf8 else 'us-ascii'
2790
+ lines = [''] # Folded lines to be output
2791
+ leading_whitespace = '' # When we have whitespace between two encoded
2792
+ # words, we may need to encode the whitespace
2793
+ # at the beginning of the second word.
2794
+ last_ew = None # Points to the last encoded character if there's an ew on
2795
+ # the line
2796
+ last_charset = None
2797
+ wrap_as_ew_blocked = 0
2798
+ want_encoding = False # This is set to True if we need to encode this part
2799
+ end_ew_not_allowed = Terminal('', 'wrap_as_ew_blocked')
2800
+ parts = list(parse_tree)
2801
+ while parts:
2802
+ part = parts.pop(0)
2803
+ if part is end_ew_not_allowed:
2804
+ wrap_as_ew_blocked -= 1
2805
+ continue
2806
+ tstr = str(part)
2807
+ if not want_encoding:
2808
+ if part.token_type == 'ptext':
2809
+ # Encode if tstr contains special characters.
2810
+ want_encoding = not SPECIALSNL.isdisjoint(tstr)
2811
+ else:
2812
+ # Encode if tstr contains newlines.
2813
+ want_encoding = not NLSET.isdisjoint(tstr)
2814
+ try:
2815
+ tstr.encode(encoding)
2816
+ charset = encoding
2817
+ except UnicodeEncodeError:
2818
+ if any(isinstance(x, errors.UndecodableBytesDefect)
2819
+ for x in part.all_defects):
2820
+ charset = 'unknown-8bit'
2821
+ else:
2822
+ # If policy.utf8 is false this should really be taken from a
2823
+ # 'charset' property on the policy.
2824
+ charset = 'utf-8'
2825
+ want_encoding = True
2826
+
2827
+ if part.token_type == 'mime-parameters':
2828
+ # Mime parameter folding (using RFC2231) is extra special.
2829
+ _fold_mime_parameters(part, lines, maxlen, encoding)
2830
+ continue
2831
+
2832
+ if want_encoding and not wrap_as_ew_blocked:
2833
+ if not part.as_ew_allowed:
2834
+ want_encoding = False
2835
+ last_ew = None
2836
+ if part.syntactic_break:
2837
+ encoded_part = part.fold(policy=policy)[:-len(policy.linesep)]
2838
+ if policy.linesep not in encoded_part:
2839
+ # It fits on a single line
2840
+ if len(encoded_part) > maxlen - len(lines[-1]):
2841
+ # But not on this one, so start a new one.
2842
+ newline = _steal_trailing_WSP_if_exists(lines)
2843
+ # XXX what if encoded_part has no leading FWS?
2844
+ lines.append(newline)
2845
+ lines[-1] += encoded_part
2846
+ continue
2847
+ # Either this is not a major syntactic break, so we don't
2848
+ # want it on a line by itself even if it fits, or it
2849
+ # doesn't fit on a line by itself. Either way, fall through
2850
+ # to unpacking the subparts and wrapping them.
2851
+ if not hasattr(part, 'encode'):
2852
+ # It's not a Terminal, do each piece individually.
2853
+ parts = list(part) + parts
2854
+ want_encoding = False
2855
+ continue
2856
+ elif part.as_ew_allowed:
2857
+ # It's a terminal, wrap it as an encoded word, possibly
2858
+ # combining it with previously encoded words if allowed.
2859
+ if (last_ew is not None and
2860
+ charset != last_charset and
2861
+ (last_charset == 'unknown-8bit' or
2862
+ last_charset == 'utf-8' and charset != 'us-ascii')):
2863
+ last_ew = None
2864
+ last_ew = _fold_as_ew(tstr, lines, maxlen, last_ew,
2865
+ part.ew_combine_allowed, charset, leading_whitespace)
2866
+ # This whitespace has been added to the lines in _fold_as_ew()
2867
+ # so clear it now.
2868
+ leading_whitespace = ''
2869
+ last_charset = charset
2870
+ want_encoding = False
2871
+ continue
2872
+ else:
2873
+ # It's a terminal which should be kept non-encoded
2874
+ # (e.g. a ListSeparator).
2875
+ last_ew = None
2876
+ want_encoding = False
2877
+ # fall through
2878
+
2879
+ if len(tstr) <= maxlen - len(lines[-1]):
2880
+ lines[-1] += tstr
2881
+ continue
2882
+
2883
+ # This part is too long to fit. The RFC wants us to break at
2884
+ # "major syntactic breaks", so unless we don't consider this
2885
+ # to be one, check if it will fit on the next line by itself.
2886
+ leading_whitespace = ''
2887
+ if (part.syntactic_break and
2888
+ len(tstr) + 1 <= maxlen):
2889
+ newline = _steal_trailing_WSP_if_exists(lines)
2890
+ if newline or part.startswith_fws():
2891
+ # We're going to fold the data onto a new line here. Due to
2892
+ # the way encoded strings handle continuation lines, we need to
2893
+ # be prepared to encode any whitespace if the next line turns
2894
+ # out to start with an encoded word.
2895
+ lines.append(newline + tstr)
2896
+
2897
+ whitespace_accumulator = []
2898
+ for char in lines[-1]:
2899
+ if char not in WSP:
2900
+ break
2901
+ whitespace_accumulator.append(char)
2902
+ leading_whitespace = ''.join(whitespace_accumulator)
2903
+ last_ew = None
2904
+ continue
2905
+ if not hasattr(part, 'encode'):
2906
+ # It's not a terminal, try folding the subparts.
2907
+ newparts = list(part)
2908
+ if not part.as_ew_allowed:
2909
+ wrap_as_ew_blocked += 1
2910
+ newparts.append(end_ew_not_allowed)
2911
+ parts = newparts + parts
2912
+ continue
2913
+ if part.as_ew_allowed and not wrap_as_ew_blocked:
2914
+ # It doesn't need CTE encoding, but encode it anyway so we can
2915
+ # wrap it.
2916
+ parts.insert(0, part)
2917
+ want_encoding = True
2918
+ continue
2919
+ # We can't figure out how to wrap, it, so give up.
2920
+ newline = _steal_trailing_WSP_if_exists(lines)
2921
+ if newline or part.startswith_fws():
2922
+ lines.append(newline + tstr)
2923
+ else:
2924
+ # We can't fold it onto the next line either...
2925
+ lines[-1] += tstr
2926
+
2927
+ return policy.linesep.join(lines) + policy.linesep
2928
+
2929
+ def _fold_as_ew(to_encode, lines, maxlen, last_ew, ew_combine_allowed, charset, leading_whitespace):
2930
+ """Fold string to_encode into lines as encoded word, combining if allowed.
2931
+ Return the new value for last_ew, or None if ew_combine_allowed is False.
2932
+
2933
+ If there is already an encoded word in the last line of lines (indicated by
2934
+ a non-None value for last_ew) and ew_combine_allowed is true, decode the
2935
+ existing ew, combine it with to_encode, and re-encode. Otherwise, encode
2936
+ to_encode. In either case, split to_encode as necessary so that the
2937
+ encoded segments fit within maxlen.
2938
+
2939
+ """
2940
+ if last_ew is not None and ew_combine_allowed:
2941
+ to_encode = str(
2942
+ get_unstructured(lines[-1][last_ew:] + to_encode))
2943
+ lines[-1] = lines[-1][:last_ew]
2944
+ elif to_encode[0] in WSP:
2945
+ # We're joining this to non-encoded text, so don't encode
2946
+ # the leading blank.
2947
+ leading_wsp = to_encode[0]
2948
+ to_encode = to_encode[1:]
2949
+ if (len(lines[-1]) == maxlen):
2950
+ lines.append(_steal_trailing_WSP_if_exists(lines))
2951
+ lines[-1] += leading_wsp
2952
+
2953
+ trailing_wsp = ''
2954
+ if to_encode[-1] in WSP:
2955
+ # Likewise for the trailing space.
2956
+ trailing_wsp = to_encode[-1]
2957
+ to_encode = to_encode[:-1]
2958
+ new_last_ew = len(lines[-1]) if last_ew is None else last_ew
2959
+
2960
+ encode_as = 'utf-8' if charset == 'us-ascii' else charset
2961
+
2962
+ # The RFC2047 chrome takes up 7 characters plus the length
2963
+ # of the charset name.
2964
+ chrome_len = len(encode_as) + 7
2965
+
2966
+ if (chrome_len + 1) >= maxlen:
2967
+ raise errors.HeaderParseError(
2968
+ "max_line_length is too small to fit an encoded word")
2969
+
2970
+ while to_encode:
2971
+ remaining_space = maxlen - len(lines[-1])
2972
+ text_space = remaining_space - chrome_len - len(leading_whitespace)
2973
+ if text_space <= 0:
2974
+ lines.append(' ')
2975
+ continue
2976
+
2977
+ # If we are at the start of a continuation line, prepend whitespace
2978
+ # (we only want to do this when the line starts with an encoded word
2979
+ # but if we're folding in this helper function, then we know that we
2980
+ # are going to be writing out an encoded word.)
2981
+ if len(lines) > 1 and len(lines[-1]) == 1 and leading_whitespace:
2982
+ encoded_word = _ew.encode(leading_whitespace, charset=encode_as)
2983
+ lines[-1] += encoded_word
2984
+ leading_whitespace = ''
2985
+
2986
+ to_encode_word = to_encode[:text_space]
2987
+ encoded_word = _ew.encode(to_encode_word, charset=encode_as)
2988
+ excess = len(encoded_word) - remaining_space
2989
+ while excess > 0:
2990
+ # Since the chunk to encode is guaranteed to fit into less than 100 characters,
2991
+ # shrinking it by one at a time shouldn't take long.
2992
+ to_encode_word = to_encode_word[:-1]
2993
+ encoded_word = _ew.encode(to_encode_word, charset=encode_as)
2994
+ excess = len(encoded_word) - remaining_space
2995
+ lines[-1] += encoded_word
2996
+ to_encode = to_encode[len(to_encode_word):]
2997
+ leading_whitespace = ''
2998
+
2999
+ if to_encode:
3000
+ lines.append(' ')
3001
+ new_last_ew = len(lines[-1])
3002
+ lines[-1] += trailing_wsp
3003
+ return new_last_ew if ew_combine_allowed else None
3004
+
3005
+ def _fold_mime_parameters(part, lines, maxlen, encoding):
3006
+ """Fold TokenList 'part' into the 'lines' list as mime parameters.
3007
+
3008
+ Using the decoded list of parameters and values, format them according to
3009
+ the RFC rules, including using RFC2231 encoding if the value cannot be
3010
+ expressed in 'encoding' and/or the parameter+value is too long to fit
3011
+ within 'maxlen'.
3012
+
3013
+ """
3014
+ # Special case for RFC2231 encoding: start from decoded values and use
3015
+ # RFC2231 encoding iff needed.
3016
+ #
3017
+ # Note that the 1 and 2s being added to the length calculations are
3018
+ # accounting for the possibly-needed spaces and semicolons we'll be adding.
3019
+ #
3020
+ for name, value in part.params:
3021
+ # XXX What if this ';' puts us over maxlen the first time through the
3022
+ # loop? We should split the header value onto a newline in that case,
3023
+ # but to do that we need to recognize the need earlier or reparse the
3024
+ # header, so I'm going to ignore that bug for now. It'll only put us
3025
+ # one character over.
3026
+ if not lines[-1].rstrip().endswith(';'):
3027
+ lines[-1] += ';'
3028
+ charset = encoding
3029
+ error_handler = 'strict'
3030
+ try:
3031
+ value.encode(encoding)
3032
+ encoding_required = False
3033
+ except UnicodeEncodeError:
3034
+ encoding_required = True
3035
+ if utils._has_surrogates(value):
3036
+ charset = 'unknown-8bit'
3037
+ error_handler = 'surrogateescape'
3038
+ else:
3039
+ charset = 'utf-8'
3040
+ if encoding_required:
3041
+ encoded_value = urllib.parse.quote(
3042
+ value, safe='', errors=error_handler)
3043
+ tstr = "{}*={}''{}".format(name, charset, encoded_value)
3044
+ else:
3045
+ tstr = '{}={}'.format(name, quote_string(value))
3046
+ if len(lines[-1]) + len(tstr) + 1 < maxlen:
3047
+ lines[-1] = lines[-1] + ' ' + tstr
3048
+ continue
3049
+ elif len(tstr) + 2 <= maxlen:
3050
+ lines.append(' ' + tstr)
3051
+ continue
3052
+ # We need multiple sections. We are allowed to mix encoded and
3053
+ # non-encoded sections, but we aren't going to. We'll encode them all.
3054
+ section = 0
3055
+ extra_chrome = charset + "''"
3056
+ while value:
3057
+ chrome_len = len(name) + len(str(section)) + 3 + len(extra_chrome)
3058
+ if maxlen <= chrome_len + 3:
3059
+ # We need room for the leading blank, the trailing semicolon,
3060
+ # and at least one character of the value. If we don't
3061
+ # have that, we'd be stuck, so in that case fall back to
3062
+ # the RFC standard width.
3063
+ maxlen = 78
3064
+ splitpoint = maxchars = maxlen - chrome_len - 2
3065
+ while True:
3066
+ partial = value[:splitpoint]
3067
+ encoded_value = urllib.parse.quote(
3068
+ partial, safe='', errors=error_handler)
3069
+ if len(encoded_value) <= maxchars:
3070
+ break
3071
+ splitpoint -= 1
3072
+ lines.append(" {}*{}*={}{}".format(
3073
+ name, section, extra_chrome, encoded_value))
3074
+ extra_chrome = ''
3075
+ section += 1
3076
+ value = value[splitpoint:]
3077
+ if value:
3078
+ lines[-1] += ';'