@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,3426 @@
1
+ """Get useful information from live Python objects.
2
+
3
+ This module encapsulates the interface provided by the internal special
4
+ attributes (co_*, im_*, tb_*, etc.) in a friendlier fashion.
5
+ It also provides some help for examining source code and class layout.
6
+
7
+ Here are some of the useful functions provided by this module:
8
+
9
+ ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(),
10
+ isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(),
11
+ isroutine() - check object types
12
+ getmembers() - get members of an object that satisfy a given condition
13
+
14
+ getfile(), getsourcefile(), getsource() - find an object's source code
15
+ getdoc(), getcomments() - get documentation on an object
16
+ getmodule() - determine the module that an object came from
17
+ getclasstree() - arrange classes so as to represent their hierarchy
18
+
19
+ getargvalues(), getcallargs() - get info about function arguments
20
+ getfullargspec() - same, with support for Python 3 features
21
+ formatargvalues() - format an argument spec
22
+ getouterframes(), getinnerframes() - get info about frames
23
+ currentframe() - get the current stack frame
24
+ stack(), trace() - get info about frames on the stack or in a traceback
25
+
26
+ signature() - get a Signature object for the callable
27
+
28
+ get_annotations() - safely compute an object's annotations
29
+ """
30
+
31
+ # This module is in the public domain. No warranties.
32
+
33
+ __author__ = ('Ka-Ping Yee <ping@lfw.org>',
34
+ 'Yury Selivanov <yselivanov@sprymix.com>')
35
+
36
+ __all__ = [
37
+ "AGEN_CLOSED",
38
+ "AGEN_CREATED",
39
+ "AGEN_RUNNING",
40
+ "AGEN_SUSPENDED",
41
+ "ArgInfo",
42
+ "Arguments",
43
+ "Attribute",
44
+ "BlockFinder",
45
+ "BoundArguments",
46
+ "BufferFlags",
47
+ "CORO_CLOSED",
48
+ "CORO_CREATED",
49
+ "CORO_RUNNING",
50
+ "CORO_SUSPENDED",
51
+ "CO_ASYNC_GENERATOR",
52
+ "CO_COROUTINE",
53
+ "CO_GENERATOR",
54
+ "CO_ITERABLE_COROUTINE",
55
+ "CO_NESTED",
56
+ "CO_NEWLOCALS",
57
+ "CO_NOFREE",
58
+ "CO_OPTIMIZED",
59
+ "CO_VARARGS",
60
+ "CO_VARKEYWORDS",
61
+ "ClassFoundException",
62
+ "ClosureVars",
63
+ "EndOfBlock",
64
+ "FrameInfo",
65
+ "FullArgSpec",
66
+ "GEN_CLOSED",
67
+ "GEN_CREATED",
68
+ "GEN_RUNNING",
69
+ "GEN_SUSPENDED",
70
+ "Parameter",
71
+ "Signature",
72
+ "TPFLAGS_IS_ABSTRACT",
73
+ "Traceback",
74
+ "classify_class_attrs",
75
+ "cleandoc",
76
+ "currentframe",
77
+ "findsource",
78
+ "formatannotation",
79
+ "formatannotationrelativeto",
80
+ "formatargvalues",
81
+ "get_annotations",
82
+ "getabsfile",
83
+ "getargs",
84
+ "getargvalues",
85
+ "getasyncgenlocals",
86
+ "getasyncgenstate",
87
+ "getattr_static",
88
+ "getblock",
89
+ "getcallargs",
90
+ "getclasstree",
91
+ "getclosurevars",
92
+ "getcomments",
93
+ "getcoroutinelocals",
94
+ "getcoroutinestate",
95
+ "getdoc",
96
+ "getfile",
97
+ "getframeinfo",
98
+ "getfullargspec",
99
+ "getgeneratorlocals",
100
+ "getgeneratorstate",
101
+ "getinnerframes",
102
+ "getlineno",
103
+ "getmembers",
104
+ "getmembers_static",
105
+ "getmodule",
106
+ "getmodulename",
107
+ "getmro",
108
+ "getouterframes",
109
+ "getsource",
110
+ "getsourcefile",
111
+ "getsourcelines",
112
+ "indentsize",
113
+ "isabstract",
114
+ "isasyncgen",
115
+ "isasyncgenfunction",
116
+ "isawaitable",
117
+ "isbuiltin",
118
+ "isclass",
119
+ "iscode",
120
+ "iscoroutine",
121
+ "iscoroutinefunction",
122
+ "isdatadescriptor",
123
+ "isframe",
124
+ "isfunction",
125
+ "isgenerator",
126
+ "isgeneratorfunction",
127
+ "isgetsetdescriptor",
128
+ "ismemberdescriptor",
129
+ "ismethod",
130
+ "ismethoddescriptor",
131
+ "ismethodwrapper",
132
+ "ismodule",
133
+ "isroutine",
134
+ "istraceback",
135
+ "markcoroutinefunction",
136
+ "signature",
137
+ "stack",
138
+ "trace",
139
+ "unwrap",
140
+ "walktree",
141
+ ]
142
+
143
+
144
+ import abc
145
+ import ast
146
+ import dis
147
+ import collections.abc
148
+ import enum
149
+ import importlib.machinery
150
+ import itertools
151
+ import linecache
152
+ import os
153
+ import re
154
+ import sys
155
+ import tokenize
156
+ import token
157
+ import types
158
+ import functools
159
+ import builtins
160
+ from keyword import iskeyword
161
+ from operator import attrgetter
162
+ from collections import namedtuple, OrderedDict
163
+ from weakref import ref as make_weakref
164
+
165
+ # Create constants for the compiler flags in Include/code.h
166
+ # We try to get them from dis to avoid duplication
167
+ mod_dict = globals()
168
+ for k, v in dis.COMPILER_FLAG_NAMES.items():
169
+ mod_dict["CO_" + v] = k
170
+ del k, v, mod_dict
171
+
172
+ # See Include/object.h
173
+ TPFLAGS_IS_ABSTRACT = 1 << 20
174
+
175
+
176
+ def get_annotations(obj, *, globals=None, locals=None, eval_str=False):
177
+ """Compute the annotations dict for an object.
178
+
179
+ obj may be a callable, class, or module.
180
+ Passing in an object of any other type raises TypeError.
181
+
182
+ Returns a dict. get_annotations() returns a new dict every time
183
+ it's called; calling it twice on the same object will return two
184
+ different but equivalent dicts.
185
+
186
+ This function handles several details for you:
187
+
188
+ * If eval_str is true, values of type str will
189
+ be un-stringized using eval(). This is intended
190
+ for use with stringized annotations
191
+ ("from __future__ import annotations").
192
+ * If obj doesn't have an annotations dict, returns an
193
+ empty dict. (Functions and methods always have an
194
+ annotations dict; classes, modules, and other types of
195
+ callables may not.)
196
+ * Ignores inherited annotations on classes. If a class
197
+ doesn't have its own annotations dict, returns an empty dict.
198
+ * All accesses to object members and dict values are done
199
+ using getattr() and dict.get() for safety.
200
+ * Always, always, always returns a freshly-created dict.
201
+
202
+ eval_str controls whether or not values of type str are replaced
203
+ with the result of calling eval() on those values:
204
+
205
+ * If eval_str is true, eval() is called on values of type str.
206
+ * If eval_str is false (the default), values of type str are unchanged.
207
+
208
+ globals and locals are passed in to eval(); see the documentation
209
+ for eval() for more information. If either globals or locals is
210
+ None, this function may replace that value with a context-specific
211
+ default, contingent on type(obj):
212
+
213
+ * If obj is a module, globals defaults to obj.__dict__.
214
+ * If obj is a class, globals defaults to
215
+ sys.modules[obj.__module__].__dict__ and locals
216
+ defaults to the obj class namespace.
217
+ * If obj is a callable, globals defaults to obj.__globals__,
218
+ although if obj is a wrapped function (using
219
+ functools.update_wrapper()) it is first unwrapped.
220
+ """
221
+ if isinstance(obj, type):
222
+ # class
223
+ obj_dict = getattr(obj, '__dict__', None)
224
+ if obj_dict and hasattr(obj_dict, 'get'):
225
+ ann = obj_dict.get('__annotations__', None)
226
+ if isinstance(ann, types.GetSetDescriptorType):
227
+ ann = None
228
+ else:
229
+ ann = None
230
+
231
+ obj_globals = None
232
+ module_name = getattr(obj, '__module__', None)
233
+ if module_name:
234
+ module = sys.modules.get(module_name, None)
235
+ if module:
236
+ obj_globals = getattr(module, '__dict__', None)
237
+ obj_locals = dict(vars(obj))
238
+ unwrap = obj
239
+ elif isinstance(obj, types.ModuleType):
240
+ # module
241
+ ann = getattr(obj, '__annotations__', None)
242
+ obj_globals = getattr(obj, '__dict__')
243
+ obj_locals = None
244
+ unwrap = None
245
+ elif callable(obj):
246
+ # this includes types.Function, types.BuiltinFunctionType,
247
+ # types.BuiltinMethodType, functools.partial, functools.singledispatch,
248
+ # "class funclike" from Lib/test/test_inspect... on and on it goes.
249
+ ann = getattr(obj, '__annotations__', None)
250
+ obj_globals = getattr(obj, '__globals__', None)
251
+ obj_locals = None
252
+ unwrap = obj
253
+ else:
254
+ raise TypeError(f"{obj!r} is not a module, class, or callable.")
255
+
256
+ if ann is None:
257
+ return {}
258
+
259
+ if not isinstance(ann, dict):
260
+ raise ValueError(f"{obj!r}.__annotations__ is neither a dict nor None")
261
+
262
+ if not ann:
263
+ return {}
264
+
265
+ if not eval_str:
266
+ return dict(ann)
267
+
268
+ if unwrap is not None:
269
+ while True:
270
+ if hasattr(unwrap, '__wrapped__'):
271
+ unwrap = unwrap.__wrapped__
272
+ continue
273
+ if isinstance(unwrap, functools.partial):
274
+ unwrap = unwrap.func
275
+ continue
276
+ break
277
+ if hasattr(unwrap, "__globals__"):
278
+ obj_globals = unwrap.__globals__
279
+
280
+ if globals is None:
281
+ globals = obj_globals
282
+ if locals is None:
283
+ locals = obj_locals or {}
284
+
285
+ # "Inject" type parameters into the local namespace
286
+ # (unless they are shadowed by assignments *in* the local namespace),
287
+ # as a way of emulating annotation scopes when calling `eval()`
288
+ if type_params := getattr(obj, "__type_params__", ()):
289
+ locals = {param.__name__: param for param in type_params} | locals
290
+
291
+ return_value = {key:
292
+ value if not isinstance(value, str) else eval(value, globals, locals)
293
+ for key, value in ann.items() }
294
+ return return_value
295
+
296
+
297
+ # ----------------------------------------------------------- type-checking
298
+ def ismodule(object):
299
+ """Return true if the object is a module."""
300
+ return isinstance(object, types.ModuleType)
301
+
302
+ def isclass(object):
303
+ """Return true if the object is a class."""
304
+ return isinstance(object, type)
305
+
306
+ def ismethod(object):
307
+ """Return true if the object is an instance method."""
308
+ return isinstance(object, types.MethodType)
309
+
310
+ def ismethoddescriptor(object):
311
+ """Return true if the object is a method descriptor.
312
+
313
+ But not if ismethod() or isclass() or isfunction() are true.
314
+
315
+ This is new in Python 2.2, and, for example, is true of int.__add__.
316
+ An object passing this test has a __get__ attribute but not a __set__
317
+ attribute, but beyond that the set of attributes varies. __name__ is
318
+ usually sensible, and __doc__ often is.
319
+
320
+ Methods implemented via descriptors that also pass one of the other
321
+ tests return false from the ismethoddescriptor() test, simply because
322
+ the other tests promise more -- you can, e.g., count on having the
323
+ __func__ attribute (etc) when an object passes ismethod()."""
324
+ if isclass(object) or ismethod(object) or isfunction(object):
325
+ # mutual exclusion
326
+ return False
327
+ tp = type(object)
328
+ return hasattr(tp, "__get__") and not hasattr(tp, "__set__")
329
+
330
+ def isdatadescriptor(object):
331
+ """Return true if the object is a data descriptor.
332
+
333
+ Data descriptors have a __set__ or a __delete__ attribute. Examples are
334
+ properties (defined in Python) and getsets and members (defined in C).
335
+ Typically, data descriptors will also have __name__ and __doc__ attributes
336
+ (properties, getsets, and members have both of these attributes), but this
337
+ is not guaranteed."""
338
+ if isclass(object) or ismethod(object) or isfunction(object):
339
+ # mutual exclusion
340
+ return False
341
+ tp = type(object)
342
+ return hasattr(tp, "__set__") or hasattr(tp, "__delete__")
343
+
344
+ if hasattr(types, 'MemberDescriptorType'):
345
+ # CPython and equivalent
346
+ def ismemberdescriptor(object):
347
+ """Return true if the object is a member descriptor.
348
+
349
+ Member descriptors are specialized descriptors defined in extension
350
+ modules."""
351
+ return isinstance(object, types.MemberDescriptorType)
352
+ else:
353
+ # Other implementations
354
+ def ismemberdescriptor(object):
355
+ """Return true if the object is a member descriptor.
356
+
357
+ Member descriptors are specialized descriptors defined in extension
358
+ modules."""
359
+ return False
360
+
361
+ if hasattr(types, 'GetSetDescriptorType'):
362
+ # CPython and equivalent
363
+ def isgetsetdescriptor(object):
364
+ """Return true if the object is a getset descriptor.
365
+
366
+ getset descriptors are specialized descriptors defined in extension
367
+ modules."""
368
+ return isinstance(object, types.GetSetDescriptorType)
369
+ else:
370
+ # Other implementations
371
+ def isgetsetdescriptor(object):
372
+ """Return true if the object is a getset descriptor.
373
+
374
+ getset descriptors are specialized descriptors defined in extension
375
+ modules."""
376
+ return False
377
+
378
+ def isfunction(object):
379
+ """Return true if the object is a user-defined function.
380
+
381
+ Function objects provide these attributes:
382
+ __doc__ documentation string
383
+ __name__ name with which this function was defined
384
+ __code__ code object containing compiled function bytecode
385
+ __defaults__ tuple of any default values for arguments
386
+ __globals__ global namespace in which this function was defined
387
+ __annotations__ dict of parameter annotations
388
+ __kwdefaults__ dict of keyword only parameters with defaults"""
389
+ return isinstance(object, types.FunctionType)
390
+
391
+ def _has_code_flag(f, flag):
392
+ """Return true if ``f`` is a function (or a method or functools.partial
393
+ wrapper wrapping a function) whose code object has the given ``flag``
394
+ set in its flags."""
395
+ while ismethod(f):
396
+ f = f.__func__
397
+ f = functools._unwrap_partial(f)
398
+ if not (isfunction(f) or _signature_is_functionlike(f)):
399
+ return False
400
+ return bool(f.__code__.co_flags & flag)
401
+
402
+ def isgeneratorfunction(obj):
403
+ """Return true if the object is a user-defined generator function.
404
+
405
+ Generator function objects provide the same attributes as functions.
406
+ See help(isfunction) for a list of attributes."""
407
+ return _has_code_flag(obj, CO_GENERATOR)
408
+
409
+ # A marker for markcoroutinefunction and iscoroutinefunction.
410
+ _is_coroutine_mark = object()
411
+
412
+ def _has_coroutine_mark(f):
413
+ while ismethod(f):
414
+ f = f.__func__
415
+ f = functools._unwrap_partial(f)
416
+ return getattr(f, "_is_coroutine_marker", None) is _is_coroutine_mark
417
+
418
+ def markcoroutinefunction(func):
419
+ """
420
+ Decorator to ensure callable is recognised as a coroutine function.
421
+ """
422
+ if hasattr(func, '__func__'):
423
+ func = func.__func__
424
+ func._is_coroutine_marker = _is_coroutine_mark
425
+ return func
426
+
427
+ def iscoroutinefunction(obj):
428
+ """Return true if the object is a coroutine function.
429
+
430
+ Coroutine functions are normally defined with "async def" syntax, but may
431
+ be marked via markcoroutinefunction.
432
+ """
433
+ return _has_code_flag(obj, CO_COROUTINE) or _has_coroutine_mark(obj)
434
+
435
+ def isasyncgenfunction(obj):
436
+ """Return true if the object is an asynchronous generator function.
437
+
438
+ Asynchronous generator functions are defined with "async def"
439
+ syntax and have "yield" expressions in their body.
440
+ """
441
+ return _has_code_flag(obj, CO_ASYNC_GENERATOR)
442
+
443
+ def isasyncgen(object):
444
+ """Return true if the object is an asynchronous generator."""
445
+ return isinstance(object, types.AsyncGeneratorType)
446
+
447
+ def isgenerator(object):
448
+ """Return true if the object is a generator.
449
+
450
+ Generator objects provide these attributes:
451
+ __iter__ defined to support iteration over container
452
+ close raises a new GeneratorExit exception inside the
453
+ generator to terminate the iteration
454
+ gi_code code object
455
+ gi_frame frame object or possibly None once the generator has
456
+ been exhausted
457
+ gi_running set to 1 when generator is executing, 0 otherwise
458
+ next return the next item from the container
459
+ send resumes the generator and "sends" a value that becomes
460
+ the result of the current yield-expression
461
+ throw used to raise an exception inside the generator"""
462
+ return isinstance(object, types.GeneratorType)
463
+
464
+ def iscoroutine(object):
465
+ """Return true if the object is a coroutine."""
466
+ return isinstance(object, types.CoroutineType)
467
+
468
+ def isawaitable(object):
469
+ """Return true if object can be passed to an ``await`` expression."""
470
+ return (isinstance(object, types.CoroutineType) or
471
+ isinstance(object, types.GeneratorType) and
472
+ bool(object.gi_code.co_flags & CO_ITERABLE_COROUTINE) or
473
+ isinstance(object, collections.abc.Awaitable))
474
+
475
+ def istraceback(object):
476
+ """Return true if the object is a traceback.
477
+
478
+ Traceback objects provide these attributes:
479
+ tb_frame frame object at this level
480
+ tb_lasti index of last attempted instruction in bytecode
481
+ tb_lineno current line number in Python source code
482
+ tb_next next inner traceback object (called by this level)"""
483
+ return isinstance(object, types.TracebackType)
484
+
485
+ def isframe(object):
486
+ """Return true if the object is a frame object.
487
+
488
+ Frame objects provide these attributes:
489
+ f_back next outer frame object (this frame's caller)
490
+ f_builtins built-in namespace seen by this frame
491
+ f_code code object being executed in this frame
492
+ f_globals global namespace seen by this frame
493
+ f_lasti index of last attempted instruction in bytecode
494
+ f_lineno current line number in Python source code
495
+ f_locals local namespace seen by this frame
496
+ f_trace tracing function for this frame, or None"""
497
+ return isinstance(object, types.FrameType)
498
+
499
+ def iscode(object):
500
+ """Return true if the object is a code object.
501
+
502
+ Code objects provide these attributes:
503
+ co_argcount number of arguments (not including *, ** args
504
+ or keyword only arguments)
505
+ co_code string of raw compiled bytecode
506
+ co_cellvars tuple of names of cell variables
507
+ co_consts tuple of constants used in the bytecode
508
+ co_filename name of file in which this code object was created
509
+ co_firstlineno number of first line in Python source code
510
+ co_flags bitmap: 1=optimized | 2=newlocals | 4=*arg | 8=**arg
511
+ | 16=nested | 32=generator | 64=nofree | 128=coroutine
512
+ | 256=iterable_coroutine | 512=async_generator
513
+ co_freevars tuple of names of free variables
514
+ co_posonlyargcount number of positional only arguments
515
+ co_kwonlyargcount number of keyword only arguments (not including ** arg)
516
+ co_lnotab encoded mapping of line numbers to bytecode indices
517
+ co_name name with which this code object was defined
518
+ co_names tuple of names other than arguments and function locals
519
+ co_nlocals number of local variables
520
+ co_stacksize virtual machine stack space required
521
+ co_varnames tuple of names of arguments and local variables"""
522
+ return isinstance(object, types.CodeType)
523
+
524
+ def isbuiltin(object):
525
+ """Return true if the object is a built-in function or method.
526
+
527
+ Built-in functions and methods provide these attributes:
528
+ __doc__ documentation string
529
+ __name__ original name of this function or method
530
+ __self__ instance to which a method is bound, or None"""
531
+ return isinstance(object, types.BuiltinFunctionType)
532
+
533
+ def ismethodwrapper(object):
534
+ """Return true if the object is a method wrapper."""
535
+ return isinstance(object, types.MethodWrapperType)
536
+
537
+ def isroutine(object):
538
+ """Return true if the object is any kind of function or method."""
539
+ return (isbuiltin(object)
540
+ or isfunction(object)
541
+ or ismethod(object)
542
+ or ismethoddescriptor(object)
543
+ or ismethodwrapper(object))
544
+
545
+ def isabstract(object):
546
+ """Return true if the object is an abstract base class (ABC)."""
547
+ if not isinstance(object, type):
548
+ return False
549
+ if object.__flags__ & TPFLAGS_IS_ABSTRACT:
550
+ return True
551
+ if not issubclass(type(object), abc.ABCMeta):
552
+ return False
553
+ if hasattr(object, '__abstractmethods__'):
554
+ # It looks like ABCMeta.__new__ has finished running;
555
+ # TPFLAGS_IS_ABSTRACT should have been accurate.
556
+ return False
557
+ # It looks like ABCMeta.__new__ has not finished running yet; we're
558
+ # probably in __init_subclass__. We'll look for abstractmethods manually.
559
+ for name, value in object.__dict__.items():
560
+ if getattr(value, "__isabstractmethod__", False):
561
+ return True
562
+ for base in object.__bases__:
563
+ for name in getattr(base, "__abstractmethods__", ()):
564
+ value = getattr(object, name, None)
565
+ if getattr(value, "__isabstractmethod__", False):
566
+ return True
567
+ return False
568
+
569
+ def _getmembers(object, predicate, getter):
570
+ results = []
571
+ processed = set()
572
+ names = dir(object)
573
+ if isclass(object):
574
+ mro = getmro(object)
575
+ # add any DynamicClassAttributes to the list of names if object is a class;
576
+ # this may result in duplicate entries if, for example, a virtual
577
+ # attribute with the same name as a DynamicClassAttribute exists
578
+ try:
579
+ for base in object.__bases__:
580
+ for k, v in base.__dict__.items():
581
+ if isinstance(v, types.DynamicClassAttribute):
582
+ names.append(k)
583
+ except AttributeError:
584
+ pass
585
+ else:
586
+ mro = ()
587
+ for key in names:
588
+ # First try to get the value via getattr. Some descriptors don't
589
+ # like calling their __get__ (see bug #1785), so fall back to
590
+ # looking in the __dict__.
591
+ try:
592
+ value = getter(object, key)
593
+ # handle the duplicate key
594
+ if key in processed:
595
+ raise AttributeError
596
+ except AttributeError:
597
+ for base in mro:
598
+ if key in base.__dict__:
599
+ value = base.__dict__[key]
600
+ break
601
+ else:
602
+ # could be a (currently) missing slot member, or a buggy
603
+ # __dir__; discard and move on
604
+ continue
605
+ if not predicate or predicate(value):
606
+ results.append((key, value))
607
+ processed.add(key)
608
+ results.sort(key=lambda pair: pair[0])
609
+ return results
610
+
611
+ def getmembers(object, predicate=None):
612
+ """Return all members of an object as (name, value) pairs sorted by name.
613
+ Optionally, only return members that satisfy a given predicate."""
614
+ return _getmembers(object, predicate, getattr)
615
+
616
+ def getmembers_static(object, predicate=None):
617
+ """Return all members of an object as (name, value) pairs sorted by name
618
+ without triggering dynamic lookup via the descriptor protocol,
619
+ __getattr__ or __getattribute__. Optionally, only return members that
620
+ satisfy a given predicate.
621
+
622
+ Note: this function may not be able to retrieve all members
623
+ that getmembers can fetch (like dynamically created attributes)
624
+ and may find members that getmembers can't (like descriptors
625
+ that raise AttributeError). It can also return descriptor objects
626
+ instead of instance members in some cases.
627
+ """
628
+ return _getmembers(object, predicate, getattr_static)
629
+
630
+ Attribute = namedtuple('Attribute', 'name kind defining_class object')
631
+
632
+ def classify_class_attrs(cls):
633
+ """Return list of attribute-descriptor tuples.
634
+
635
+ For each name in dir(cls), the return list contains a 4-tuple
636
+ with these elements:
637
+
638
+ 0. The name (a string).
639
+
640
+ 1. The kind of attribute this is, one of these strings:
641
+ 'class method' created via classmethod()
642
+ 'static method' created via staticmethod()
643
+ 'property' created via property()
644
+ 'method' any other flavor of method or descriptor
645
+ 'data' not a method
646
+
647
+ 2. The class which defined this attribute (a class).
648
+
649
+ 3. The object as obtained by calling getattr; if this fails, or if the
650
+ resulting object does not live anywhere in the class' mro (including
651
+ metaclasses) then the object is looked up in the defining class's
652
+ dict (found by walking the mro).
653
+
654
+ If one of the items in dir(cls) is stored in the metaclass it will now
655
+ be discovered and not have None be listed as the class in which it was
656
+ defined. Any items whose home class cannot be discovered are skipped.
657
+ """
658
+
659
+ mro = getmro(cls)
660
+ metamro = getmro(type(cls)) # for attributes stored in the metaclass
661
+ metamro = tuple(cls for cls in metamro if cls not in (type, object))
662
+ class_bases = (cls,) + mro
663
+ all_bases = class_bases + metamro
664
+ names = dir(cls)
665
+ # :dd any DynamicClassAttributes to the list of names;
666
+ # this may result in duplicate entries if, for example, a virtual
667
+ # attribute with the same name as a DynamicClassAttribute exists.
668
+ for base in mro:
669
+ for k, v in base.__dict__.items():
670
+ if isinstance(v, types.DynamicClassAttribute) and v.fget is not None:
671
+ names.append(k)
672
+ result = []
673
+ processed = set()
674
+
675
+ for name in names:
676
+ # Get the object associated with the name, and where it was defined.
677
+ # Normal objects will be looked up with both getattr and directly in
678
+ # its class' dict (in case getattr fails [bug #1785], and also to look
679
+ # for a docstring).
680
+ # For DynamicClassAttributes on the second pass we only look in the
681
+ # class's dict.
682
+ #
683
+ # Getting an obj from the __dict__ sometimes reveals more than
684
+ # using getattr. Static and class methods are dramatic examples.
685
+ homecls = None
686
+ get_obj = None
687
+ dict_obj = None
688
+ if name not in processed:
689
+ try:
690
+ if name == '__dict__':
691
+ raise Exception("__dict__ is special, don't want the proxy")
692
+ get_obj = getattr(cls, name)
693
+ except Exception:
694
+ pass
695
+ else:
696
+ homecls = getattr(get_obj, "__objclass__", homecls)
697
+ if homecls not in class_bases:
698
+ # if the resulting object does not live somewhere in the
699
+ # mro, drop it and search the mro manually
700
+ homecls = None
701
+ last_cls = None
702
+ # first look in the classes
703
+ for srch_cls in class_bases:
704
+ srch_obj = getattr(srch_cls, name, None)
705
+ if srch_obj is get_obj:
706
+ last_cls = srch_cls
707
+ # then check the metaclasses
708
+ for srch_cls in metamro:
709
+ try:
710
+ srch_obj = srch_cls.__getattr__(cls, name)
711
+ except AttributeError:
712
+ continue
713
+ if srch_obj is get_obj:
714
+ last_cls = srch_cls
715
+ if last_cls is not None:
716
+ homecls = last_cls
717
+ for base in all_bases:
718
+ if name in base.__dict__:
719
+ dict_obj = base.__dict__[name]
720
+ if homecls not in metamro:
721
+ homecls = base
722
+ break
723
+ if homecls is None:
724
+ # unable to locate the attribute anywhere, most likely due to
725
+ # buggy custom __dir__; discard and move on
726
+ continue
727
+ obj = get_obj if get_obj is not None else dict_obj
728
+ # Classify the object or its descriptor.
729
+ if isinstance(dict_obj, (staticmethod, types.BuiltinMethodType)):
730
+ kind = "static method"
731
+ obj = dict_obj
732
+ elif isinstance(dict_obj, (classmethod, types.ClassMethodDescriptorType)):
733
+ kind = "class method"
734
+ obj = dict_obj
735
+ elif isinstance(dict_obj, property):
736
+ kind = "property"
737
+ obj = dict_obj
738
+ elif isroutine(obj):
739
+ kind = "method"
740
+ else:
741
+ kind = "data"
742
+ result.append(Attribute(name, kind, homecls, obj))
743
+ processed.add(name)
744
+ return result
745
+
746
+ # ----------------------------------------------------------- class helpers
747
+
748
+ def getmro(cls):
749
+ "Return tuple of base classes (including cls) in method resolution order."
750
+ return cls.__mro__
751
+
752
+ # -------------------------------------------------------- function helpers
753
+
754
+ def unwrap(func, *, stop=None):
755
+ """Get the object wrapped by *func*.
756
+
757
+ Follows the chain of :attr:`__wrapped__` attributes returning the last
758
+ object in the chain.
759
+
760
+ *stop* is an optional callback accepting an object in the wrapper chain
761
+ as its sole argument that allows the unwrapping to be terminated early if
762
+ the callback returns a true value. If the callback never returns a true
763
+ value, the last object in the chain is returned as usual. For example,
764
+ :func:`signature` uses this to stop unwrapping if any object in the
765
+ chain has a ``__signature__`` attribute defined.
766
+
767
+ :exc:`ValueError` is raised if a cycle is encountered.
768
+
769
+ """
770
+ f = func # remember the original func for error reporting
771
+ # Memoise by id to tolerate non-hashable objects, but store objects to
772
+ # ensure they aren't destroyed, which would allow their IDs to be reused.
773
+ memo = {id(f): f}
774
+ recursion_limit = sys.getrecursionlimit()
775
+ while not isinstance(func, type) and hasattr(func, '__wrapped__'):
776
+ if stop is not None and stop(func):
777
+ break
778
+ func = func.__wrapped__
779
+ id_func = id(func)
780
+ if (id_func in memo) or (len(memo) >= recursion_limit):
781
+ raise ValueError('wrapper loop when unwrapping {!r}'.format(f))
782
+ memo[id_func] = func
783
+ return func
784
+
785
+ # -------------------------------------------------- source code extraction
786
+ def indentsize(line):
787
+ """Return the indent size, in spaces, at the start of a line of text."""
788
+ expline = line.expandtabs()
789
+ return len(expline) - len(expline.lstrip())
790
+
791
+ def _findclass(func):
792
+ cls = sys.modules.get(func.__module__)
793
+ if cls is None:
794
+ return None
795
+ for name in func.__qualname__.split('.')[:-1]:
796
+ cls = getattr(cls, name)
797
+ if not isclass(cls):
798
+ return None
799
+ return cls
800
+
801
+ def _finddoc(obj):
802
+ if isclass(obj):
803
+ for base in obj.__mro__:
804
+ if base is not object:
805
+ try:
806
+ doc = base.__doc__
807
+ except AttributeError:
808
+ continue
809
+ if doc is not None:
810
+ return doc
811
+ return None
812
+
813
+ if ismethod(obj):
814
+ name = obj.__func__.__name__
815
+ self = obj.__self__
816
+ if (isclass(self) and
817
+ getattr(getattr(self, name, None), '__func__') is obj.__func__):
818
+ # classmethod
819
+ cls = self
820
+ else:
821
+ cls = self.__class__
822
+ elif isfunction(obj):
823
+ name = obj.__name__
824
+ cls = _findclass(obj)
825
+ if cls is None or getattr(cls, name) is not obj:
826
+ return None
827
+ elif isbuiltin(obj):
828
+ name = obj.__name__
829
+ self = obj.__self__
830
+ if (isclass(self) and
831
+ self.__qualname__ + '.' + name == obj.__qualname__):
832
+ # classmethod
833
+ cls = self
834
+ else:
835
+ cls = self.__class__
836
+ # Should be tested before isdatadescriptor().
837
+ elif isinstance(obj, property):
838
+ func = obj.fget
839
+ name = func.__name__
840
+ cls = _findclass(func)
841
+ if cls is None or getattr(cls, name) is not obj:
842
+ return None
843
+ elif ismethoddescriptor(obj) or isdatadescriptor(obj):
844
+ name = obj.__name__
845
+ cls = obj.__objclass__
846
+ if getattr(cls, name) is not obj:
847
+ return None
848
+ if ismemberdescriptor(obj):
849
+ slots = getattr(cls, '__slots__', None)
850
+ if isinstance(slots, dict) and name in slots:
851
+ return slots[name]
852
+ else:
853
+ return None
854
+ for base in cls.__mro__:
855
+ try:
856
+ doc = getattr(base, name).__doc__
857
+ except AttributeError:
858
+ continue
859
+ if doc is not None:
860
+ return doc
861
+ return None
862
+
863
+ def getdoc(object):
864
+ """Get the documentation string for an object.
865
+
866
+ All tabs are expanded to spaces. To clean up docstrings that are
867
+ indented to line up with blocks of code, any whitespace than can be
868
+ uniformly removed from the second line onwards is removed."""
869
+ try:
870
+ doc = object.__doc__
871
+ except AttributeError:
872
+ return None
873
+ if doc is None:
874
+ try:
875
+ doc = _finddoc(object)
876
+ except (AttributeError, TypeError):
877
+ return None
878
+ if not isinstance(doc, str):
879
+ return None
880
+ return cleandoc(doc)
881
+
882
+ def cleandoc(doc):
883
+ """Clean up indentation from docstrings.
884
+
885
+ Any whitespace that can be uniformly removed from the second line
886
+ onwards is removed."""
887
+ try:
888
+ lines = doc.expandtabs().split('\n')
889
+ except UnicodeError:
890
+ return None
891
+ else:
892
+ # Find minimum indentation of any non-blank lines after first line.
893
+ margin = sys.maxsize
894
+ for line in lines[1:]:
895
+ content = len(line.lstrip())
896
+ if content:
897
+ indent = len(line) - content
898
+ margin = min(margin, indent)
899
+ # Remove indentation.
900
+ if lines:
901
+ lines[0] = lines[0].lstrip()
902
+ if margin < sys.maxsize:
903
+ for i in range(1, len(lines)): lines[i] = lines[i][margin:]
904
+ # Remove any trailing or leading blank lines.
905
+ while lines and not lines[-1]:
906
+ lines.pop()
907
+ while lines and not lines[0]:
908
+ lines.pop(0)
909
+ return '\n'.join(lines)
910
+
911
+ def getfile(object):
912
+ """Work out which source or compiled file an object was defined in."""
913
+ if ismodule(object):
914
+ if getattr(object, '__file__', None):
915
+ return object.__file__
916
+ raise TypeError('{!r} is a built-in module'.format(object))
917
+ if isclass(object):
918
+ if hasattr(object, '__module__'):
919
+ module = sys.modules.get(object.__module__)
920
+ if getattr(module, '__file__', None):
921
+ return module.__file__
922
+ if object.__module__ == '__main__':
923
+ raise OSError('source code not available')
924
+ raise TypeError('{!r} is a built-in class'.format(object))
925
+ if ismethod(object):
926
+ object = object.__func__
927
+ if isfunction(object):
928
+ object = object.__code__
929
+ if istraceback(object):
930
+ object = object.tb_frame
931
+ if isframe(object):
932
+ object = object.f_code
933
+ if iscode(object):
934
+ return object.co_filename
935
+ raise TypeError('module, class, method, function, traceback, frame, or '
936
+ 'code object was expected, got {}'.format(
937
+ type(object).__name__))
938
+
939
+ def getmodulename(path):
940
+ """Return the module name for a given file, or None."""
941
+ fname = os.path.basename(path)
942
+ # Check for paths that look like an actual module file
943
+ suffixes = [(-len(suffix), suffix)
944
+ for suffix in importlib.machinery.all_suffixes()]
945
+ suffixes.sort() # try longest suffixes first, in case they overlap
946
+ for neglen, suffix in suffixes:
947
+ if fname.endswith(suffix):
948
+ return fname[:neglen]
949
+ return None
950
+
951
+ def getsourcefile(object):
952
+ """Return the filename that can be used to locate an object's source.
953
+ Return None if no way can be identified to get the source.
954
+ """
955
+ filename = getfile(object)
956
+ all_bytecode_suffixes = importlib.machinery.DEBUG_BYTECODE_SUFFIXES[:]
957
+ all_bytecode_suffixes += importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES[:]
958
+ if any(filename.endswith(s) for s in all_bytecode_suffixes):
959
+ filename = (os.path.splitext(filename)[0] +
960
+ importlib.machinery.SOURCE_SUFFIXES[0])
961
+ elif any(filename.endswith(s) for s in
962
+ importlib.machinery.EXTENSION_SUFFIXES):
963
+ return None
964
+ # return a filename found in the linecache even if it doesn't exist on disk
965
+ if filename in linecache.cache:
966
+ return filename
967
+ if os.path.exists(filename):
968
+ return filename
969
+ # only return a non-existent filename if the module has a PEP 302 loader
970
+ module = getmodule(object, filename)
971
+ if getattr(module, '__loader__', None) is not None:
972
+ return filename
973
+ elif getattr(getattr(module, "__spec__", None), "loader", None) is not None:
974
+ return filename
975
+
976
+ def getabsfile(object, _filename=None):
977
+ """Return an absolute path to the source or compiled file for an object.
978
+
979
+ The idea is for each object to have a unique origin, so this routine
980
+ normalizes the result as much as possible."""
981
+ if _filename is None:
982
+ _filename = getsourcefile(object) or getfile(object)
983
+ return os.path.normcase(os.path.abspath(_filename))
984
+
985
+ modulesbyfile = {}
986
+ _filesbymodname = {}
987
+
988
+ def getmodule(object, _filename=None):
989
+ """Return the module an object was defined in, or None if not found."""
990
+ if ismodule(object):
991
+ return object
992
+ if hasattr(object, '__module__'):
993
+ return sys.modules.get(object.__module__)
994
+ # Try the filename to modulename cache
995
+ if _filename is not None and _filename in modulesbyfile:
996
+ return sys.modules.get(modulesbyfile[_filename])
997
+ # Try the cache again with the absolute file name
998
+ try:
999
+ file = getabsfile(object, _filename)
1000
+ except (TypeError, FileNotFoundError):
1001
+ return None
1002
+ if file in modulesbyfile:
1003
+ return sys.modules.get(modulesbyfile[file])
1004
+ # Update the filename to module name cache and check yet again
1005
+ # Copy sys.modules in order to cope with changes while iterating
1006
+ for modname, module in sys.modules.copy().items():
1007
+ if ismodule(module) and hasattr(module, '__file__'):
1008
+ f = module.__file__
1009
+ if f == _filesbymodname.get(modname, None):
1010
+ # Have already mapped this module, so skip it
1011
+ continue
1012
+ _filesbymodname[modname] = f
1013
+ f = getabsfile(module)
1014
+ # Always map to the name the module knows itself by
1015
+ modulesbyfile[f] = modulesbyfile[
1016
+ os.path.realpath(f)] = module.__name__
1017
+ if file in modulesbyfile:
1018
+ return sys.modules.get(modulesbyfile[file])
1019
+ # Check the main module
1020
+ main = sys.modules['__main__']
1021
+ if not hasattr(object, '__name__'):
1022
+ return None
1023
+ if hasattr(main, object.__name__):
1024
+ mainobject = getattr(main, object.__name__)
1025
+ if mainobject is object:
1026
+ return main
1027
+ # Check builtins
1028
+ builtin = sys.modules['builtins']
1029
+ if hasattr(builtin, object.__name__):
1030
+ builtinobject = getattr(builtin, object.__name__)
1031
+ if builtinobject is object:
1032
+ return builtin
1033
+
1034
+
1035
+ class ClassFoundException(Exception):
1036
+ pass
1037
+
1038
+
1039
+ class _ClassFinder(ast.NodeVisitor):
1040
+
1041
+ def __init__(self, qualname):
1042
+ self.stack = []
1043
+ self.qualname = qualname
1044
+
1045
+ def visit_FunctionDef(self, node):
1046
+ self.stack.append(node.name)
1047
+ self.stack.append('<locals>')
1048
+ self.generic_visit(node)
1049
+ self.stack.pop()
1050
+ self.stack.pop()
1051
+
1052
+ visit_AsyncFunctionDef = visit_FunctionDef
1053
+
1054
+ def visit_ClassDef(self, node):
1055
+ self.stack.append(node.name)
1056
+ if self.qualname == '.'.join(self.stack):
1057
+ # Return the decorator for the class if present
1058
+ if node.decorator_list:
1059
+ line_number = node.decorator_list[0].lineno
1060
+ else:
1061
+ line_number = node.lineno
1062
+
1063
+ # decrement by one since lines starts with indexing by zero
1064
+ line_number -= 1
1065
+ raise ClassFoundException(line_number)
1066
+ self.generic_visit(node)
1067
+ self.stack.pop()
1068
+
1069
+
1070
+ def findsource(object):
1071
+ """Return the entire source file and starting line number for an object.
1072
+
1073
+ The argument may be a module, class, method, function, traceback, frame,
1074
+ or code object. The source code is returned as a list of all the lines
1075
+ in the file and the line number indexes a line in that list. An OSError
1076
+ is raised if the source code cannot be retrieved."""
1077
+
1078
+ file = getsourcefile(object)
1079
+ if file:
1080
+ # Invalidate cache if needed.
1081
+ linecache.checkcache(file)
1082
+ else:
1083
+ file = getfile(object)
1084
+ # Allow filenames in form of "<something>" to pass through.
1085
+ # `doctest` monkeypatches `linecache` module to enable
1086
+ # inspection, so let `linecache.getlines` to be called.
1087
+ if not (file.startswith('<') and file.endswith('>')):
1088
+ raise OSError('source code not available')
1089
+
1090
+ module = getmodule(object, file)
1091
+ if module:
1092
+ lines = linecache.getlines(file, module.__dict__)
1093
+ else:
1094
+ lines = linecache.getlines(file)
1095
+ if not lines:
1096
+ raise OSError('could not get source code')
1097
+
1098
+ if ismodule(object):
1099
+ return lines, 0
1100
+
1101
+ if isclass(object):
1102
+ qualname = object.__qualname__
1103
+ source = ''.join(lines)
1104
+ tree = ast.parse(source)
1105
+ class_finder = _ClassFinder(qualname)
1106
+ try:
1107
+ class_finder.visit(tree)
1108
+ except ClassFoundException as e:
1109
+ line_number = e.args[0]
1110
+ return lines, line_number
1111
+ else:
1112
+ raise OSError('could not find class definition')
1113
+
1114
+ if ismethod(object):
1115
+ object = object.__func__
1116
+ if isfunction(object):
1117
+ object = object.__code__
1118
+ if istraceback(object):
1119
+ object = object.tb_frame
1120
+ if isframe(object):
1121
+ object = object.f_code
1122
+ if iscode(object):
1123
+ if not hasattr(object, 'co_firstlineno'):
1124
+ raise OSError('could not find function definition')
1125
+ lnum = object.co_firstlineno - 1
1126
+ pat = re.compile(r'^(\s*def\s)|(\s*async\s+def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)')
1127
+ while lnum > 0:
1128
+ try:
1129
+ line = lines[lnum]
1130
+ except IndexError:
1131
+ raise OSError('lineno is out of bounds')
1132
+ if pat.match(line):
1133
+ break
1134
+ lnum = lnum - 1
1135
+ return lines, lnum
1136
+ raise OSError('could not find code object')
1137
+
1138
+ def getcomments(object):
1139
+ """Get lines of comments immediately preceding an object's source code.
1140
+
1141
+ Returns None when source can't be found.
1142
+ """
1143
+ try:
1144
+ lines, lnum = findsource(object)
1145
+ except (OSError, TypeError):
1146
+ return None
1147
+
1148
+ if ismodule(object):
1149
+ # Look for a comment block at the top of the file.
1150
+ start = 0
1151
+ if lines and lines[0][:2] == '#!': start = 1
1152
+ while start < len(lines) and lines[start].strip() in ('', '#'):
1153
+ start = start + 1
1154
+ if start < len(lines) and lines[start][:1] == '#':
1155
+ comments = []
1156
+ end = start
1157
+ while end < len(lines) and lines[end][:1] == '#':
1158
+ comments.append(lines[end].expandtabs())
1159
+ end = end + 1
1160
+ return ''.join(comments)
1161
+
1162
+ # Look for a preceding block of comments at the same indentation.
1163
+ elif lnum > 0:
1164
+ indent = indentsize(lines[lnum])
1165
+ end = lnum - 1
1166
+ if end >= 0 and lines[end].lstrip()[:1] == '#' and \
1167
+ indentsize(lines[end]) == indent:
1168
+ comments = [lines[end].expandtabs().lstrip()]
1169
+ if end > 0:
1170
+ end = end - 1
1171
+ comment = lines[end].expandtabs().lstrip()
1172
+ while comment[:1] == '#' and indentsize(lines[end]) == indent:
1173
+ comments[:0] = [comment]
1174
+ end = end - 1
1175
+ if end < 0: break
1176
+ comment = lines[end].expandtabs().lstrip()
1177
+ while comments and comments[0].strip() == '#':
1178
+ comments[:1] = []
1179
+ while comments and comments[-1].strip() == '#':
1180
+ comments[-1:] = []
1181
+ return ''.join(comments)
1182
+
1183
+ class EndOfBlock(Exception): pass
1184
+
1185
+ class BlockFinder:
1186
+ """Provide a tokeneater() method to detect the end of a code block."""
1187
+ def __init__(self):
1188
+ self.indent = 0
1189
+ self.islambda = False
1190
+ self.started = False
1191
+ self.passline = False
1192
+ self.indecorator = False
1193
+ self.last = 1
1194
+ self.body_col0 = None
1195
+
1196
+ def tokeneater(self, type, token, srowcol, erowcol, line):
1197
+ if not self.started and not self.indecorator:
1198
+ # skip any decorators
1199
+ if token == "@":
1200
+ self.indecorator = True
1201
+ # look for the first "def", "class" or "lambda"
1202
+ elif token in ("def", "class", "lambda"):
1203
+ if token == "lambda":
1204
+ self.islambda = True
1205
+ self.started = True
1206
+ self.passline = True # skip to the end of the line
1207
+ elif type == tokenize.NEWLINE:
1208
+ self.passline = False # stop skipping when a NEWLINE is seen
1209
+ self.last = srowcol[0]
1210
+ if self.islambda: # lambdas always end at the first NEWLINE
1211
+ raise EndOfBlock
1212
+ # hitting a NEWLINE when in a decorator without args
1213
+ # ends the decorator
1214
+ if self.indecorator:
1215
+ self.indecorator = False
1216
+ elif self.passline:
1217
+ pass
1218
+ elif type == tokenize.INDENT:
1219
+ if self.body_col0 is None and self.started:
1220
+ self.body_col0 = erowcol[1]
1221
+ self.indent = self.indent + 1
1222
+ self.passline = True
1223
+ elif type == tokenize.DEDENT:
1224
+ self.indent = self.indent - 1
1225
+ # the end of matching indent/dedent pairs end a block
1226
+ # (note that this only works for "def"/"class" blocks,
1227
+ # not e.g. for "if: else:" or "try: finally:" blocks)
1228
+ if self.indent <= 0:
1229
+ raise EndOfBlock
1230
+ elif type == tokenize.COMMENT:
1231
+ if self.body_col0 is not None and srowcol[1] >= self.body_col0:
1232
+ # Include comments if indented at least as much as the block
1233
+ self.last = srowcol[0]
1234
+ elif self.indent == 0 and type not in (tokenize.COMMENT, tokenize.NL):
1235
+ # any other token on the same indentation level end the previous
1236
+ # block as well, except the pseudo-tokens COMMENT and NL.
1237
+ raise EndOfBlock
1238
+
1239
+ def getblock(lines):
1240
+ """Extract the block of code at the top of the given list of lines."""
1241
+ blockfinder = BlockFinder()
1242
+ try:
1243
+ tokens = tokenize.generate_tokens(iter(lines).__next__)
1244
+ for _token in tokens:
1245
+ blockfinder.tokeneater(*_token)
1246
+ except (EndOfBlock, IndentationError):
1247
+ pass
1248
+ except SyntaxError as e:
1249
+ if "unmatched" not in e.msg:
1250
+ raise e from None
1251
+ _, *_token_info = _token
1252
+ try:
1253
+ blockfinder.tokeneater(tokenize.NEWLINE, *_token_info)
1254
+ except (EndOfBlock, IndentationError):
1255
+ pass
1256
+ return lines[:blockfinder.last]
1257
+
1258
+ def getsourcelines(object):
1259
+ """Return a list of source lines and starting line number for an object.
1260
+
1261
+ The argument may be a module, class, method, function, traceback, frame,
1262
+ or code object. The source code is returned as a list of the lines
1263
+ corresponding to the object and the line number indicates where in the
1264
+ original source file the first line of code was found. An OSError is
1265
+ raised if the source code cannot be retrieved."""
1266
+ object = unwrap(object)
1267
+ lines, lnum = findsource(object)
1268
+
1269
+ if istraceback(object):
1270
+ object = object.tb_frame
1271
+
1272
+ # for module or frame that corresponds to module, return all source lines
1273
+ if (ismodule(object) or
1274
+ (isframe(object) and object.f_code.co_name == "<module>")):
1275
+ return lines, 0
1276
+ else:
1277
+ return getblock(lines[lnum:]), lnum + 1
1278
+
1279
+ def getsource(object):
1280
+ """Return the text of the source code for an object.
1281
+
1282
+ The argument may be a module, class, method, function, traceback, frame,
1283
+ or code object. The source code is returned as a single string. An
1284
+ OSError is raised if the source code cannot be retrieved."""
1285
+ lines, lnum = getsourcelines(object)
1286
+ return ''.join(lines)
1287
+
1288
+ # --------------------------------------------------- class tree extraction
1289
+ def walktree(classes, children, parent):
1290
+ """Recursive helper function for getclasstree()."""
1291
+ results = []
1292
+ classes.sort(key=attrgetter('__module__', '__name__'))
1293
+ for c in classes:
1294
+ results.append((c, c.__bases__))
1295
+ if c in children:
1296
+ results.append(walktree(children[c], children, c))
1297
+ return results
1298
+
1299
+ def getclasstree(classes, unique=False):
1300
+ """Arrange the given list of classes into a hierarchy of nested lists.
1301
+
1302
+ Where a nested list appears, it contains classes derived from the class
1303
+ whose entry immediately precedes the list. Each entry is a 2-tuple
1304
+ containing a class and a tuple of its base classes. If the 'unique'
1305
+ argument is true, exactly one entry appears in the returned structure
1306
+ for each class in the given list. Otherwise, classes using multiple
1307
+ inheritance and their descendants will appear multiple times."""
1308
+ children = {}
1309
+ roots = []
1310
+ for c in classes:
1311
+ if c.__bases__:
1312
+ for parent in c.__bases__:
1313
+ if parent not in children:
1314
+ children[parent] = []
1315
+ if c not in children[parent]:
1316
+ children[parent].append(c)
1317
+ if unique and parent in classes: break
1318
+ elif c not in roots:
1319
+ roots.append(c)
1320
+ for parent in children:
1321
+ if parent not in classes:
1322
+ roots.append(parent)
1323
+ return walktree(roots, children, None)
1324
+
1325
+ # ------------------------------------------------ argument list extraction
1326
+ Arguments = namedtuple('Arguments', 'args, varargs, varkw')
1327
+
1328
+ def getargs(co):
1329
+ """Get information about the arguments accepted by a code object.
1330
+
1331
+ Three things are returned: (args, varargs, varkw), where
1332
+ 'args' is the list of argument names. Keyword-only arguments are
1333
+ appended. 'varargs' and 'varkw' are the names of the * and **
1334
+ arguments or None."""
1335
+ if not iscode(co):
1336
+ raise TypeError('{!r} is not a code object'.format(co))
1337
+
1338
+ names = co.co_varnames
1339
+ nargs = co.co_argcount
1340
+ nkwargs = co.co_kwonlyargcount
1341
+ args = list(names[:nargs])
1342
+ kwonlyargs = list(names[nargs:nargs+nkwargs])
1343
+
1344
+ nargs += nkwargs
1345
+ varargs = None
1346
+ if co.co_flags & CO_VARARGS:
1347
+ varargs = co.co_varnames[nargs]
1348
+ nargs = nargs + 1
1349
+ varkw = None
1350
+ if co.co_flags & CO_VARKEYWORDS:
1351
+ varkw = co.co_varnames[nargs]
1352
+ return Arguments(args + kwonlyargs, varargs, varkw)
1353
+
1354
+
1355
+ FullArgSpec = namedtuple('FullArgSpec',
1356
+ 'args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations')
1357
+
1358
+ def getfullargspec(func):
1359
+ """Get the names and default values of a callable object's parameters.
1360
+
1361
+ A tuple of seven things is returned:
1362
+ (args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations).
1363
+ 'args' is a list of the parameter names.
1364
+ 'varargs' and 'varkw' are the names of the * and ** parameters or None.
1365
+ 'defaults' is an n-tuple of the default values of the last n parameters.
1366
+ 'kwonlyargs' is a list of keyword-only parameter names.
1367
+ 'kwonlydefaults' is a dictionary mapping names from kwonlyargs to defaults.
1368
+ 'annotations' is a dictionary mapping parameter names to annotations.
1369
+
1370
+ Notable differences from inspect.signature():
1371
+ - the "self" parameter is always reported, even for bound methods
1372
+ - wrapper chains defined by __wrapped__ *not* unwrapped automatically
1373
+ """
1374
+ try:
1375
+ # Re: `skip_bound_arg=False`
1376
+ #
1377
+ # There is a notable difference in behaviour between getfullargspec
1378
+ # and Signature: the former always returns 'self' parameter for bound
1379
+ # methods, whereas the Signature always shows the actual calling
1380
+ # signature of the passed object.
1381
+ #
1382
+ # To simulate this behaviour, we "unbind" bound methods, to trick
1383
+ # inspect.signature to always return their first parameter ("self",
1384
+ # usually)
1385
+
1386
+ # Re: `follow_wrapper_chains=False`
1387
+ #
1388
+ # getfullargspec() historically ignored __wrapped__ attributes,
1389
+ # so we ensure that remains the case in 3.3+
1390
+
1391
+ sig = _signature_from_callable(func,
1392
+ follow_wrapper_chains=False,
1393
+ skip_bound_arg=False,
1394
+ sigcls=Signature,
1395
+ eval_str=False)
1396
+ except Exception as ex:
1397
+ # Most of the times 'signature' will raise ValueError.
1398
+ # But, it can also raise AttributeError, and, maybe something
1399
+ # else. So to be fully backwards compatible, we catch all
1400
+ # possible exceptions here, and reraise a TypeError.
1401
+ raise TypeError('unsupported callable') from ex
1402
+
1403
+ args = []
1404
+ varargs = None
1405
+ varkw = None
1406
+ posonlyargs = []
1407
+ kwonlyargs = []
1408
+ annotations = {}
1409
+ defaults = ()
1410
+ kwdefaults = {}
1411
+
1412
+ if sig.return_annotation is not sig.empty:
1413
+ annotations['return'] = sig.return_annotation
1414
+
1415
+ for param in sig.parameters.values():
1416
+ kind = param.kind
1417
+ name = param.name
1418
+
1419
+ if kind is _POSITIONAL_ONLY:
1420
+ posonlyargs.append(name)
1421
+ if param.default is not param.empty:
1422
+ defaults += (param.default,)
1423
+ elif kind is _POSITIONAL_OR_KEYWORD:
1424
+ args.append(name)
1425
+ if param.default is not param.empty:
1426
+ defaults += (param.default,)
1427
+ elif kind is _VAR_POSITIONAL:
1428
+ varargs = name
1429
+ elif kind is _KEYWORD_ONLY:
1430
+ kwonlyargs.append(name)
1431
+ if param.default is not param.empty:
1432
+ kwdefaults[name] = param.default
1433
+ elif kind is _VAR_KEYWORD:
1434
+ varkw = name
1435
+
1436
+ if param.annotation is not param.empty:
1437
+ annotations[name] = param.annotation
1438
+
1439
+ if not kwdefaults:
1440
+ # compatibility with 'func.__kwdefaults__'
1441
+ kwdefaults = None
1442
+
1443
+ if not defaults:
1444
+ # compatibility with 'func.__defaults__'
1445
+ defaults = None
1446
+
1447
+ return FullArgSpec(posonlyargs + args, varargs, varkw, defaults,
1448
+ kwonlyargs, kwdefaults, annotations)
1449
+
1450
+
1451
+ ArgInfo = namedtuple('ArgInfo', 'args varargs keywords locals')
1452
+
1453
+ def getargvalues(frame):
1454
+ """Get information about arguments passed into a particular frame.
1455
+
1456
+ A tuple of four things is returned: (args, varargs, varkw, locals).
1457
+ 'args' is a list of the argument names.
1458
+ 'varargs' and 'varkw' are the names of the * and ** arguments or None.
1459
+ 'locals' is the locals dictionary of the given frame."""
1460
+ args, varargs, varkw = getargs(frame.f_code)
1461
+ return ArgInfo(args, varargs, varkw, frame.f_locals)
1462
+
1463
+ def formatannotation(annotation, base_module=None):
1464
+ if getattr(annotation, '__module__', None) == 'typing':
1465
+ def repl(match):
1466
+ text = match.group()
1467
+ return text.removeprefix('typing.')
1468
+ return re.sub(r'[\w\.]+', repl, repr(annotation))
1469
+ if isinstance(annotation, types.GenericAlias):
1470
+ return str(annotation)
1471
+ if isinstance(annotation, type):
1472
+ if annotation.__module__ in ('builtins', base_module):
1473
+ return annotation.__qualname__
1474
+ return annotation.__module__+'.'+annotation.__qualname__
1475
+ return repr(annotation)
1476
+
1477
+ def formatannotationrelativeto(object):
1478
+ module = getattr(object, '__module__', None)
1479
+ def _formatannotation(annotation):
1480
+ return formatannotation(annotation, module)
1481
+ return _formatannotation
1482
+
1483
+
1484
+ def formatargvalues(args, varargs, varkw, locals,
1485
+ formatarg=str,
1486
+ formatvarargs=lambda name: '*' + name,
1487
+ formatvarkw=lambda name: '**' + name,
1488
+ formatvalue=lambda value: '=' + repr(value)):
1489
+ """Format an argument spec from the 4 values returned by getargvalues.
1490
+
1491
+ The first four arguments are (args, varargs, varkw, locals). The
1492
+ next four arguments are the corresponding optional formatting functions
1493
+ that are called to turn names and values into strings. The ninth
1494
+ argument is an optional function to format the sequence of arguments."""
1495
+ def convert(name, locals=locals,
1496
+ formatarg=formatarg, formatvalue=formatvalue):
1497
+ return formatarg(name) + formatvalue(locals[name])
1498
+ specs = []
1499
+ for i in range(len(args)):
1500
+ specs.append(convert(args[i]))
1501
+ if varargs:
1502
+ specs.append(formatvarargs(varargs) + formatvalue(locals[varargs]))
1503
+ if varkw:
1504
+ specs.append(formatvarkw(varkw) + formatvalue(locals[varkw]))
1505
+ return '(' + ', '.join(specs) + ')'
1506
+
1507
+ def _missing_arguments(f_name, argnames, pos, values):
1508
+ names = [repr(name) for name in argnames if name not in values]
1509
+ missing = len(names)
1510
+ if missing == 1:
1511
+ s = names[0]
1512
+ elif missing == 2:
1513
+ s = "{} and {}".format(*names)
1514
+ else:
1515
+ tail = ", {} and {}".format(*names[-2:])
1516
+ del names[-2:]
1517
+ s = ", ".join(names) + tail
1518
+ raise TypeError("%s() missing %i required %s argument%s: %s" %
1519
+ (f_name, missing,
1520
+ "positional" if pos else "keyword-only",
1521
+ "" if missing == 1 else "s", s))
1522
+
1523
+ def _too_many(f_name, args, kwonly, varargs, defcount, given, values):
1524
+ atleast = len(args) - defcount
1525
+ kwonly_given = len([arg for arg in kwonly if arg in values])
1526
+ if varargs:
1527
+ plural = atleast != 1
1528
+ sig = "at least %d" % (atleast,)
1529
+ elif defcount:
1530
+ plural = True
1531
+ sig = "from %d to %d" % (atleast, len(args))
1532
+ else:
1533
+ plural = len(args) != 1
1534
+ sig = str(len(args))
1535
+ kwonly_sig = ""
1536
+ if kwonly_given:
1537
+ msg = " positional argument%s (and %d keyword-only argument%s)"
1538
+ kwonly_sig = (msg % ("s" if given != 1 else "", kwonly_given,
1539
+ "s" if kwonly_given != 1 else ""))
1540
+ raise TypeError("%s() takes %s positional argument%s but %d%s %s given" %
1541
+ (f_name, sig, "s" if plural else "", given, kwonly_sig,
1542
+ "was" if given == 1 and not kwonly_given else "were"))
1543
+
1544
+ def getcallargs(func, /, *positional, **named):
1545
+ """Get the mapping of arguments to values.
1546
+
1547
+ A dict is returned, with keys the function argument names (including the
1548
+ names of the * and ** arguments, if any), and values the respective bound
1549
+ values from 'positional' and 'named'."""
1550
+ spec = getfullargspec(func)
1551
+ args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = spec
1552
+ f_name = func.__name__
1553
+ arg2value = {}
1554
+
1555
+
1556
+ if ismethod(func) and func.__self__ is not None:
1557
+ # implicit 'self' (or 'cls' for classmethods) argument
1558
+ positional = (func.__self__,) + positional
1559
+ num_pos = len(positional)
1560
+ num_args = len(args)
1561
+ num_defaults = len(defaults) if defaults else 0
1562
+
1563
+ n = min(num_pos, num_args)
1564
+ for i in range(n):
1565
+ arg2value[args[i]] = positional[i]
1566
+ if varargs:
1567
+ arg2value[varargs] = tuple(positional[n:])
1568
+ possible_kwargs = set(args + kwonlyargs)
1569
+ if varkw:
1570
+ arg2value[varkw] = {}
1571
+ for kw, value in named.items():
1572
+ if kw not in possible_kwargs:
1573
+ if not varkw:
1574
+ raise TypeError("%s() got an unexpected keyword argument %r" %
1575
+ (f_name, kw))
1576
+ arg2value[varkw][kw] = value
1577
+ continue
1578
+ if kw in arg2value:
1579
+ raise TypeError("%s() got multiple values for argument %r" %
1580
+ (f_name, kw))
1581
+ arg2value[kw] = value
1582
+ if num_pos > num_args and not varargs:
1583
+ _too_many(f_name, args, kwonlyargs, varargs, num_defaults,
1584
+ num_pos, arg2value)
1585
+ if num_pos < num_args:
1586
+ req = args[:num_args - num_defaults]
1587
+ for arg in req:
1588
+ if arg not in arg2value:
1589
+ _missing_arguments(f_name, req, True, arg2value)
1590
+ for i, arg in enumerate(args[num_args - num_defaults:]):
1591
+ if arg not in arg2value:
1592
+ arg2value[arg] = defaults[i]
1593
+ missing = 0
1594
+ for kwarg in kwonlyargs:
1595
+ if kwarg not in arg2value:
1596
+ if kwonlydefaults and kwarg in kwonlydefaults:
1597
+ arg2value[kwarg] = kwonlydefaults[kwarg]
1598
+ else:
1599
+ missing += 1
1600
+ if missing:
1601
+ _missing_arguments(f_name, kwonlyargs, False, arg2value)
1602
+ return arg2value
1603
+
1604
+ ClosureVars = namedtuple('ClosureVars', 'nonlocals globals builtins unbound')
1605
+
1606
+ def getclosurevars(func):
1607
+ """
1608
+ Get the mapping of free variables to their current values.
1609
+
1610
+ Returns a named tuple of dicts mapping the current nonlocal, global
1611
+ and builtin references as seen by the body of the function. A final
1612
+ set of unbound names that could not be resolved is also provided.
1613
+ """
1614
+
1615
+ if ismethod(func):
1616
+ func = func.__func__
1617
+
1618
+ if not isfunction(func):
1619
+ raise TypeError("{!r} is not a Python function".format(func))
1620
+
1621
+ code = func.__code__
1622
+ # Nonlocal references are named in co_freevars and resolved
1623
+ # by looking them up in __closure__ by positional index
1624
+ if func.__closure__ is None:
1625
+ nonlocal_vars = {}
1626
+ else:
1627
+ nonlocal_vars = {
1628
+ var : cell.cell_contents
1629
+ for var, cell in zip(code.co_freevars, func.__closure__)
1630
+ }
1631
+
1632
+ # Global and builtin references are named in co_names and resolved
1633
+ # by looking them up in __globals__ or __builtins__
1634
+ global_ns = func.__globals__
1635
+ builtin_ns = global_ns.get("__builtins__", builtins.__dict__)
1636
+ if ismodule(builtin_ns):
1637
+ builtin_ns = builtin_ns.__dict__
1638
+ global_vars = {}
1639
+ builtin_vars = {}
1640
+ unbound_names = set()
1641
+ for name in code.co_names:
1642
+ if name in ("None", "True", "False"):
1643
+ # Because these used to be builtins instead of keywords, they
1644
+ # may still show up as name references. We ignore them.
1645
+ continue
1646
+ try:
1647
+ global_vars[name] = global_ns[name]
1648
+ except KeyError:
1649
+ try:
1650
+ builtin_vars[name] = builtin_ns[name]
1651
+ except KeyError:
1652
+ unbound_names.add(name)
1653
+
1654
+ return ClosureVars(nonlocal_vars, global_vars,
1655
+ builtin_vars, unbound_names)
1656
+
1657
+ # -------------------------------------------------- stack frame extraction
1658
+
1659
+ _Traceback = namedtuple('_Traceback', 'filename lineno function code_context index')
1660
+
1661
+ class Traceback(_Traceback):
1662
+ def __new__(cls, filename, lineno, function, code_context, index, *, positions=None):
1663
+ instance = super().__new__(cls, filename, lineno, function, code_context, index)
1664
+ instance.positions = positions
1665
+ return instance
1666
+
1667
+ def __repr__(self):
1668
+ return ('Traceback(filename={!r}, lineno={!r}, function={!r}, '
1669
+ 'code_context={!r}, index={!r}, positions={!r})'.format(
1670
+ self.filename, self.lineno, self.function, self.code_context,
1671
+ self.index, self.positions))
1672
+
1673
+ def _get_code_position_from_tb(tb):
1674
+ code, instruction_index = tb.tb_frame.f_code, tb.tb_lasti
1675
+ return _get_code_position(code, instruction_index)
1676
+
1677
+ def _get_code_position(code, instruction_index):
1678
+ if instruction_index < 0:
1679
+ return (None, None, None, None)
1680
+ positions_gen = code.co_positions()
1681
+ # The nth entry in code.co_positions() corresponds to instruction (2*n)th since Python 3.10+
1682
+ return next(itertools.islice(positions_gen, instruction_index // 2, None))
1683
+
1684
+ def getframeinfo(frame, context=1):
1685
+ """Get information about a frame or traceback object.
1686
+
1687
+ A tuple of five things is returned: the filename, the line number of
1688
+ the current line, the function name, a list of lines of context from
1689
+ the source code, and the index of the current line within that list.
1690
+ The optional second argument specifies the number of lines of context
1691
+ to return, which are centered around the current line."""
1692
+ if istraceback(frame):
1693
+ positions = _get_code_position_from_tb(frame)
1694
+ lineno = frame.tb_lineno
1695
+ frame = frame.tb_frame
1696
+ else:
1697
+ lineno = frame.f_lineno
1698
+ positions = _get_code_position(frame.f_code, frame.f_lasti)
1699
+
1700
+ if positions[0] is None:
1701
+ frame, *positions = (frame, lineno, *positions[1:])
1702
+ else:
1703
+ frame, *positions = (frame, *positions)
1704
+
1705
+ lineno = positions[0]
1706
+
1707
+ if not isframe(frame):
1708
+ raise TypeError('{!r} is not a frame or traceback object'.format(frame))
1709
+
1710
+ filename = getsourcefile(frame) or getfile(frame)
1711
+ if context > 0:
1712
+ start = lineno - 1 - context//2
1713
+ try:
1714
+ lines, lnum = findsource(frame)
1715
+ except OSError:
1716
+ lines = index = None
1717
+ else:
1718
+ start = max(0, min(start, len(lines) - context))
1719
+ lines = lines[start:start+context]
1720
+ index = lineno - 1 - start
1721
+ else:
1722
+ lines = index = None
1723
+
1724
+ return Traceback(filename, lineno, frame.f_code.co_name, lines,
1725
+ index, positions=dis.Positions(*positions))
1726
+
1727
+ def getlineno(frame):
1728
+ """Get the line number from a frame object, allowing for optimization."""
1729
+ # FrameType.f_lineno is now a descriptor that grovels co_lnotab
1730
+ return frame.f_lineno
1731
+
1732
+ _FrameInfo = namedtuple('_FrameInfo', ('frame',) + Traceback._fields)
1733
+ class FrameInfo(_FrameInfo):
1734
+ def __new__(cls, frame, filename, lineno, function, code_context, index, *, positions=None):
1735
+ instance = super().__new__(cls, frame, filename, lineno, function, code_context, index)
1736
+ instance.positions = positions
1737
+ return instance
1738
+
1739
+ def __repr__(self):
1740
+ return ('FrameInfo(frame={!r}, filename={!r}, lineno={!r}, function={!r}, '
1741
+ 'code_context={!r}, index={!r}, positions={!r})'.format(
1742
+ self.frame, self.filename, self.lineno, self.function,
1743
+ self.code_context, self.index, self.positions))
1744
+
1745
+ def getouterframes(frame, context=1):
1746
+ """Get a list of records for a frame and all higher (calling) frames.
1747
+
1748
+ Each record contains a frame object, filename, line number, function
1749
+ name, a list of lines of context, and index within the context."""
1750
+ framelist = []
1751
+ while frame:
1752
+ traceback_info = getframeinfo(frame, context)
1753
+ frameinfo = (frame,) + traceback_info
1754
+ framelist.append(FrameInfo(*frameinfo, positions=traceback_info.positions))
1755
+ frame = frame.f_back
1756
+ return framelist
1757
+
1758
+ def getinnerframes(tb, context=1):
1759
+ """Get a list of records for a traceback's frame and all lower frames.
1760
+
1761
+ Each record contains a frame object, filename, line number, function
1762
+ name, a list of lines of context, and index within the context."""
1763
+ framelist = []
1764
+ while tb:
1765
+ traceback_info = getframeinfo(tb, context)
1766
+ frameinfo = (tb.tb_frame,) + traceback_info
1767
+ framelist.append(FrameInfo(*frameinfo, positions=traceback_info.positions))
1768
+ tb = tb.tb_next
1769
+ return framelist
1770
+
1771
+ def currentframe():
1772
+ """Return the frame of the caller or None if this is not possible."""
1773
+ return sys._getframe(1) if hasattr(sys, "_getframe") else None
1774
+
1775
+ def stack(context=1):
1776
+ """Return a list of records for the stack above the caller's frame."""
1777
+ return getouterframes(sys._getframe(1), context)
1778
+
1779
+ def trace(context=1):
1780
+ """Return a list of records for the stack below the current exception."""
1781
+ exc = sys.exception()
1782
+ tb = None if exc is None else exc.__traceback__
1783
+ return getinnerframes(tb, context)
1784
+
1785
+
1786
+ # ------------------------------------------------ static version of getattr
1787
+
1788
+ _sentinel = object()
1789
+ _static_getmro = type.__dict__['__mro__'].__get__
1790
+ _get_dunder_dict_of_class = type.__dict__["__dict__"].__get__
1791
+
1792
+
1793
+ def _check_instance(obj, attr):
1794
+ instance_dict = {}
1795
+ try:
1796
+ instance_dict = object.__getattribute__(obj, "__dict__")
1797
+ except AttributeError:
1798
+ pass
1799
+ return dict.get(instance_dict, attr, _sentinel)
1800
+
1801
+
1802
+ def _check_class(klass, attr):
1803
+ for entry in _static_getmro(klass):
1804
+ if _shadowed_dict(type(entry)) is _sentinel and attr in entry.__dict__:
1805
+ return entry.__dict__[attr]
1806
+ return _sentinel
1807
+
1808
+
1809
+ @functools.lru_cache()
1810
+ def _shadowed_dict_from_weakref_mro_tuple(*weakref_mro):
1811
+ for weakref_entry in weakref_mro:
1812
+ # Normally we'd have to check whether the result of weakref_entry()
1813
+ # is None here, in case the object the weakref is pointing to has died.
1814
+ # In this specific case, however, we know that the only caller of this
1815
+ # function is `_shadowed_dict()`, and that therefore this weakref is
1816
+ # guaranteed to point to an object that is still alive.
1817
+ entry = weakref_entry()
1818
+ dunder_dict = _get_dunder_dict_of_class(entry)
1819
+ if '__dict__' in dunder_dict:
1820
+ class_dict = dunder_dict['__dict__']
1821
+ if not (type(class_dict) is types.GetSetDescriptorType and
1822
+ class_dict.__name__ == "__dict__" and
1823
+ class_dict.__objclass__ is entry):
1824
+ return class_dict
1825
+ return _sentinel
1826
+
1827
+
1828
+ def _shadowed_dict(klass):
1829
+ # gh-118013: the inner function here is decorated with lru_cache for
1830
+ # performance reasons, *but* make sure not to pass strong references
1831
+ # to the items in the mro. Doing so can lead to unexpected memory
1832
+ # consumption in cases where classes are dynamically created and
1833
+ # destroyed, and the dynamically created classes happen to be the only
1834
+ # objects that hold strong references to other objects that take up a
1835
+ # significant amount of memory.
1836
+ return _shadowed_dict_from_weakref_mro_tuple(
1837
+ *[make_weakref(entry) for entry in _static_getmro(klass)]
1838
+ )
1839
+
1840
+
1841
+ def getattr_static(obj, attr, default=_sentinel):
1842
+ """Retrieve attributes without triggering dynamic lookup via the
1843
+ descriptor protocol, __getattr__ or __getattribute__.
1844
+
1845
+ Note: this function may not be able to retrieve all attributes
1846
+ that getattr can fetch (like dynamically created attributes)
1847
+ and may find attributes that getattr can't (like descriptors
1848
+ that raise AttributeError). It can also return descriptor objects
1849
+ instead of instance members in some cases. See the
1850
+ documentation for details.
1851
+ """
1852
+ instance_result = _sentinel
1853
+
1854
+ objtype = type(obj)
1855
+ if type not in _static_getmro(objtype):
1856
+ klass = objtype
1857
+ dict_attr = _shadowed_dict(klass)
1858
+ if (dict_attr is _sentinel or
1859
+ type(dict_attr) is types.MemberDescriptorType):
1860
+ instance_result = _check_instance(obj, attr)
1861
+ else:
1862
+ klass = obj
1863
+
1864
+ klass_result = _check_class(klass, attr)
1865
+
1866
+ if instance_result is not _sentinel and klass_result is not _sentinel:
1867
+ if _check_class(type(klass_result), "__get__") is not _sentinel and (
1868
+ _check_class(type(klass_result), "__set__") is not _sentinel
1869
+ or _check_class(type(klass_result), "__delete__") is not _sentinel
1870
+ ):
1871
+ return klass_result
1872
+
1873
+ if instance_result is not _sentinel:
1874
+ return instance_result
1875
+ if klass_result is not _sentinel:
1876
+ return klass_result
1877
+
1878
+ if obj is klass:
1879
+ # for types we check the metaclass too
1880
+ for entry in _static_getmro(type(klass)):
1881
+ if (
1882
+ _shadowed_dict(type(entry)) is _sentinel
1883
+ and attr in entry.__dict__
1884
+ ):
1885
+ return entry.__dict__[attr]
1886
+ if default is not _sentinel:
1887
+ return default
1888
+ raise AttributeError(attr)
1889
+
1890
+
1891
+ # ------------------------------------------------ generator introspection
1892
+
1893
+ GEN_CREATED = 'GEN_CREATED'
1894
+ GEN_RUNNING = 'GEN_RUNNING'
1895
+ GEN_SUSPENDED = 'GEN_SUSPENDED'
1896
+ GEN_CLOSED = 'GEN_CLOSED'
1897
+
1898
+ def getgeneratorstate(generator):
1899
+ """Get current state of a generator-iterator.
1900
+
1901
+ Possible states are:
1902
+ GEN_CREATED: Waiting to start execution.
1903
+ GEN_RUNNING: Currently being executed by the interpreter.
1904
+ GEN_SUSPENDED: Currently suspended at a yield expression.
1905
+ GEN_CLOSED: Execution has completed.
1906
+ """
1907
+ if generator.gi_running:
1908
+ return GEN_RUNNING
1909
+ if generator.gi_suspended:
1910
+ return GEN_SUSPENDED
1911
+ if generator.gi_frame is None:
1912
+ return GEN_CLOSED
1913
+ return GEN_CREATED
1914
+
1915
+
1916
+ def getgeneratorlocals(generator):
1917
+ """
1918
+ Get the mapping of generator local variables to their current values.
1919
+
1920
+ A dict is returned, with the keys the local variable names and values the
1921
+ bound values."""
1922
+
1923
+ if not isgenerator(generator):
1924
+ raise TypeError("{!r} is not a Python generator".format(generator))
1925
+
1926
+ frame = getattr(generator, "gi_frame", None)
1927
+ if frame is not None:
1928
+ return generator.gi_frame.f_locals
1929
+ else:
1930
+ return {}
1931
+
1932
+
1933
+ # ------------------------------------------------ coroutine introspection
1934
+
1935
+ CORO_CREATED = 'CORO_CREATED'
1936
+ CORO_RUNNING = 'CORO_RUNNING'
1937
+ CORO_SUSPENDED = 'CORO_SUSPENDED'
1938
+ CORO_CLOSED = 'CORO_CLOSED'
1939
+
1940
+ def getcoroutinestate(coroutine):
1941
+ """Get current state of a coroutine object.
1942
+
1943
+ Possible states are:
1944
+ CORO_CREATED: Waiting to start execution.
1945
+ CORO_RUNNING: Currently being executed by the interpreter.
1946
+ CORO_SUSPENDED: Currently suspended at an await expression.
1947
+ CORO_CLOSED: Execution has completed.
1948
+ """
1949
+ if coroutine.cr_running:
1950
+ return CORO_RUNNING
1951
+ if coroutine.cr_suspended:
1952
+ return CORO_SUSPENDED
1953
+ if coroutine.cr_frame is None:
1954
+ return CORO_CLOSED
1955
+ return CORO_CREATED
1956
+
1957
+
1958
+ def getcoroutinelocals(coroutine):
1959
+ """
1960
+ Get the mapping of coroutine local variables to their current values.
1961
+
1962
+ A dict is returned, with the keys the local variable names and values the
1963
+ bound values."""
1964
+ frame = getattr(coroutine, "cr_frame", None)
1965
+ if frame is not None:
1966
+ return frame.f_locals
1967
+ else:
1968
+ return {}
1969
+
1970
+
1971
+ # ----------------------------------- asynchronous generator introspection
1972
+
1973
+ AGEN_CREATED = 'AGEN_CREATED'
1974
+ AGEN_RUNNING = 'AGEN_RUNNING'
1975
+ AGEN_SUSPENDED = 'AGEN_SUSPENDED'
1976
+ AGEN_CLOSED = 'AGEN_CLOSED'
1977
+
1978
+
1979
+ def getasyncgenstate(agen):
1980
+ """Get current state of an asynchronous generator object.
1981
+
1982
+ Possible states are:
1983
+ AGEN_CREATED: Waiting to start execution.
1984
+ AGEN_RUNNING: Currently being executed by the interpreter.
1985
+ AGEN_SUSPENDED: Currently suspended at a yield expression.
1986
+ AGEN_CLOSED: Execution has completed.
1987
+ """
1988
+ if agen.ag_running:
1989
+ return AGEN_RUNNING
1990
+ if agen.ag_suspended:
1991
+ return AGEN_SUSPENDED
1992
+ if agen.ag_frame is None:
1993
+ return AGEN_CLOSED
1994
+ return AGEN_CREATED
1995
+
1996
+
1997
+ def getasyncgenlocals(agen):
1998
+ """
1999
+ Get the mapping of asynchronous generator local variables to their current
2000
+ values.
2001
+
2002
+ A dict is returned, with the keys the local variable names and values the
2003
+ bound values."""
2004
+
2005
+ if not isasyncgen(agen):
2006
+ raise TypeError(f"{agen!r} is not a Python async generator")
2007
+
2008
+ frame = getattr(agen, "ag_frame", None)
2009
+ if frame is not None:
2010
+ return agen.ag_frame.f_locals
2011
+ else:
2012
+ return {}
2013
+
2014
+
2015
+ ###############################################################################
2016
+ ### Function Signature Object (PEP 362)
2017
+ ###############################################################################
2018
+
2019
+
2020
+ _NonUserDefinedCallables = (types.WrapperDescriptorType,
2021
+ types.MethodWrapperType,
2022
+ types.ClassMethodDescriptorType,
2023
+ types.BuiltinFunctionType)
2024
+
2025
+
2026
+ def _signature_get_user_defined_method(cls, method_name):
2027
+ """Private helper. Checks if ``cls`` has an attribute
2028
+ named ``method_name`` and returns it only if it is a
2029
+ pure python function.
2030
+ """
2031
+ if method_name == '__new__':
2032
+ meth = getattr(cls, method_name, None)
2033
+ else:
2034
+ meth = getattr_static(cls, method_name, None)
2035
+ if meth is None or isinstance(meth, _NonUserDefinedCallables):
2036
+ # Once '__signature__' will be added to 'C'-level
2037
+ # callables, this check won't be necessary
2038
+ return None
2039
+ if method_name != '__new__':
2040
+ meth = _descriptor_get(meth, cls)
2041
+ return meth
2042
+
2043
+
2044
+ def _signature_get_partial(wrapped_sig, partial, extra_args=()):
2045
+ """Private helper to calculate how 'wrapped_sig' signature will
2046
+ look like after applying a 'functools.partial' object (or alike)
2047
+ on it.
2048
+ """
2049
+
2050
+ old_params = wrapped_sig.parameters
2051
+ new_params = OrderedDict(old_params.items())
2052
+
2053
+ partial_args = partial.args or ()
2054
+ partial_keywords = partial.keywords or {}
2055
+
2056
+ if extra_args:
2057
+ partial_args = extra_args + partial_args
2058
+
2059
+ try:
2060
+ ba = wrapped_sig.bind_partial(*partial_args, **partial_keywords)
2061
+ except TypeError as ex:
2062
+ msg = 'partial object {!r} has incorrect arguments'.format(partial)
2063
+ raise ValueError(msg) from ex
2064
+
2065
+
2066
+ transform_to_kwonly = False
2067
+ for param_name, param in old_params.items():
2068
+ try:
2069
+ arg_value = ba.arguments[param_name]
2070
+ except KeyError:
2071
+ pass
2072
+ else:
2073
+ if param.kind is _POSITIONAL_ONLY:
2074
+ # If positional-only parameter is bound by partial,
2075
+ # it effectively disappears from the signature
2076
+ new_params.pop(param_name)
2077
+ continue
2078
+
2079
+ if param.kind is _POSITIONAL_OR_KEYWORD:
2080
+ if param_name in partial_keywords:
2081
+ # This means that this parameter, and all parameters
2082
+ # after it should be keyword-only (and var-positional
2083
+ # should be removed). Here's why. Consider the following
2084
+ # function:
2085
+ # foo(a, b, *args, c):
2086
+ # pass
2087
+ #
2088
+ # "partial(foo, a='spam')" will have the following
2089
+ # signature: "(*, a='spam', b, c)". Because attempting
2090
+ # to call that partial with "(10, 20)" arguments will
2091
+ # raise a TypeError, saying that "a" argument received
2092
+ # multiple values.
2093
+ transform_to_kwonly = True
2094
+ # Set the new default value
2095
+ new_params[param_name] = param.replace(default=arg_value)
2096
+ else:
2097
+ # was passed as a positional argument
2098
+ new_params.pop(param.name)
2099
+ continue
2100
+
2101
+ if param.kind is _KEYWORD_ONLY:
2102
+ # Set the new default value
2103
+ new_params[param_name] = param.replace(default=arg_value)
2104
+
2105
+ if transform_to_kwonly:
2106
+ assert param.kind is not _POSITIONAL_ONLY
2107
+
2108
+ if param.kind is _POSITIONAL_OR_KEYWORD:
2109
+ new_param = new_params[param_name].replace(kind=_KEYWORD_ONLY)
2110
+ new_params[param_name] = new_param
2111
+ new_params.move_to_end(param_name)
2112
+ elif param.kind in (_KEYWORD_ONLY, _VAR_KEYWORD):
2113
+ new_params.move_to_end(param_name)
2114
+ elif param.kind is _VAR_POSITIONAL:
2115
+ new_params.pop(param.name)
2116
+
2117
+ return wrapped_sig.replace(parameters=new_params.values())
2118
+
2119
+
2120
+ def _signature_bound_method(sig):
2121
+ """Private helper to transform signatures for unbound
2122
+ functions to bound methods.
2123
+ """
2124
+
2125
+ params = tuple(sig.parameters.values())
2126
+
2127
+ if not params or params[0].kind in (_VAR_KEYWORD, _KEYWORD_ONLY):
2128
+ raise ValueError('invalid method signature')
2129
+
2130
+ kind = params[0].kind
2131
+ if kind in (_POSITIONAL_OR_KEYWORD, _POSITIONAL_ONLY):
2132
+ # Drop first parameter:
2133
+ # '(p1, p2[, ...])' -> '(p2[, ...])'
2134
+ params = params[1:]
2135
+ else:
2136
+ if kind is not _VAR_POSITIONAL:
2137
+ # Unless we add a new parameter type we never
2138
+ # get here
2139
+ raise ValueError('invalid argument type')
2140
+ # It's a var-positional parameter.
2141
+ # Do nothing. '(*args[, ...])' -> '(*args[, ...])'
2142
+
2143
+ return sig.replace(parameters=params)
2144
+
2145
+
2146
+ def _signature_is_builtin(obj):
2147
+ """Private helper to test if `obj` is a callable that might
2148
+ support Argument Clinic's __text_signature__ protocol.
2149
+ """
2150
+ return (isbuiltin(obj) or
2151
+ ismethoddescriptor(obj) or
2152
+ isinstance(obj, _NonUserDefinedCallables) or
2153
+ # Can't test 'isinstance(type)' here, as it would
2154
+ # also be True for regular python classes.
2155
+ # Can't use the `in` operator here, as it would
2156
+ # invoke the custom __eq__ method.
2157
+ obj is type or obj is object)
2158
+
2159
+
2160
+ def _signature_is_functionlike(obj):
2161
+ """Private helper to test if `obj` is a duck type of FunctionType.
2162
+ A good example of such objects are functions compiled with
2163
+ Cython, which have all attributes that a pure Python function
2164
+ would have, but have their code statically compiled.
2165
+ """
2166
+
2167
+ if not callable(obj) or isclass(obj):
2168
+ # All function-like objects are obviously callables,
2169
+ # and not classes.
2170
+ return False
2171
+
2172
+ name = getattr(obj, '__name__', None)
2173
+ code = getattr(obj, '__code__', None)
2174
+ defaults = getattr(obj, '__defaults__', _void) # Important to use _void ...
2175
+ kwdefaults = getattr(obj, '__kwdefaults__', _void) # ... and not None here
2176
+ annotations = getattr(obj, '__annotations__', None)
2177
+
2178
+ return (isinstance(code, types.CodeType) and
2179
+ isinstance(name, str) and
2180
+ (defaults is None or isinstance(defaults, tuple)) and
2181
+ (kwdefaults is None or isinstance(kwdefaults, dict)) and
2182
+ (isinstance(annotations, (dict)) or annotations is None) )
2183
+
2184
+
2185
+ def _signature_strip_non_python_syntax(signature):
2186
+ """
2187
+ Private helper function. Takes a signature in Argument Clinic's
2188
+ extended signature format.
2189
+
2190
+ Returns a tuple of two things:
2191
+ * that signature re-rendered in standard Python syntax, and
2192
+ * the index of the "self" parameter (generally 0), or None if
2193
+ the function does not have a "self" parameter.
2194
+ """
2195
+
2196
+ if not signature:
2197
+ return signature, None
2198
+
2199
+ self_parameter = None
2200
+
2201
+ lines = [l.encode('ascii') for l in signature.split('\n') if l]
2202
+ generator = iter(lines).__next__
2203
+ token_stream = tokenize.tokenize(generator)
2204
+
2205
+ text = []
2206
+ add = text.append
2207
+
2208
+ current_parameter = 0
2209
+ OP = token.OP
2210
+ ERRORTOKEN = token.ERRORTOKEN
2211
+
2212
+ # token stream always starts with ENCODING token, skip it
2213
+ t = next(token_stream)
2214
+ assert t.type == tokenize.ENCODING
2215
+
2216
+ for t in token_stream:
2217
+ type, string = t.type, t.string
2218
+
2219
+ if type == OP:
2220
+ if string == ',':
2221
+ current_parameter += 1
2222
+
2223
+ if (type == OP) and (string == '$'):
2224
+ assert self_parameter is None
2225
+ self_parameter = current_parameter
2226
+ continue
2227
+
2228
+ add(string)
2229
+ if (string == ','):
2230
+ add(' ')
2231
+ clean_signature = ''.join(text).strip().replace("\n", "")
2232
+ return clean_signature, self_parameter
2233
+
2234
+
2235
+ def _signature_fromstr(cls, obj, s, skip_bound_arg=True):
2236
+ """Private helper to parse content of '__text_signature__'
2237
+ and return a Signature based on it.
2238
+ """
2239
+ Parameter = cls._parameter_cls
2240
+
2241
+ clean_signature, self_parameter = _signature_strip_non_python_syntax(s)
2242
+
2243
+ program = "def foo" + clean_signature + ": pass"
2244
+
2245
+ try:
2246
+ module = ast.parse(program)
2247
+ except SyntaxError:
2248
+ module = None
2249
+
2250
+ if not isinstance(module, ast.Module):
2251
+ raise ValueError("{!r} builtin has invalid signature".format(obj))
2252
+
2253
+ f = module.body[0]
2254
+
2255
+ parameters = []
2256
+ empty = Parameter.empty
2257
+
2258
+ module = None
2259
+ module_dict = {}
2260
+ module_name = getattr(obj, '__module__', None)
2261
+ if module_name:
2262
+ module = sys.modules.get(module_name, None)
2263
+ if module:
2264
+ module_dict = module.__dict__
2265
+ sys_module_dict = sys.modules.copy()
2266
+
2267
+ def parse_name(node):
2268
+ assert isinstance(node, ast.arg)
2269
+ if node.annotation is not None:
2270
+ raise ValueError("Annotations are not currently supported")
2271
+ return node.arg
2272
+
2273
+ def wrap_value(s):
2274
+ try:
2275
+ value = eval(s, module_dict)
2276
+ except NameError:
2277
+ try:
2278
+ value = eval(s, sys_module_dict)
2279
+ except NameError:
2280
+ raise ValueError
2281
+
2282
+ if isinstance(value, (str, int, float, bytes, bool, type(None))):
2283
+ return ast.Constant(value)
2284
+ raise ValueError
2285
+
2286
+ class RewriteSymbolics(ast.NodeTransformer):
2287
+ def visit_Attribute(self, node):
2288
+ a = []
2289
+ n = node
2290
+ while isinstance(n, ast.Attribute):
2291
+ a.append(n.attr)
2292
+ n = n.value
2293
+ if not isinstance(n, ast.Name):
2294
+ raise ValueError
2295
+ a.append(n.id)
2296
+ value = ".".join(reversed(a))
2297
+ return wrap_value(value)
2298
+
2299
+ def visit_Name(self, node):
2300
+ if not isinstance(node.ctx, ast.Load):
2301
+ raise ValueError()
2302
+ return wrap_value(node.id)
2303
+
2304
+ def visit_BinOp(self, node):
2305
+ # Support constant folding of a couple simple binary operations
2306
+ # commonly used to define default values in text signatures
2307
+ left = self.visit(node.left)
2308
+ right = self.visit(node.right)
2309
+ if not isinstance(left, ast.Constant) or not isinstance(right, ast.Constant):
2310
+ raise ValueError
2311
+ if isinstance(node.op, ast.Add):
2312
+ return ast.Constant(left.value + right.value)
2313
+ elif isinstance(node.op, ast.Sub):
2314
+ return ast.Constant(left.value - right.value)
2315
+ elif isinstance(node.op, ast.BitOr):
2316
+ return ast.Constant(left.value | right.value)
2317
+ raise ValueError
2318
+
2319
+ def p(name_node, default_node, default=empty):
2320
+ name = parse_name(name_node)
2321
+ if default_node and default_node is not _empty:
2322
+ try:
2323
+ default_node = RewriteSymbolics().visit(default_node)
2324
+ default = ast.literal_eval(default_node)
2325
+ except ValueError:
2326
+ raise ValueError("{!r} builtin has invalid signature".format(obj)) from None
2327
+ parameters.append(Parameter(name, kind, default=default, annotation=empty))
2328
+
2329
+ # non-keyword-only parameters
2330
+ total_non_kw_args = len(f.args.posonlyargs) + len(f.args.args)
2331
+ required_non_kw_args = total_non_kw_args - len(f.args.defaults)
2332
+ defaults = itertools.chain(itertools.repeat(None, required_non_kw_args), f.args.defaults)
2333
+
2334
+ kind = Parameter.POSITIONAL_ONLY
2335
+ for (name, default) in zip(f.args.posonlyargs, defaults):
2336
+ p(name, default)
2337
+
2338
+ kind = Parameter.POSITIONAL_OR_KEYWORD
2339
+ for (name, default) in zip(f.args.args, defaults):
2340
+ p(name, default)
2341
+
2342
+ # *args
2343
+ if f.args.vararg:
2344
+ kind = Parameter.VAR_POSITIONAL
2345
+ p(f.args.vararg, empty)
2346
+
2347
+ # keyword-only arguments
2348
+ kind = Parameter.KEYWORD_ONLY
2349
+ for name, default in zip(f.args.kwonlyargs, f.args.kw_defaults):
2350
+ p(name, default)
2351
+
2352
+ # **kwargs
2353
+ if f.args.kwarg:
2354
+ kind = Parameter.VAR_KEYWORD
2355
+ p(f.args.kwarg, empty)
2356
+
2357
+ if self_parameter is not None:
2358
+ # Possibly strip the bound argument:
2359
+ # - We *always* strip first bound argument if
2360
+ # it is a module.
2361
+ # - We don't strip first bound argument if
2362
+ # skip_bound_arg is False.
2363
+ assert parameters
2364
+ _self = getattr(obj, '__self__', None)
2365
+ self_isbound = _self is not None
2366
+ self_ismodule = ismodule(_self)
2367
+ if self_isbound and (self_ismodule or skip_bound_arg):
2368
+ parameters.pop(0)
2369
+ else:
2370
+ # for builtins, self parameter is always positional-only!
2371
+ p = parameters[0].replace(kind=Parameter.POSITIONAL_ONLY)
2372
+ parameters[0] = p
2373
+
2374
+ return cls(parameters, return_annotation=cls.empty)
2375
+
2376
+
2377
+ def _signature_from_builtin(cls, func, skip_bound_arg=True):
2378
+ """Private helper function to get signature for
2379
+ builtin callables.
2380
+ """
2381
+
2382
+ if not _signature_is_builtin(func):
2383
+ raise TypeError("{!r} is not a Python builtin "
2384
+ "function".format(func))
2385
+
2386
+ s = getattr(func, "__text_signature__", None)
2387
+ if not s:
2388
+ raise ValueError("no signature found for builtin {!r}".format(func))
2389
+
2390
+ return _signature_fromstr(cls, func, s, skip_bound_arg)
2391
+
2392
+
2393
+ def _signature_from_function(cls, func, skip_bound_arg=True,
2394
+ globals=None, locals=None, eval_str=False):
2395
+ """Private helper: constructs Signature for the given python function."""
2396
+
2397
+ is_duck_function = False
2398
+ if not isfunction(func):
2399
+ if _signature_is_functionlike(func):
2400
+ is_duck_function = True
2401
+ else:
2402
+ # If it's not a pure Python function, and not a duck type
2403
+ # of pure function:
2404
+ raise TypeError('{!r} is not a Python function'.format(func))
2405
+
2406
+ s = getattr(func, "__text_signature__", None)
2407
+ if s:
2408
+ return _signature_fromstr(cls, func, s, skip_bound_arg)
2409
+
2410
+ Parameter = cls._parameter_cls
2411
+
2412
+ # Parameter information.
2413
+ func_code = func.__code__
2414
+ pos_count = func_code.co_argcount
2415
+ arg_names = func_code.co_varnames
2416
+ posonly_count = func_code.co_posonlyargcount
2417
+ positional = arg_names[:pos_count]
2418
+ keyword_only_count = func_code.co_kwonlyargcount
2419
+ keyword_only = arg_names[pos_count:pos_count + keyword_only_count]
2420
+ annotations = get_annotations(func, globals=globals, locals=locals, eval_str=eval_str)
2421
+ defaults = func.__defaults__
2422
+ kwdefaults = func.__kwdefaults__
2423
+
2424
+ if defaults:
2425
+ pos_default_count = len(defaults)
2426
+ else:
2427
+ pos_default_count = 0
2428
+
2429
+ parameters = []
2430
+
2431
+ non_default_count = pos_count - pos_default_count
2432
+ posonly_left = posonly_count
2433
+
2434
+ # Non-keyword-only parameters w/o defaults.
2435
+ for name in positional[:non_default_count]:
2436
+ kind = _POSITIONAL_ONLY if posonly_left else _POSITIONAL_OR_KEYWORD
2437
+ annotation = annotations.get(name, _empty)
2438
+ parameters.append(Parameter(name, annotation=annotation,
2439
+ kind=kind))
2440
+ if posonly_left:
2441
+ posonly_left -= 1
2442
+
2443
+ # ... w/ defaults.
2444
+ for offset, name in enumerate(positional[non_default_count:]):
2445
+ kind = _POSITIONAL_ONLY if posonly_left else _POSITIONAL_OR_KEYWORD
2446
+ annotation = annotations.get(name, _empty)
2447
+ parameters.append(Parameter(name, annotation=annotation,
2448
+ kind=kind,
2449
+ default=defaults[offset]))
2450
+ if posonly_left:
2451
+ posonly_left -= 1
2452
+
2453
+ # *args
2454
+ if func_code.co_flags & CO_VARARGS:
2455
+ name = arg_names[pos_count + keyword_only_count]
2456
+ annotation = annotations.get(name, _empty)
2457
+ parameters.append(Parameter(name, annotation=annotation,
2458
+ kind=_VAR_POSITIONAL))
2459
+
2460
+ # Keyword-only parameters.
2461
+ for name in keyword_only:
2462
+ default = _empty
2463
+ if kwdefaults is not None:
2464
+ default = kwdefaults.get(name, _empty)
2465
+
2466
+ annotation = annotations.get(name, _empty)
2467
+ parameters.append(Parameter(name, annotation=annotation,
2468
+ kind=_KEYWORD_ONLY,
2469
+ default=default))
2470
+ # **kwargs
2471
+ if func_code.co_flags & CO_VARKEYWORDS:
2472
+ index = pos_count + keyword_only_count
2473
+ if func_code.co_flags & CO_VARARGS:
2474
+ index += 1
2475
+
2476
+ name = arg_names[index]
2477
+ annotation = annotations.get(name, _empty)
2478
+ parameters.append(Parameter(name, annotation=annotation,
2479
+ kind=_VAR_KEYWORD))
2480
+
2481
+ # Is 'func' is a pure Python function - don't validate the
2482
+ # parameters list (for correct order and defaults), it should be OK.
2483
+ return cls(parameters,
2484
+ return_annotation=annotations.get('return', _empty),
2485
+ __validate_parameters__=is_duck_function)
2486
+
2487
+
2488
+ def _descriptor_get(descriptor, obj):
2489
+ if isclass(descriptor):
2490
+ return descriptor
2491
+ get = getattr(type(descriptor), '__get__', _sentinel)
2492
+ if get is _sentinel:
2493
+ return descriptor
2494
+ return get(descriptor, obj, type(obj))
2495
+
2496
+
2497
+ def _signature_from_callable(obj, *,
2498
+ follow_wrapper_chains=True,
2499
+ skip_bound_arg=True,
2500
+ globals=None,
2501
+ locals=None,
2502
+ eval_str=False,
2503
+ sigcls):
2504
+
2505
+ """Private helper function to get signature for arbitrary
2506
+ callable objects.
2507
+ """
2508
+
2509
+ _get_signature_of = functools.partial(_signature_from_callable,
2510
+ follow_wrapper_chains=follow_wrapper_chains,
2511
+ skip_bound_arg=skip_bound_arg,
2512
+ globals=globals,
2513
+ locals=locals,
2514
+ sigcls=sigcls,
2515
+ eval_str=eval_str)
2516
+
2517
+ if not callable(obj):
2518
+ raise TypeError('{!r} is not a callable object'.format(obj))
2519
+
2520
+ if isinstance(obj, types.MethodType):
2521
+ # In this case we skip the first parameter of the underlying
2522
+ # function (usually `self` or `cls`).
2523
+ sig = _get_signature_of(obj.__func__)
2524
+
2525
+ if skip_bound_arg:
2526
+ return _signature_bound_method(sig)
2527
+ else:
2528
+ return sig
2529
+
2530
+ # Was this function wrapped by a decorator?
2531
+ if follow_wrapper_chains:
2532
+ # Unwrap until we find an explicit signature or a MethodType (which will be
2533
+ # handled explicitly below).
2534
+ obj = unwrap(obj, stop=(lambda f: hasattr(f, "__signature__")
2535
+ or isinstance(f, types.MethodType)))
2536
+ if isinstance(obj, types.MethodType):
2537
+ # If the unwrapped object is a *method*, we might want to
2538
+ # skip its first parameter (self).
2539
+ # See test_signature_wrapped_bound_method for details.
2540
+ return _get_signature_of(obj)
2541
+
2542
+ try:
2543
+ sig = obj.__signature__
2544
+ except AttributeError:
2545
+ pass
2546
+ else:
2547
+ if sig is not None:
2548
+ # since __text_signature__ is not writable on classes, __signature__
2549
+ # may contain text (or be a callable that returns text);
2550
+ # if so, convert it
2551
+ o_sig = sig
2552
+ if not isinstance(sig, (Signature, str)) and callable(sig):
2553
+ sig = sig()
2554
+ if isinstance(sig, str):
2555
+ sig = _signature_fromstr(sigcls, obj, sig)
2556
+ if not isinstance(sig, Signature):
2557
+ raise TypeError(
2558
+ 'unexpected object {!r} in __signature__ '
2559
+ 'attribute'.format(o_sig))
2560
+ return sig
2561
+
2562
+ try:
2563
+ partialmethod = obj._partialmethod
2564
+ except AttributeError:
2565
+ pass
2566
+ else:
2567
+ if isinstance(partialmethod, functools.partialmethod):
2568
+ # Unbound partialmethod (see functools.partialmethod)
2569
+ # This means, that we need to calculate the signature
2570
+ # as if it's a regular partial object, but taking into
2571
+ # account that the first positional argument
2572
+ # (usually `self`, or `cls`) will not be passed
2573
+ # automatically (as for boundmethods)
2574
+
2575
+ wrapped_sig = _get_signature_of(partialmethod.func)
2576
+
2577
+ sig = _signature_get_partial(wrapped_sig, partialmethod, (None,))
2578
+ first_wrapped_param = tuple(wrapped_sig.parameters.values())[0]
2579
+ if first_wrapped_param.kind is Parameter.VAR_POSITIONAL:
2580
+ # First argument of the wrapped callable is `*args`, as in
2581
+ # `partialmethod(lambda *args)`.
2582
+ return sig
2583
+ else:
2584
+ sig_params = tuple(sig.parameters.values())
2585
+ assert (not sig_params or
2586
+ first_wrapped_param is not sig_params[0])
2587
+ new_params = (first_wrapped_param,) + sig_params
2588
+ return sig.replace(parameters=new_params)
2589
+
2590
+ if isfunction(obj) or _signature_is_functionlike(obj):
2591
+ # If it's a pure Python function, or an object that is duck type
2592
+ # of a Python function (Cython functions, for instance), then:
2593
+ return _signature_from_function(sigcls, obj,
2594
+ skip_bound_arg=skip_bound_arg,
2595
+ globals=globals, locals=locals, eval_str=eval_str)
2596
+
2597
+ if _signature_is_builtin(obj):
2598
+ return _signature_from_builtin(sigcls, obj,
2599
+ skip_bound_arg=skip_bound_arg)
2600
+
2601
+ if isinstance(obj, functools.partial):
2602
+ wrapped_sig = _get_signature_of(obj.func)
2603
+ return _signature_get_partial(wrapped_sig, obj)
2604
+
2605
+ if isinstance(obj, type):
2606
+ # obj is a class or a metaclass
2607
+
2608
+ # First, let's see if it has an overloaded __call__ defined
2609
+ # in its metaclass
2610
+ call = _signature_get_user_defined_method(type(obj), '__call__')
2611
+ if call is not None:
2612
+ return _get_signature_of(call)
2613
+
2614
+ new = _signature_get_user_defined_method(obj, '__new__')
2615
+ init = _signature_get_user_defined_method(obj, '__init__')
2616
+
2617
+ # Go through the MRO and see if any class has user-defined
2618
+ # pure Python __new__ or __init__ method
2619
+ for base in obj.__mro__:
2620
+ # Now we check if the 'obj' class has an own '__new__' method
2621
+ if new is not None and '__new__' in base.__dict__:
2622
+ sig = _get_signature_of(new)
2623
+ if skip_bound_arg:
2624
+ sig = _signature_bound_method(sig)
2625
+ return sig
2626
+ # or an own '__init__' method
2627
+ elif init is not None and '__init__' in base.__dict__:
2628
+ return _get_signature_of(init)
2629
+
2630
+ # At this point we know, that `obj` is a class, with no user-
2631
+ # defined '__init__', '__new__', or class-level '__call__'
2632
+
2633
+ for base in obj.__mro__[:-1]:
2634
+ # Since '__text_signature__' is implemented as a
2635
+ # descriptor that extracts text signature from the
2636
+ # class docstring, if 'obj' is derived from a builtin
2637
+ # class, its own '__text_signature__' may be 'None'.
2638
+ # Therefore, we go through the MRO (except the last
2639
+ # class in there, which is 'object') to find the first
2640
+ # class with non-empty text signature.
2641
+ try:
2642
+ text_sig = base.__text_signature__
2643
+ except AttributeError:
2644
+ pass
2645
+ else:
2646
+ if text_sig:
2647
+ # If 'base' class has a __text_signature__ attribute:
2648
+ # return a signature based on it
2649
+ return _signature_fromstr(sigcls, base, text_sig)
2650
+
2651
+ # No '__text_signature__' was found for the 'obj' class.
2652
+ # Last option is to check if its '__init__' is
2653
+ # object.__init__ or type.__init__.
2654
+ if type not in obj.__mro__:
2655
+ # We have a class (not metaclass), but no user-defined
2656
+ # __init__ or __new__ for it
2657
+ if (obj.__init__ is object.__init__ and
2658
+ obj.__new__ is object.__new__):
2659
+ # Return a signature of 'object' builtin.
2660
+ return sigcls.from_callable(object)
2661
+ else:
2662
+ raise ValueError(
2663
+ 'no signature found for builtin type {!r}'.format(obj))
2664
+
2665
+ else:
2666
+ # An object with __call__
2667
+ call = getattr_static(type(obj), '__call__', None)
2668
+ if call is not None:
2669
+ call = _descriptor_get(call, obj)
2670
+ return _get_signature_of(call)
2671
+
2672
+ raise ValueError('callable {!r} is not supported by signature'.format(obj))
2673
+
2674
+
2675
+ class _void:
2676
+ """A private marker - used in Parameter & Signature."""
2677
+
2678
+
2679
+ class _empty:
2680
+ """Marker object for Signature.empty and Parameter.empty."""
2681
+
2682
+
2683
+ class _ParameterKind(enum.IntEnum):
2684
+ POSITIONAL_ONLY = 'positional-only'
2685
+ POSITIONAL_OR_KEYWORD = 'positional or keyword'
2686
+ VAR_POSITIONAL = 'variadic positional'
2687
+ KEYWORD_ONLY = 'keyword-only'
2688
+ VAR_KEYWORD = 'variadic keyword'
2689
+
2690
+ def __new__(cls, description):
2691
+ value = len(cls.__members__)
2692
+ member = int.__new__(cls, value)
2693
+ member._value_ = value
2694
+ member.description = description
2695
+ return member
2696
+
2697
+ def __str__(self):
2698
+ return self.name
2699
+
2700
+ _POSITIONAL_ONLY = _ParameterKind.POSITIONAL_ONLY
2701
+ _POSITIONAL_OR_KEYWORD = _ParameterKind.POSITIONAL_OR_KEYWORD
2702
+ _VAR_POSITIONAL = _ParameterKind.VAR_POSITIONAL
2703
+ _KEYWORD_ONLY = _ParameterKind.KEYWORD_ONLY
2704
+ _VAR_KEYWORD = _ParameterKind.VAR_KEYWORD
2705
+
2706
+
2707
+ class Parameter:
2708
+ """Represents a parameter in a function signature.
2709
+
2710
+ Has the following public attributes:
2711
+
2712
+ * name : str
2713
+ The name of the parameter as a string.
2714
+ * default : object
2715
+ The default value for the parameter if specified. If the
2716
+ parameter has no default value, this attribute is set to
2717
+ `Parameter.empty`.
2718
+ * annotation
2719
+ The annotation for the parameter if specified. If the
2720
+ parameter has no annotation, this attribute is set to
2721
+ `Parameter.empty`.
2722
+ * kind : str
2723
+ Describes how argument values are bound to the parameter.
2724
+ Possible values: `Parameter.POSITIONAL_ONLY`,
2725
+ `Parameter.POSITIONAL_OR_KEYWORD`, `Parameter.VAR_POSITIONAL`,
2726
+ `Parameter.KEYWORD_ONLY`, `Parameter.VAR_KEYWORD`.
2727
+ """
2728
+
2729
+ __slots__ = ('_name', '_kind', '_default', '_annotation')
2730
+
2731
+ POSITIONAL_ONLY = _POSITIONAL_ONLY
2732
+ POSITIONAL_OR_KEYWORD = _POSITIONAL_OR_KEYWORD
2733
+ VAR_POSITIONAL = _VAR_POSITIONAL
2734
+ KEYWORD_ONLY = _KEYWORD_ONLY
2735
+ VAR_KEYWORD = _VAR_KEYWORD
2736
+
2737
+ empty = _empty
2738
+
2739
+ def __init__(self, name, kind, *, default=_empty, annotation=_empty):
2740
+ try:
2741
+ self._kind = _ParameterKind(kind)
2742
+ except ValueError:
2743
+ raise ValueError(f'value {kind!r} is not a valid Parameter.kind')
2744
+ if default is not _empty:
2745
+ if self._kind in (_VAR_POSITIONAL, _VAR_KEYWORD):
2746
+ msg = '{} parameters cannot have default values'
2747
+ msg = msg.format(self._kind.description)
2748
+ raise ValueError(msg)
2749
+ self._default = default
2750
+ self._annotation = annotation
2751
+
2752
+ if name is _empty:
2753
+ raise ValueError('name is a required attribute for Parameter')
2754
+
2755
+ if not isinstance(name, str):
2756
+ msg = 'name must be a str, not a {}'.format(type(name).__name__)
2757
+ raise TypeError(msg)
2758
+
2759
+ if name[0] == '.' and name[1:].isdigit():
2760
+ # These are implicit arguments generated by comprehensions. In
2761
+ # order to provide a friendlier interface to users, we recast
2762
+ # their name as "implicitN" and treat them as positional-only.
2763
+ # See issue 19611.
2764
+ if self._kind != _POSITIONAL_OR_KEYWORD:
2765
+ msg = (
2766
+ 'implicit arguments must be passed as '
2767
+ 'positional or keyword arguments, not {}'
2768
+ )
2769
+ msg = msg.format(self._kind.description)
2770
+ raise ValueError(msg)
2771
+ self._kind = _POSITIONAL_ONLY
2772
+ name = 'implicit{}'.format(name[1:])
2773
+
2774
+ # It's possible for C functions to have a positional-only parameter
2775
+ # where the name is a keyword, so for compatibility we'll allow it.
2776
+ is_keyword = iskeyword(name) and self._kind is not _POSITIONAL_ONLY
2777
+ if is_keyword or not name.isidentifier():
2778
+ raise ValueError('{!r} is not a valid parameter name'.format(name))
2779
+
2780
+ self._name = name
2781
+
2782
+ def __reduce__(self):
2783
+ return (type(self),
2784
+ (self._name, self._kind),
2785
+ {'_default': self._default,
2786
+ '_annotation': self._annotation})
2787
+
2788
+ def __setstate__(self, state):
2789
+ self._default = state['_default']
2790
+ self._annotation = state['_annotation']
2791
+
2792
+ @property
2793
+ def name(self):
2794
+ return self._name
2795
+
2796
+ @property
2797
+ def default(self):
2798
+ return self._default
2799
+
2800
+ @property
2801
+ def annotation(self):
2802
+ return self._annotation
2803
+
2804
+ @property
2805
+ def kind(self):
2806
+ return self._kind
2807
+
2808
+ def replace(self, *, name=_void, kind=_void,
2809
+ annotation=_void, default=_void):
2810
+ """Creates a customized copy of the Parameter."""
2811
+
2812
+ if name is _void:
2813
+ name = self._name
2814
+
2815
+ if kind is _void:
2816
+ kind = self._kind
2817
+
2818
+ if annotation is _void:
2819
+ annotation = self._annotation
2820
+
2821
+ if default is _void:
2822
+ default = self._default
2823
+
2824
+ return type(self)(name, kind, default=default, annotation=annotation)
2825
+
2826
+ def __str__(self):
2827
+ kind = self.kind
2828
+ formatted = self._name
2829
+
2830
+ # Add annotation and default value
2831
+ if self._annotation is not _empty:
2832
+ formatted = '{}: {}'.format(formatted,
2833
+ formatannotation(self._annotation))
2834
+
2835
+ if self._default is not _empty:
2836
+ if self._annotation is not _empty:
2837
+ formatted = '{} = {}'.format(formatted, repr(self._default))
2838
+ else:
2839
+ formatted = '{}={}'.format(formatted, repr(self._default))
2840
+
2841
+ if kind == _VAR_POSITIONAL:
2842
+ formatted = '*' + formatted
2843
+ elif kind == _VAR_KEYWORD:
2844
+ formatted = '**' + formatted
2845
+
2846
+ return formatted
2847
+
2848
+ def __repr__(self):
2849
+ return '<{} "{}">'.format(self.__class__.__name__, self)
2850
+
2851
+ def __hash__(self):
2852
+ return hash((self._name, self._kind, self._annotation, self._default))
2853
+
2854
+ def __eq__(self, other):
2855
+ if self is other:
2856
+ return True
2857
+ if not isinstance(other, Parameter):
2858
+ return NotImplemented
2859
+ return (self._name == other._name and
2860
+ self._kind == other._kind and
2861
+ self._default == other._default and
2862
+ self._annotation == other._annotation)
2863
+
2864
+
2865
+ class BoundArguments:
2866
+ """Result of `Signature.bind` call. Holds the mapping of arguments
2867
+ to the function's parameters.
2868
+
2869
+ Has the following public attributes:
2870
+
2871
+ * arguments : dict
2872
+ An ordered mutable mapping of parameters' names to arguments' values.
2873
+ Does not contain arguments' default values.
2874
+ * signature : Signature
2875
+ The Signature object that created this instance.
2876
+ * args : tuple
2877
+ Tuple of positional arguments values.
2878
+ * kwargs : dict
2879
+ Dict of keyword arguments values.
2880
+ """
2881
+
2882
+ __slots__ = ('arguments', '_signature', '__weakref__')
2883
+
2884
+ def __init__(self, signature, arguments):
2885
+ self.arguments = arguments
2886
+ self._signature = signature
2887
+
2888
+ @property
2889
+ def signature(self):
2890
+ return self._signature
2891
+
2892
+ @property
2893
+ def args(self):
2894
+ args = []
2895
+ for param_name, param in self._signature.parameters.items():
2896
+ if param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY):
2897
+ break
2898
+
2899
+ try:
2900
+ arg = self.arguments[param_name]
2901
+ except KeyError:
2902
+ # We're done here. Other arguments
2903
+ # will be mapped in 'BoundArguments.kwargs'
2904
+ break
2905
+ else:
2906
+ if param.kind == _VAR_POSITIONAL:
2907
+ # *args
2908
+ args.extend(arg)
2909
+ else:
2910
+ # plain argument
2911
+ args.append(arg)
2912
+
2913
+ return tuple(args)
2914
+
2915
+ @property
2916
+ def kwargs(self):
2917
+ kwargs = {}
2918
+ kwargs_started = False
2919
+ for param_name, param in self._signature.parameters.items():
2920
+ if not kwargs_started:
2921
+ if param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY):
2922
+ kwargs_started = True
2923
+ else:
2924
+ if param_name not in self.arguments:
2925
+ kwargs_started = True
2926
+ continue
2927
+
2928
+ if not kwargs_started:
2929
+ continue
2930
+
2931
+ try:
2932
+ arg = self.arguments[param_name]
2933
+ except KeyError:
2934
+ pass
2935
+ else:
2936
+ if param.kind == _VAR_KEYWORD:
2937
+ # **kwargs
2938
+ kwargs.update(arg)
2939
+ else:
2940
+ # plain keyword argument
2941
+ kwargs[param_name] = arg
2942
+
2943
+ return kwargs
2944
+
2945
+ def apply_defaults(self):
2946
+ """Set default values for missing arguments.
2947
+
2948
+ For variable-positional arguments (*args) the default is an
2949
+ empty tuple.
2950
+
2951
+ For variable-keyword arguments (**kwargs) the default is an
2952
+ empty dict.
2953
+ """
2954
+ arguments = self.arguments
2955
+ new_arguments = []
2956
+ for name, param in self._signature.parameters.items():
2957
+ try:
2958
+ new_arguments.append((name, arguments[name]))
2959
+ except KeyError:
2960
+ if param.default is not _empty:
2961
+ val = param.default
2962
+ elif param.kind is _VAR_POSITIONAL:
2963
+ val = ()
2964
+ elif param.kind is _VAR_KEYWORD:
2965
+ val = {}
2966
+ else:
2967
+ # This BoundArguments was likely produced by
2968
+ # Signature.bind_partial().
2969
+ continue
2970
+ new_arguments.append((name, val))
2971
+ self.arguments = dict(new_arguments)
2972
+
2973
+ def __eq__(self, other):
2974
+ if self is other:
2975
+ return True
2976
+ if not isinstance(other, BoundArguments):
2977
+ return NotImplemented
2978
+ return (self.signature == other.signature and
2979
+ self.arguments == other.arguments)
2980
+
2981
+ def __setstate__(self, state):
2982
+ self._signature = state['_signature']
2983
+ self.arguments = state['arguments']
2984
+
2985
+ def __getstate__(self):
2986
+ return {'_signature': self._signature, 'arguments': self.arguments}
2987
+
2988
+ def __repr__(self):
2989
+ args = []
2990
+ for arg, value in self.arguments.items():
2991
+ args.append('{}={!r}'.format(arg, value))
2992
+ return '<{} ({})>'.format(self.__class__.__name__, ', '.join(args))
2993
+
2994
+
2995
+ class Signature:
2996
+ """A Signature object represents the overall signature of a function.
2997
+ It stores a Parameter object for each parameter accepted by the
2998
+ function, as well as information specific to the function itself.
2999
+
3000
+ A Signature object has the following public attributes and methods:
3001
+
3002
+ * parameters : OrderedDict
3003
+ An ordered mapping of parameters' names to the corresponding
3004
+ Parameter objects (keyword-only arguments are in the same order
3005
+ as listed in `code.co_varnames`).
3006
+ * return_annotation : object
3007
+ The annotation for the return type of the function if specified.
3008
+ If the function has no annotation for its return type, this
3009
+ attribute is set to `Signature.empty`.
3010
+ * bind(*args, **kwargs) -> BoundArguments
3011
+ Creates a mapping from positional and keyword arguments to
3012
+ parameters.
3013
+ * bind_partial(*args, **kwargs) -> BoundArguments
3014
+ Creates a partial mapping from positional and keyword arguments
3015
+ to parameters (simulating 'functools.partial' behavior.)
3016
+ """
3017
+
3018
+ __slots__ = ('_return_annotation', '_parameters')
3019
+
3020
+ _parameter_cls = Parameter
3021
+ _bound_arguments_cls = BoundArguments
3022
+
3023
+ empty = _empty
3024
+
3025
+ def __init__(self, parameters=None, *, return_annotation=_empty,
3026
+ __validate_parameters__=True):
3027
+ """Constructs Signature from the given list of Parameter
3028
+ objects and 'return_annotation'. All arguments are optional.
3029
+ """
3030
+
3031
+ if parameters is None:
3032
+ params = OrderedDict()
3033
+ else:
3034
+ if __validate_parameters__:
3035
+ params = OrderedDict()
3036
+ top_kind = _POSITIONAL_ONLY
3037
+ seen_default = False
3038
+
3039
+ for param in parameters:
3040
+ kind = param.kind
3041
+ name = param.name
3042
+
3043
+ if kind < top_kind:
3044
+ msg = (
3045
+ 'wrong parameter order: {} parameter before {} '
3046
+ 'parameter'
3047
+ )
3048
+ msg = msg.format(top_kind.description,
3049
+ kind.description)
3050
+ raise ValueError(msg)
3051
+ elif kind > top_kind:
3052
+ top_kind = kind
3053
+
3054
+ if kind in (_POSITIONAL_ONLY, _POSITIONAL_OR_KEYWORD):
3055
+ if param.default is _empty:
3056
+ if seen_default:
3057
+ # No default for this parameter, but the
3058
+ # previous parameter of had a default
3059
+ msg = 'non-default argument follows default ' \
3060
+ 'argument'
3061
+ raise ValueError(msg)
3062
+ else:
3063
+ # There is a default for this parameter.
3064
+ seen_default = True
3065
+
3066
+ if name in params:
3067
+ msg = 'duplicate parameter name: {!r}'.format(name)
3068
+ raise ValueError(msg)
3069
+
3070
+ params[name] = param
3071
+ else:
3072
+ params = OrderedDict((param.name, param) for param in parameters)
3073
+
3074
+ self._parameters = types.MappingProxyType(params)
3075
+ self._return_annotation = return_annotation
3076
+
3077
+ @classmethod
3078
+ def from_callable(cls, obj, *,
3079
+ follow_wrapped=True, globals=None, locals=None, eval_str=False):
3080
+ """Constructs Signature for the given callable object."""
3081
+ return _signature_from_callable(obj, sigcls=cls,
3082
+ follow_wrapper_chains=follow_wrapped,
3083
+ globals=globals, locals=locals, eval_str=eval_str)
3084
+
3085
+ @property
3086
+ def parameters(self):
3087
+ return self._parameters
3088
+
3089
+ @property
3090
+ def return_annotation(self):
3091
+ return self._return_annotation
3092
+
3093
+ def replace(self, *, parameters=_void, return_annotation=_void):
3094
+ """Creates a customized copy of the Signature.
3095
+ Pass 'parameters' and/or 'return_annotation' arguments
3096
+ to override them in the new copy.
3097
+ """
3098
+
3099
+ if parameters is _void:
3100
+ parameters = self.parameters.values()
3101
+
3102
+ if return_annotation is _void:
3103
+ return_annotation = self._return_annotation
3104
+
3105
+ return type(self)(parameters,
3106
+ return_annotation=return_annotation)
3107
+
3108
+ def _hash_basis(self):
3109
+ params = tuple(param for param in self.parameters.values()
3110
+ if param.kind != _KEYWORD_ONLY)
3111
+
3112
+ kwo_params = {param.name: param for param in self.parameters.values()
3113
+ if param.kind == _KEYWORD_ONLY}
3114
+
3115
+ return params, kwo_params, self.return_annotation
3116
+
3117
+ def __hash__(self):
3118
+ params, kwo_params, return_annotation = self._hash_basis()
3119
+ kwo_params = frozenset(kwo_params.values())
3120
+ return hash((params, kwo_params, return_annotation))
3121
+
3122
+ def __eq__(self, other):
3123
+ if self is other:
3124
+ return True
3125
+ if not isinstance(other, Signature):
3126
+ return NotImplemented
3127
+ return self._hash_basis() == other._hash_basis()
3128
+
3129
+ def _bind(self, args, kwargs, *, partial=False):
3130
+ """Private method. Don't use directly."""
3131
+
3132
+ arguments = {}
3133
+
3134
+ parameters = iter(self.parameters.values())
3135
+ parameters_ex = ()
3136
+ arg_vals = iter(args)
3137
+
3138
+ pos_only_param_in_kwargs = []
3139
+
3140
+ while True:
3141
+ # Let's iterate through the positional arguments and corresponding
3142
+ # parameters
3143
+ try:
3144
+ arg_val = next(arg_vals)
3145
+ except StopIteration:
3146
+ # No more positional arguments
3147
+ try:
3148
+ param = next(parameters)
3149
+ except StopIteration:
3150
+ # No more parameters. That's it. Just need to check that
3151
+ # we have no `kwargs` after this while loop
3152
+ break
3153
+ else:
3154
+ if param.kind == _VAR_POSITIONAL:
3155
+ # That's OK, just empty *args. Let's start parsing
3156
+ # kwargs
3157
+ break
3158
+ elif param.name in kwargs:
3159
+ if param.kind == _POSITIONAL_ONLY:
3160
+ # Raise a TypeError once we are sure there is no
3161
+ # **kwargs param later.
3162
+ pos_only_param_in_kwargs.append(param)
3163
+ continue
3164
+ parameters_ex = (param,)
3165
+ break
3166
+ elif (param.kind == _VAR_KEYWORD or
3167
+ param.default is not _empty):
3168
+ # That's fine too - we have a default value for this
3169
+ # parameter. So, lets start parsing `kwargs`, starting
3170
+ # with the current parameter
3171
+ parameters_ex = (param,)
3172
+ break
3173
+ else:
3174
+ # No default, not VAR_KEYWORD, not VAR_POSITIONAL,
3175
+ # not in `kwargs`
3176
+ if partial:
3177
+ parameters_ex = (param,)
3178
+ break
3179
+ else:
3180
+ if param.kind == _KEYWORD_ONLY:
3181
+ argtype = ' keyword-only'
3182
+ else:
3183
+ argtype = ''
3184
+ msg = 'missing a required{argtype} argument: {arg!r}'
3185
+ msg = msg.format(arg=param.name, argtype=argtype)
3186
+ raise TypeError(msg) from None
3187
+ else:
3188
+ # We have a positional argument to process
3189
+ try:
3190
+ param = next(parameters)
3191
+ except StopIteration:
3192
+ raise TypeError('too many positional arguments') from None
3193
+ else:
3194
+ if param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY):
3195
+ # Looks like we have no parameter for this positional
3196
+ # argument
3197
+ raise TypeError(
3198
+ 'too many positional arguments') from None
3199
+
3200
+ if param.kind == _VAR_POSITIONAL:
3201
+ # We have an '*args'-like argument, let's fill it with
3202
+ # all positional arguments we have left and move on to
3203
+ # the next phase
3204
+ values = [arg_val]
3205
+ values.extend(arg_vals)
3206
+ arguments[param.name] = tuple(values)
3207
+ break
3208
+
3209
+ if param.name in kwargs and param.kind != _POSITIONAL_ONLY:
3210
+ raise TypeError(
3211
+ 'multiple values for argument {arg!r}'.format(
3212
+ arg=param.name)) from None
3213
+
3214
+ arguments[param.name] = arg_val
3215
+
3216
+ # Now, we iterate through the remaining parameters to process
3217
+ # keyword arguments
3218
+ kwargs_param = None
3219
+ for param in itertools.chain(parameters_ex, parameters):
3220
+ if param.kind == _VAR_KEYWORD:
3221
+ # Memorize that we have a '**kwargs'-like parameter
3222
+ kwargs_param = param
3223
+ continue
3224
+
3225
+ if param.kind == _VAR_POSITIONAL:
3226
+ # Named arguments don't refer to '*args'-like parameters.
3227
+ # We only arrive here if the positional arguments ended
3228
+ # before reaching the last parameter before *args.
3229
+ continue
3230
+
3231
+ param_name = param.name
3232
+ try:
3233
+ arg_val = kwargs.pop(param_name)
3234
+ except KeyError:
3235
+ # We have no value for this parameter. It's fine though,
3236
+ # if it has a default value, or it is an '*args'-like
3237
+ # parameter, left alone by the processing of positional
3238
+ # arguments.
3239
+ if (not partial and param.kind != _VAR_POSITIONAL and
3240
+ param.default is _empty):
3241
+ raise TypeError('missing a required argument: {arg!r}'. \
3242
+ format(arg=param_name)) from None
3243
+
3244
+ else:
3245
+ arguments[param_name] = arg_val
3246
+
3247
+ if kwargs:
3248
+ if kwargs_param is not None:
3249
+ # Process our '**kwargs'-like parameter
3250
+ arguments[kwargs_param.name] = kwargs
3251
+ elif pos_only_param_in_kwargs:
3252
+ raise TypeError(
3253
+ 'got some positional-only arguments passed as '
3254
+ 'keyword arguments: {arg!r}'.format(
3255
+ arg=', '.join(
3256
+ param.name
3257
+ for param in pos_only_param_in_kwargs
3258
+ ),
3259
+ ),
3260
+ )
3261
+ else:
3262
+ raise TypeError(
3263
+ 'got an unexpected keyword argument {arg!r}'.format(
3264
+ arg=next(iter(kwargs))))
3265
+
3266
+ return self._bound_arguments_cls(self, arguments)
3267
+
3268
+ def bind(self, /, *args, **kwargs):
3269
+ """Get a BoundArguments object, that maps the passed `args`
3270
+ and `kwargs` to the function's signature. Raises `TypeError`
3271
+ if the passed arguments can not be bound.
3272
+ """
3273
+ return self._bind(args, kwargs)
3274
+
3275
+ def bind_partial(self, /, *args, **kwargs):
3276
+ """Get a BoundArguments object, that partially maps the
3277
+ passed `args` and `kwargs` to the function's signature.
3278
+ Raises `TypeError` if the passed arguments can not be bound.
3279
+ """
3280
+ return self._bind(args, kwargs, partial=True)
3281
+
3282
+ def __reduce__(self):
3283
+ return (type(self),
3284
+ (tuple(self._parameters.values()),),
3285
+ {'_return_annotation': self._return_annotation})
3286
+
3287
+ def __setstate__(self, state):
3288
+ self._return_annotation = state['_return_annotation']
3289
+
3290
+ def __repr__(self):
3291
+ return '<{} {}>'.format(self.__class__.__name__, self)
3292
+
3293
+ def __str__(self):
3294
+ result = []
3295
+ render_pos_only_separator = False
3296
+ render_kw_only_separator = True
3297
+ for param in self.parameters.values():
3298
+ formatted = str(param)
3299
+
3300
+ kind = param.kind
3301
+
3302
+ if kind == _POSITIONAL_ONLY:
3303
+ render_pos_only_separator = True
3304
+ elif render_pos_only_separator:
3305
+ # It's not a positional-only parameter, and the flag
3306
+ # is set to 'True' (there were pos-only params before.)
3307
+ result.append('/')
3308
+ render_pos_only_separator = False
3309
+
3310
+ if kind == _VAR_POSITIONAL:
3311
+ # OK, we have an '*args'-like parameter, so we won't need
3312
+ # a '*' to separate keyword-only arguments
3313
+ render_kw_only_separator = False
3314
+ elif kind == _KEYWORD_ONLY and render_kw_only_separator:
3315
+ # We have a keyword-only parameter to render and we haven't
3316
+ # rendered an '*args'-like parameter before, so add a '*'
3317
+ # separator to the parameters list ("foo(arg1, *, arg2)" case)
3318
+ result.append('*')
3319
+ # This condition should be only triggered once, so
3320
+ # reset the flag
3321
+ render_kw_only_separator = False
3322
+
3323
+ result.append(formatted)
3324
+
3325
+ if render_pos_only_separator:
3326
+ # There were only positional-only parameters, hence the
3327
+ # flag was not reset to 'False'
3328
+ result.append('/')
3329
+
3330
+ rendered = '({})'.format(', '.join(result))
3331
+
3332
+ if self.return_annotation is not _empty:
3333
+ anno = formatannotation(self.return_annotation)
3334
+ rendered += ' -> {}'.format(anno)
3335
+
3336
+ return rendered
3337
+
3338
+
3339
+ def signature(obj, *, follow_wrapped=True, globals=None, locals=None, eval_str=False):
3340
+ """Get a signature object for the passed callable."""
3341
+ return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
3342
+ globals=globals, locals=locals, eval_str=eval_str)
3343
+
3344
+
3345
+ class BufferFlags(enum.IntFlag):
3346
+ SIMPLE = 0x0
3347
+ WRITABLE = 0x1
3348
+ FORMAT = 0x4
3349
+ ND = 0x8
3350
+ STRIDES = 0x10 | ND
3351
+ C_CONTIGUOUS = 0x20 | STRIDES
3352
+ F_CONTIGUOUS = 0x40 | STRIDES
3353
+ ANY_CONTIGUOUS = 0x80 | STRIDES
3354
+ INDIRECT = 0x100 | STRIDES
3355
+ CONTIG = ND | WRITABLE
3356
+ CONTIG_RO = ND
3357
+ STRIDED = STRIDES | WRITABLE
3358
+ STRIDED_RO = STRIDES
3359
+ RECORDS = STRIDES | WRITABLE | FORMAT
3360
+ RECORDS_RO = STRIDES | FORMAT
3361
+ FULL = INDIRECT | WRITABLE | FORMAT
3362
+ FULL_RO = INDIRECT | FORMAT
3363
+ READ = 0x100
3364
+ WRITE = 0x200
3365
+
3366
+
3367
+ def _main():
3368
+ """ Logic for inspecting an object given at command line """
3369
+ import argparse
3370
+ import importlib
3371
+
3372
+ parser = argparse.ArgumentParser()
3373
+ parser.add_argument(
3374
+ 'object',
3375
+ help="The object to be analysed. "
3376
+ "It supports the 'module:qualname' syntax")
3377
+ parser.add_argument(
3378
+ '-d', '--details', action='store_true',
3379
+ help='Display info about the module rather than its source code')
3380
+
3381
+ args = parser.parse_args()
3382
+
3383
+ target = args.object
3384
+ mod_name, has_attrs, attrs = target.partition(":")
3385
+ try:
3386
+ obj = module = importlib.import_module(mod_name)
3387
+ except Exception as exc:
3388
+ msg = "Failed to import {} ({}: {})".format(mod_name,
3389
+ type(exc).__name__,
3390
+ exc)
3391
+ print(msg, file=sys.stderr)
3392
+ sys.exit(2)
3393
+
3394
+ if has_attrs:
3395
+ parts = attrs.split(".")
3396
+ obj = module
3397
+ for part in parts:
3398
+ obj = getattr(obj, part)
3399
+
3400
+ if module.__name__ in sys.builtin_module_names:
3401
+ print("Can't get info for builtin modules.", file=sys.stderr)
3402
+ sys.exit(1)
3403
+
3404
+ if args.details:
3405
+ print('Target: {}'.format(target))
3406
+ print('Origin: {}'.format(getsourcefile(module)))
3407
+ print('Cached: {}'.format(module.__cached__))
3408
+ if obj is module:
3409
+ print('Loader: {}'.format(repr(module.__loader__)))
3410
+ if hasattr(module, '__path__'):
3411
+ print('Submodule search path: {}'.format(module.__path__))
3412
+ else:
3413
+ try:
3414
+ __, lineno = findsource(obj)
3415
+ except Exception:
3416
+ pass
3417
+ else:
3418
+ print('Line: {}'.format(lineno))
3419
+
3420
+ print('\n')
3421
+ else:
3422
+ print(getsource(obj))
3423
+
3424
+
3425
+ if __name__ == "__main__":
3426
+ _main()