@v587d/capital-generation 2.29.0 → 2.30.1

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 (305) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +3 -3
  3. package/THIRD_PARTY_NOTICES.md +16 -0
  4. package/automation/package.json +1 -1
  5. package/chart-ui/package.json +1 -1
  6. package/config/package.json +1 -1
  7. package/lib/collector-runtime.js +56 -1
  8. package/lib/data-collector/catalog-taxonomy.d.ts +1 -1
  9. package/lib/data-collector/catalog-taxonomy.js +33 -0
  10. package/lib/data-collector/dataset-tools.js +4 -2
  11. package/lib/data-collector/describe.d.ts +2 -0
  12. package/lib/data-collector/describe.js +2 -0
  13. package/lib/data-collector/store.d.ts +11 -0
  14. package/lib/data-collector/store.js +80 -1
  15. package/lib/data-collector/tools.d.ts +1 -1
  16. package/lib/data-collector/tools.js +10 -9
  17. package/lib/python-runtime/errors.d.ts +1 -1
  18. package/lib/python-runtime/errors.js +2 -0
  19. package/lib/python-runtime/manager.d.ts +28 -1
  20. package/lib/python-runtime/manager.js +141 -5
  21. package/lib/python-runtime/probe.d.ts +24 -0
  22. package/lib/python-runtime/probe.js +66 -50
  23. package/lib/sources/csindex-http.d.ts +4 -0
  24. package/lib/sources/csindex-http.js +233 -0
  25. package/lib/sources/eastmoney-http.js +1504 -1
  26. package/lib/sources/fuyao-rest.js +168 -8
  27. package/lib/sources/official-http.d.ts +4 -0
  28. package/lib/sources/official-http.js +477 -0
  29. package/lib/sources/python-remote.d.ts +25 -0
  30. package/lib/sources/python-remote.js +461 -0
  31. package/lib/sources/sina-http.d.ts +2 -0
  32. package/lib/sources/sina-http.js +484 -0
  33. package/lib/sources/tencent-http.js +23 -8
  34. package/lib/sources/ths-http.d.ts +2 -0
  35. package/lib/sources/ths-http.js +517 -0
  36. package/lib/time/tools.js +19 -0
  37. package/lib/web-retriever/local-fetch.d.ts +1 -1
  38. package/lib/web-retriever/local-fetch.js +1 -1
  39. package/lib/web-retriever/sources.d.ts +7 -0
  40. package/lib/web-retriever/sources.js +46 -21
  41. package/lib/web-retriever/throttle.d.ts +8 -0
  42. package/lib/web-retriever/throttle.js +13 -0
  43. package/lib/web-retriever/tools.js +1 -1
  44. package/lib/web-retriever/wind-client.d.ts +1 -1
  45. package/lib/web-retriever/wind-client.js +1 -1
  46. package/package.json +1 -1
  47. package/preset/capital-generation/agent.patch.yml +7 -5
  48. package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +16 -16
  49. package/python/scripts/baostock_stock_basic.py +129 -0
  50. package/python/scripts/baostock_valuation_history.py +141 -0
  51. package/python/scripts/pbc_social_financing.py +291 -0
  52. package/python/vendor/baostock/LICENSE +19 -0
  53. package/python/vendor/baostock/__init__.py +42 -0
  54. package/python/vendor/baostock/common/__init__.py +0 -0
  55. package/python/vendor/baostock/common/contants.py +189 -0
  56. package/python/vendor/baostock/common/context.py +4 -0
  57. package/python/vendor/baostock/corpreport/__init__.py +0 -0
  58. package/python/vendor/baostock/corpreport/corp_performance.py +202 -0
  59. package/python/vendor/baostock/data/__init__.py +0 -0
  60. package/python/vendor/baostock/data/messageheader.py +17 -0
  61. package/python/vendor/baostock/data/msg.py +21 -0
  62. package/python/vendor/baostock/data/resultset.py +200 -0
  63. package/python/vendor/baostock/demo/__init__.py +0 -0
  64. package/python/vendor/baostock/demo/demo_A_stock_5mk-data.py +34 -0
  65. package/python/vendor/baostock/demo/demo_A_stock_k_data.py +36 -0
  66. package/python/vendor/baostock/demo/demo_AllStock.py +27 -0
  67. package/python/vendor/baostock/demo/demo_Balance_data.py +22 -0
  68. package/python/vendor/baostock/demo/demo_CashFlow_data.py +22 -0
  69. package/python/vendor/baostock/demo/demo_Dividend_data.py +35 -0
  70. package/python/vendor/baostock/demo/demo_Dupont_data.py +25 -0
  71. package/python/vendor/baostock/demo/demo_Forecast_report.py +24 -0
  72. package/python/vendor/baostock/demo/demo_Growth_data.py +22 -0
  73. package/python/vendor/baostock/demo/demo_Index_k_data.py +39 -0
  74. package/python/vendor/baostock/demo/demo_Operation_data.py +22 -0
  75. package/python/vendor/baostock/demo/demo_PerformanceExpress_report.py +25 -0
  76. package/python/vendor/baostock/demo/demo_Profit_data.py +22 -0
  77. package/python/vendor/baostock/demo/demo_TradeDates.py +27 -0
  78. package/python/vendor/baostock/demo/demo_adjust_factor_data.py +23 -0
  79. package/python/vendor/baostock/demo/demo_assignDayData.py +23 -0
  80. package/python/vendor/baostock/demo/demo_daily_adjust_factor_data.py +28 -0
  81. package/python/vendor/baostock/demo/demo_daily_k_4_AStock.py +28 -0
  82. package/python/vendor/baostock/demo/demo_daily_k_4_ETF.py +28 -0
  83. package/python/vendor/baostock/demo/demo_depositRate_data.py +26 -0
  84. package/python/vendor/baostock/demo/demo_hs300_stocks.py +26 -0
  85. package/python/vendor/baostock/demo/demo_loanRate_data.py +26 -0
  86. package/python/vendor/baostock/demo/demo_moneySupplyDataMonth_data.py +26 -0
  87. package/python/vendor/baostock/demo/demo_moneySupplyDataYear_data.py +26 -0
  88. package/python/vendor/baostock/demo/demo_requiredReserveRatio_data.py +26 -0
  89. package/python/vendor/baostock/demo/demo_set_API_key.py +37 -0
  90. package/python/vendor/baostock/demo/demo_stockBasic_data.py +27 -0
  91. package/python/vendor/baostock/demo/demo_stock_Valuation_indicator_data.py +34 -0
  92. package/python/vendor/baostock/demo/demo_stock_industry.py +26 -0
  93. package/python/vendor/baostock/demo/demo_sz50stocks.py +26 -0
  94. package/python/vendor/baostock/demo/demo_zz500_stock.py +26 -0
  95. package/python/vendor/baostock/evaluation/__init__.py +0 -0
  96. package/python/vendor/baostock/evaluation/season_index.py +758 -0
  97. package/python/vendor/baostock/login/__init__.py +0 -0
  98. package/python/vendor/baostock/login/loginout.py +230 -0
  99. package/python/vendor/baostock/macroscopic/__init__.py +0 -0
  100. package/python/vendor/baostock/macroscopic/economic_data.py +723 -0
  101. package/python/vendor/baostock/metadata/__init__.py +0 -0
  102. package/python/vendor/baostock/metadata/stock_metadata.py +207 -0
  103. package/python/vendor/baostock/security/__init__.py +0 -0
  104. package/python/vendor/baostock/security/history.py +265 -0
  105. package/python/vendor/baostock/security/sectorinfo.py +1024 -0
  106. package/python/vendor/baostock/util/__init__.py +0 -0
  107. package/python/vendor/baostock/util/socketutil.py +97 -0
  108. package/python/vendor/baostock/util/stringutil.py +83 -0
  109. package/python/vendor/et_xmlfile/LICENSE +23 -0
  110. package/python/vendor/et_xmlfile/LICENSE.python +298 -0
  111. package/python/vendor/et_xmlfile/__init__.py +8 -0
  112. package/python/vendor/et_xmlfile/incremental_tree.py +917 -0
  113. package/python/vendor/et_xmlfile/xmlfile.py +158 -0
  114. package/python/vendor/openpyxl/LICENSE +23 -0
  115. package/python/vendor/openpyxl/__init__.py +19 -0
  116. package/python/vendor/openpyxl/_constants.py +13 -0
  117. package/python/vendor/openpyxl/cell/__init__.py +4 -0
  118. package/python/vendor/openpyxl/cell/_writer.py +136 -0
  119. package/python/vendor/openpyxl/cell/cell.py +332 -0
  120. package/python/vendor/openpyxl/cell/read_only.py +136 -0
  121. package/python/vendor/openpyxl/cell/rich_text.py +202 -0
  122. package/python/vendor/openpyxl/cell/text.py +184 -0
  123. package/python/vendor/openpyxl/chart/_3d.py +105 -0
  124. package/python/vendor/openpyxl/chart/__init__.py +19 -0
  125. package/python/vendor/openpyxl/chart/_chart.py +199 -0
  126. package/python/vendor/openpyxl/chart/area_chart.py +106 -0
  127. package/python/vendor/openpyxl/chart/axis.py +401 -0
  128. package/python/vendor/openpyxl/chart/bar_chart.py +144 -0
  129. package/python/vendor/openpyxl/chart/bubble_chart.py +67 -0
  130. package/python/vendor/openpyxl/chart/chartspace.py +195 -0
  131. package/python/vendor/openpyxl/chart/data_source.py +246 -0
  132. package/python/vendor/openpyxl/chart/descriptors.py +43 -0
  133. package/python/vendor/openpyxl/chart/error_bar.py +62 -0
  134. package/python/vendor/openpyxl/chart/label.py +127 -0
  135. package/python/vendor/openpyxl/chart/layout.py +74 -0
  136. package/python/vendor/openpyxl/chart/legend.py +75 -0
  137. package/python/vendor/openpyxl/chart/line_chart.py +129 -0
  138. package/python/vendor/openpyxl/chart/marker.py +90 -0
  139. package/python/vendor/openpyxl/chart/picture.py +35 -0
  140. package/python/vendor/openpyxl/chart/pie_chart.py +177 -0
  141. package/python/vendor/openpyxl/chart/pivot.py +65 -0
  142. package/python/vendor/openpyxl/chart/plotarea.py +162 -0
  143. package/python/vendor/openpyxl/chart/print_settings.py +57 -0
  144. package/python/vendor/openpyxl/chart/radar_chart.py +55 -0
  145. package/python/vendor/openpyxl/chart/reader.py +32 -0
  146. package/python/vendor/openpyxl/chart/reference.py +124 -0
  147. package/python/vendor/openpyxl/chart/scatter_chart.py +53 -0
  148. package/python/vendor/openpyxl/chart/series.py +197 -0
  149. package/python/vendor/openpyxl/chart/series_factory.py +41 -0
  150. package/python/vendor/openpyxl/chart/shapes.py +89 -0
  151. package/python/vendor/openpyxl/chart/stock_chart.py +54 -0
  152. package/python/vendor/openpyxl/chart/surface_chart.py +119 -0
  153. package/python/vendor/openpyxl/chart/text.py +78 -0
  154. package/python/vendor/openpyxl/chart/title.py +76 -0
  155. package/python/vendor/openpyxl/chart/trendline.py +98 -0
  156. package/python/vendor/openpyxl/chart/updown_bars.py +31 -0
  157. package/python/vendor/openpyxl/chartsheet/__init__.py +3 -0
  158. package/python/vendor/openpyxl/chartsheet/chartsheet.py +107 -0
  159. package/python/vendor/openpyxl/chartsheet/custom.py +61 -0
  160. package/python/vendor/openpyxl/chartsheet/properties.py +28 -0
  161. package/python/vendor/openpyxl/chartsheet/protection.py +41 -0
  162. package/python/vendor/openpyxl/chartsheet/publish.py +58 -0
  163. package/python/vendor/openpyxl/chartsheet/relation.py +97 -0
  164. package/python/vendor/openpyxl/chartsheet/views.py +51 -0
  165. package/python/vendor/openpyxl/comments/__init__.py +4 -0
  166. package/python/vendor/openpyxl/comments/author.py +21 -0
  167. package/python/vendor/openpyxl/comments/comment_sheet.py +211 -0
  168. package/python/vendor/openpyxl/comments/comments.py +62 -0
  169. package/python/vendor/openpyxl/comments/shape_writer.py +112 -0
  170. package/python/vendor/openpyxl/compat/__init__.py +54 -0
  171. package/python/vendor/openpyxl/compat/abc.py +8 -0
  172. package/python/vendor/openpyxl/compat/numbers.py +43 -0
  173. package/python/vendor/openpyxl/compat/product.py +17 -0
  174. package/python/vendor/openpyxl/compat/singleton.py +40 -0
  175. package/python/vendor/openpyxl/compat/strings.py +25 -0
  176. package/python/vendor/openpyxl/descriptors/__init__.py +58 -0
  177. package/python/vendor/openpyxl/descriptors/base.py +272 -0
  178. package/python/vendor/openpyxl/descriptors/container.py +41 -0
  179. package/python/vendor/openpyxl/descriptors/excel.py +112 -0
  180. package/python/vendor/openpyxl/descriptors/namespace.py +12 -0
  181. package/python/vendor/openpyxl/descriptors/nested.py +129 -0
  182. package/python/vendor/openpyxl/descriptors/sequence.py +136 -0
  183. package/python/vendor/openpyxl/descriptors/serialisable.py +240 -0
  184. package/python/vendor/openpyxl/descriptors/slots.py +18 -0
  185. package/python/vendor/openpyxl/drawing/__init__.py +4 -0
  186. package/python/vendor/openpyxl/drawing/colors.py +435 -0
  187. package/python/vendor/openpyxl/drawing/connector.py +144 -0
  188. package/python/vendor/openpyxl/drawing/drawing.py +92 -0
  189. package/python/vendor/openpyxl/drawing/effect.py +407 -0
  190. package/python/vendor/openpyxl/drawing/fill.py +425 -0
  191. package/python/vendor/openpyxl/drawing/geometry.py +584 -0
  192. package/python/vendor/openpyxl/drawing/graphic.py +177 -0
  193. package/python/vendor/openpyxl/drawing/image.py +65 -0
  194. package/python/vendor/openpyxl/drawing/line.py +144 -0
  195. package/python/vendor/openpyxl/drawing/picture.py +144 -0
  196. package/python/vendor/openpyxl/drawing/properties.py +174 -0
  197. package/python/vendor/openpyxl/drawing/relation.py +17 -0
  198. package/python/vendor/openpyxl/drawing/spreadsheet_drawing.py +382 -0
  199. package/python/vendor/openpyxl/drawing/text.py +717 -0
  200. package/python/vendor/openpyxl/drawing/xdr.py +33 -0
  201. package/python/vendor/openpyxl/formatting/__init__.py +3 -0
  202. package/python/vendor/openpyxl/formatting/formatting.py +114 -0
  203. package/python/vendor/openpyxl/formatting/rule.py +291 -0
  204. package/python/vendor/openpyxl/formula/__init__.py +3 -0
  205. package/python/vendor/openpyxl/formula/tokenizer.py +446 -0
  206. package/python/vendor/openpyxl/formula/translate.py +166 -0
  207. package/python/vendor/openpyxl/packaging/__init__.py +3 -0
  208. package/python/vendor/openpyxl/packaging/core.py +115 -0
  209. package/python/vendor/openpyxl/packaging/custom.py +289 -0
  210. package/python/vendor/openpyxl/packaging/extended.py +137 -0
  211. package/python/vendor/openpyxl/packaging/interface.py +56 -0
  212. package/python/vendor/openpyxl/packaging/manifest.py +194 -0
  213. package/python/vendor/openpyxl/packaging/relationship.py +158 -0
  214. package/python/vendor/openpyxl/packaging/workbook.py +185 -0
  215. package/python/vendor/openpyxl/pivot/__init__.py +1 -0
  216. package/python/vendor/openpyxl/pivot/cache.py +965 -0
  217. package/python/vendor/openpyxl/pivot/fields.py +326 -0
  218. package/python/vendor/openpyxl/pivot/record.py +111 -0
  219. package/python/vendor/openpyxl/pivot/table.py +1261 -0
  220. package/python/vendor/openpyxl/reader/__init__.py +1 -0
  221. package/python/vendor/openpyxl/reader/drawings.py +71 -0
  222. package/python/vendor/openpyxl/reader/excel.py +349 -0
  223. package/python/vendor/openpyxl/reader/strings.py +44 -0
  224. package/python/vendor/openpyxl/reader/workbook.py +133 -0
  225. package/python/vendor/openpyxl/styles/__init__.py +11 -0
  226. package/python/vendor/openpyxl/styles/alignment.py +62 -0
  227. package/python/vendor/openpyxl/styles/borders.py +103 -0
  228. package/python/vendor/openpyxl/styles/builtins.py +1397 -0
  229. package/python/vendor/openpyxl/styles/cell_style.py +206 -0
  230. package/python/vendor/openpyxl/styles/colors.py +172 -0
  231. package/python/vendor/openpyxl/styles/differential.py +95 -0
  232. package/python/vendor/openpyxl/styles/fills.py +224 -0
  233. package/python/vendor/openpyxl/styles/fonts.py +113 -0
  234. package/python/vendor/openpyxl/styles/named_styles.py +282 -0
  235. package/python/vendor/openpyxl/styles/numbers.py +200 -0
  236. package/python/vendor/openpyxl/styles/protection.py +17 -0
  237. package/python/vendor/openpyxl/styles/proxy.py +62 -0
  238. package/python/vendor/openpyxl/styles/styleable.py +151 -0
  239. package/python/vendor/openpyxl/styles/stylesheet.py +274 -0
  240. package/python/vendor/openpyxl/styles/table.py +94 -0
  241. package/python/vendor/openpyxl/utils/__init__.py +17 -0
  242. package/python/vendor/openpyxl/utils/bound_dictionary.py +26 -0
  243. package/python/vendor/openpyxl/utils/cell.py +240 -0
  244. package/python/vendor/openpyxl/utils/dataframe.py +87 -0
  245. package/python/vendor/openpyxl/utils/datetime.py +140 -0
  246. package/python/vendor/openpyxl/utils/escape.py +43 -0
  247. package/python/vendor/openpyxl/utils/exceptions.py +34 -0
  248. package/python/vendor/openpyxl/utils/formulas.py +24 -0
  249. package/python/vendor/openpyxl/utils/indexed_list.py +49 -0
  250. package/python/vendor/openpyxl/utils/inference.py +60 -0
  251. package/python/vendor/openpyxl/utils/protection.py +22 -0
  252. package/python/vendor/openpyxl/utils/units.py +108 -0
  253. package/python/vendor/openpyxl/workbook/__init__.py +4 -0
  254. package/python/vendor/openpyxl/workbook/_writer.py +197 -0
  255. package/python/vendor/openpyxl/workbook/child.py +166 -0
  256. package/python/vendor/openpyxl/workbook/defined_name.py +189 -0
  257. package/python/vendor/openpyxl/workbook/external_link/__init__.py +3 -0
  258. package/python/vendor/openpyxl/workbook/external_link/external.py +190 -0
  259. package/python/vendor/openpyxl/workbook/external_reference.py +18 -0
  260. package/python/vendor/openpyxl/workbook/function_group.py +36 -0
  261. package/python/vendor/openpyxl/workbook/properties.py +151 -0
  262. package/python/vendor/openpyxl/workbook/protection.py +163 -0
  263. package/python/vendor/openpyxl/workbook/smart_tags.py +56 -0
  264. package/python/vendor/openpyxl/workbook/views.py +155 -0
  265. package/python/vendor/openpyxl/workbook/web.py +98 -0
  266. package/python/vendor/openpyxl/workbook/workbook.py +438 -0
  267. package/python/vendor/openpyxl/worksheet/__init__.py +1 -0
  268. package/python/vendor/openpyxl/worksheet/_read_only.py +190 -0
  269. package/python/vendor/openpyxl/worksheet/_reader.py +472 -0
  270. package/python/vendor/openpyxl/worksheet/_write_only.py +160 -0
  271. package/python/vendor/openpyxl/worksheet/_writer.py +390 -0
  272. package/python/vendor/openpyxl/worksheet/cell_range.py +512 -0
  273. package/python/vendor/openpyxl/worksheet/cell_watch.py +34 -0
  274. package/python/vendor/openpyxl/worksheet/controls.py +107 -0
  275. package/python/vendor/openpyxl/worksheet/copier.py +70 -0
  276. package/python/vendor/openpyxl/worksheet/custom.py +35 -0
  277. package/python/vendor/openpyxl/worksheet/datavalidation.py +202 -0
  278. package/python/vendor/openpyxl/worksheet/dimensions.py +306 -0
  279. package/python/vendor/openpyxl/worksheet/drawing.py +14 -0
  280. package/python/vendor/openpyxl/worksheet/errors.py +93 -0
  281. package/python/vendor/openpyxl/worksheet/filters.py +486 -0
  282. package/python/vendor/openpyxl/worksheet/formula.py +51 -0
  283. package/python/vendor/openpyxl/worksheet/header_footer.py +270 -0
  284. package/python/vendor/openpyxl/worksheet/hyperlink.py +46 -0
  285. package/python/vendor/openpyxl/worksheet/merge.py +141 -0
  286. package/python/vendor/openpyxl/worksheet/ole.py +133 -0
  287. package/python/vendor/openpyxl/worksheet/page.py +174 -0
  288. package/python/vendor/openpyxl/worksheet/pagebreak.py +94 -0
  289. package/python/vendor/openpyxl/worksheet/picture.py +8 -0
  290. package/python/vendor/openpyxl/worksheet/print_settings.py +184 -0
  291. package/python/vendor/openpyxl/worksheet/properties.py +97 -0
  292. package/python/vendor/openpyxl/worksheet/protection.py +120 -0
  293. package/python/vendor/openpyxl/worksheet/related.py +17 -0
  294. package/python/vendor/openpyxl/worksheet/scenario.py +105 -0
  295. package/python/vendor/openpyxl/worksheet/smart_tag.py +78 -0
  296. package/python/vendor/openpyxl/worksheet/table.py +385 -0
  297. package/python/vendor/openpyxl/worksheet/views.py +155 -0
  298. package/python/vendor/openpyxl/worksheet/worksheet.py +907 -0
  299. package/python/vendor/openpyxl/writer/__init__.py +1 -0
  300. package/python/vendor/openpyxl/writer/excel.py +295 -0
  301. package/python/vendor/openpyxl/writer/theme.py +291 -0
  302. package/python/vendor/openpyxl/xml/__init__.py +42 -0
  303. package/python/vendor/openpyxl/xml/constants.py +129 -0
  304. package/python/vendor/openpyxl/xml/functions.py +87 -0
  305. package/watchlist/package.json +1 -1
@@ -0,0 +1,272 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+
4
+ """
5
+ Based on Python Cookbook 3rd Edition, 8.13
6
+ http://chimera.labs.oreilly.com/books/1230000000393/ch08.html#_discussiuncion_130
7
+ """
8
+
9
+ import datetime
10
+ import re
11
+
12
+ from openpyxl import DEBUG
13
+ from openpyxl.utils.datetime import from_ISO8601
14
+
15
+ from .namespace import namespaced
16
+
17
+ class Descriptor:
18
+
19
+ def __init__(self, name=None, **kw):
20
+ self.name = name
21
+ for k, v in kw.items():
22
+ setattr(self, k, v)
23
+
24
+ def __set__(self, instance, value):
25
+ instance.__dict__[self.name] = value
26
+
27
+
28
+ class Typed(Descriptor):
29
+ """Values must of a particular type"""
30
+
31
+ expected_type = type(None)
32
+ allow_none = False
33
+ nested = False
34
+
35
+ def __init__(self, *args, **kw):
36
+ super().__init__(*args, **kw)
37
+ self.__doc__ = f"Values must be of type {self.expected_type}"
38
+
39
+ def __set__(self, instance, value):
40
+ if not isinstance(value, self.expected_type):
41
+ if (not self.allow_none
42
+ or (self.allow_none and value is not None)):
43
+ msg = f"{instance.__class__}.{self.name} should be {self.expected_type} but value is {type(value)}"
44
+ if DEBUG:
45
+ msg = f"{instance.__class__}.{self.name} should be {self.expected_type} but {value} is {type(value)}"
46
+ raise TypeError(msg)
47
+ super().__set__(instance, value)
48
+
49
+ def __repr__(self):
50
+ return self.__doc__
51
+
52
+
53
+ def _convert(expected_type, value):
54
+ """
55
+ Check value is of or can be converted to expected type.
56
+ """
57
+ if not isinstance(value, expected_type):
58
+ try:
59
+ value = expected_type(value)
60
+ except:
61
+ raise TypeError('expected ' + str(expected_type))
62
+ return value
63
+
64
+
65
+ class Convertible(Typed):
66
+ """Values must be convertible to a particular type"""
67
+
68
+ def __set__(self, instance, value):
69
+ if ((self.allow_none and value is not None)
70
+ or not self.allow_none):
71
+ value = _convert(self.expected_type, value)
72
+ super().__set__(instance, value)
73
+
74
+
75
+ class Max(Convertible):
76
+ """Values must be less than a `max` value"""
77
+
78
+ expected_type = float
79
+ allow_none = False
80
+
81
+ def __init__(self, **kw):
82
+ if 'max' not in kw and not hasattr(self, 'max'):
83
+ raise TypeError('missing max value')
84
+ super().__init__(**kw)
85
+
86
+ def __set__(self, instance, value):
87
+ if ((self.allow_none and value is not None)
88
+ or not self.allow_none):
89
+ value = _convert(self.expected_type, value)
90
+ if value > self.max:
91
+ raise ValueError('Max value is {0}'.format(self.max))
92
+ super().__set__(instance, value)
93
+
94
+
95
+ class Min(Convertible):
96
+ """Values must be greater than a `min` value"""
97
+
98
+ expected_type = float
99
+ allow_none = False
100
+
101
+ def __init__(self, **kw):
102
+ if 'min' not in kw and not hasattr(self, 'min'):
103
+ raise TypeError('missing min value')
104
+ super().__init__(**kw)
105
+
106
+ def __set__(self, instance, value):
107
+ if ((self.allow_none and value is not None)
108
+ or not self.allow_none):
109
+ value = _convert(self.expected_type, value)
110
+ if value < self.min:
111
+ raise ValueError('Min value is {0}'.format(self.min))
112
+ super().__set__(instance, value)
113
+
114
+
115
+ class MinMax(Min, Max):
116
+ """Values must be greater than `min` value and less than a `max` one"""
117
+ pass
118
+
119
+
120
+ class Set(Descriptor):
121
+ """Value can only be from a set of know values"""
122
+
123
+ def __init__(self, name=None, **kw):
124
+ if not 'values' in kw:
125
+ raise TypeError("missing set of values")
126
+ kw['values'] = set(kw['values'])
127
+ super().__init__(name, **kw)
128
+ self.__doc__ = "Value must be one of {0}".format(self.values)
129
+
130
+ def __set__(self, instance, value):
131
+ if value not in self.values:
132
+ raise ValueError(self.__doc__)
133
+ super().__set__(instance, value)
134
+
135
+
136
+ class NoneSet(Set):
137
+
138
+ """'none' will be treated as None"""
139
+
140
+ def __init__(self, name=None, **kw):
141
+ super().__init__(name, **kw)
142
+ self.values.add(None)
143
+
144
+ def __set__(self, instance, value):
145
+ if value == 'none':
146
+ value = None
147
+ super().__set__(instance, value)
148
+
149
+
150
+ class Integer(Convertible):
151
+
152
+ expected_type = int
153
+
154
+
155
+ class Float(Convertible):
156
+
157
+ expected_type = float
158
+
159
+
160
+ class Bool(Convertible):
161
+
162
+ expected_type = bool
163
+
164
+ def __set__(self, instance, value):
165
+ if isinstance(value, str):
166
+ if value in ('false', 'f', '0'):
167
+ value = False
168
+ super().__set__(instance, value)
169
+
170
+
171
+ class String(Typed):
172
+
173
+ expected_type = str
174
+
175
+
176
+ class Text(String, Convertible):
177
+
178
+ pass
179
+
180
+
181
+ class ASCII(Typed):
182
+
183
+ expected_type = bytes
184
+
185
+
186
+ class Tuple(Typed):
187
+
188
+ expected_type = tuple
189
+
190
+
191
+ class Length(Descriptor):
192
+
193
+ def __init__(self, name=None, **kw):
194
+ if "length" not in kw:
195
+ raise TypeError("value length must be supplied")
196
+ super().__init__(**kw)
197
+
198
+
199
+ def __set__(self, instance, value):
200
+ if len(value) != self.length:
201
+ raise ValueError("Value must be length {0}".format(self.length))
202
+ super().__set__(instance, value)
203
+
204
+
205
+ class Default(Typed):
206
+ """
207
+ When called returns an instance of the expected type.
208
+ Additional default values can be passed in to the descriptor
209
+ """
210
+
211
+ def __init__(self, name=None, **kw):
212
+ if "defaults" not in kw:
213
+ kw['defaults'] = {}
214
+ super().__init__(**kw)
215
+
216
+ def __call__(self):
217
+ return self.expected_type()
218
+
219
+
220
+ class Alias(Descriptor):
221
+ """
222
+ Aliases can be used when either the desired attribute name is not allowed
223
+ or confusing in Python (eg. "type") or a more descriptive name is desired
224
+ (eg. "underline" for "u")
225
+ """
226
+
227
+ def __init__(self, alias):
228
+ self.alias = alias
229
+
230
+ def __set__(self, instance, value):
231
+ setattr(instance, self.alias, value)
232
+
233
+ def __get__(self, instance, cls):
234
+ return getattr(instance, self.alias)
235
+
236
+
237
+ class MatchPattern(Descriptor):
238
+ """Values must match a regex pattern """
239
+ allow_none = False
240
+
241
+ def __init__(self, name=None, **kw):
242
+ if 'pattern' not in kw and not hasattr(self, 'pattern'):
243
+ raise TypeError('missing pattern value')
244
+
245
+ super().__init__(name, **kw)
246
+ self.test_pattern = re.compile(self.pattern, re.VERBOSE)
247
+
248
+
249
+ def __set__(self, instance, value):
250
+
251
+ if value is None and not self.allow_none:
252
+ raise ValueError("Value must not be none")
253
+
254
+ if ((self.allow_none and value is not None)
255
+ or not self.allow_none):
256
+ if not self.test_pattern.match(value):
257
+ raise ValueError('Value does not match pattern {0}'.format(self.pattern))
258
+
259
+ super().__set__(instance, value)
260
+
261
+
262
+ class DateTime(Typed):
263
+
264
+ expected_type = datetime.datetime
265
+
266
+ def __set__(self, instance, value):
267
+ if value is not None and isinstance(value, str):
268
+ try:
269
+ value = from_ISO8601(value)
270
+ except ValueError:
271
+ raise ValueError("Value must be ISO datetime format")
272
+ super().__set__(instance, value)
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ """
4
+ Utility list for top level containers that contain one type of element
5
+
6
+ Provides the necessary API to read and write XML
7
+ """
8
+
9
+ from openpyxl.xml.functions import Element
10
+
11
+
12
+ class ElementList(list):
13
+
14
+
15
+ @property
16
+ def tagname(self):
17
+ raise NotImplementedError
18
+
19
+
20
+ @property
21
+ def expected_type(self):
22
+ raise NotImplementedError
23
+
24
+
25
+ @classmethod
26
+ def from_tree(cls, tree):
27
+ l = [cls.expected_type.from_tree(el) for el in tree]
28
+ return cls(l)
29
+
30
+
31
+ def to_tree(self):
32
+ container = Element(self.tagname)
33
+ for el in self:
34
+ container.append(el.to_tree())
35
+ return container
36
+
37
+
38
+ def append(self, value):
39
+ if not isinstance(value, self.expected_type):
40
+ raise TypeError(f"Value must of type {self.expected_type} {type(value)} provided")
41
+ super().append(value)
@@ -0,0 +1,112 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ """
4
+ Excel specific descriptors
5
+ """
6
+
7
+ from openpyxl.xml.constants import REL_NS
8
+ from openpyxl.compat import safe_string
9
+ from openpyxl.xml.functions import Element
10
+
11
+ from . import (
12
+ MatchPattern,
13
+ MinMax,
14
+ Integer,
15
+ String,
16
+ Sequence,
17
+ )
18
+ from .serialisable import Serialisable
19
+
20
+
21
+ class HexBinary(MatchPattern):
22
+
23
+ pattern = "[0-9a-fA-F]+$"
24
+
25
+
26
+ class UniversalMeasure(MatchPattern):
27
+
28
+ pattern = r"[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)"
29
+
30
+
31
+ class TextPoint(MinMax):
32
+ """
33
+ Size in hundredths of points.
34
+ In theory other units of measurement can be used but these are unbounded
35
+ """
36
+ expected_type = int
37
+
38
+ min = -400000
39
+ max = 400000
40
+
41
+
42
+ Coordinate = Integer
43
+
44
+
45
+ class Percentage(MinMax):
46
+
47
+ pattern = r"((100)|([0-9][0-9]?))(\.[0-9][0-9]?)?%" # strict
48
+ min = -1000000
49
+ max = 1000000
50
+
51
+ def __set__(self, instance, value):
52
+ if isinstance(value, str) and "%" in value:
53
+ value = value.replace("%", "")
54
+ value = int(float(value) * 1000)
55
+ super().__set__(instance, value)
56
+
57
+
58
+ class Extension(Serialisable):
59
+
60
+ uri = String()
61
+
62
+ def __init__(self,
63
+ uri=None,
64
+ ):
65
+ self.uri = uri
66
+
67
+
68
+ class ExtensionList(Serialisable):
69
+
70
+ ext = Sequence(expected_type=Extension)
71
+
72
+ def __init__(self,
73
+ ext=(),
74
+ ):
75
+ self.ext = ext
76
+
77
+
78
+ class Relation(String):
79
+
80
+ namespace = REL_NS
81
+ allow_none = True
82
+
83
+
84
+ class Base64Binary(MatchPattern):
85
+ # http://www.w3.org/TR/xmlschema11-2/#nt-Base64Binary
86
+ pattern = "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$"
87
+
88
+
89
+ class Guid(MatchPattern):
90
+ # https://msdn.microsoft.com/en-us/library/dd946381(v=office.12).aspx
91
+ pattern = r"{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}"
92
+
93
+
94
+ class CellRange(MatchPattern):
95
+
96
+ pattern = r"^[$]?([A-Za-z]{1,3})[$]?(\d+)(:[$]?([A-Za-z]{1,3})[$]?(\d+)?)?$|^[A-Za-z]{1,3}:[A-Za-z]{1,3}$"
97
+ allow_none = True
98
+
99
+ def __set__(self, instance, value):
100
+
101
+ if value is not None:
102
+ value = value.upper()
103
+ super().__set__(instance, value)
104
+
105
+
106
+ def _explicit_none(tagname, value, namespace=None):
107
+ """
108
+ Override serialisation because explicit none required
109
+ """
110
+ if namespace is not None:
111
+ tagname = "{%s}%s" % (namespace, tagname)
112
+ return Element(tagname, val=safe_string(value))
@@ -0,0 +1,12 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+
4
+ def namespaced(obj, tagname, namespace=None):
5
+ """
6
+ Utility to create a namespaced tag for an object
7
+ """
8
+
9
+ namespace = getattr(obj, "namespace", None) or namespace
10
+ if namespace is not None:
11
+ tagname = "{%s}%s" % (namespace, tagname)
12
+ return tagname
@@ -0,0 +1,129 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ """
4
+ Generic serialisable classes
5
+ """
6
+ from .base import (
7
+ Convertible,
8
+ Bool,
9
+ Descriptor,
10
+ NoneSet,
11
+ MinMax,
12
+ Set,
13
+ Float,
14
+ Integer,
15
+ String,
16
+ )
17
+ from openpyxl.compat import safe_string
18
+ from openpyxl.xml.functions import Element, localname, whitespace
19
+
20
+
21
+ class Nested(Descriptor):
22
+
23
+ nested = True
24
+ attribute = "val"
25
+
26
+ def __set__(self, instance, value):
27
+ if hasattr(value, "tag"):
28
+ tag = localname(value)
29
+ if tag != self.name:
30
+ raise ValueError("Tag does not match attribute")
31
+
32
+ value = self.from_tree(value)
33
+ super().__set__(instance, value)
34
+
35
+
36
+ def from_tree(self, node):
37
+ return node.get(self.attribute)
38
+
39
+
40
+ def to_tree(self, tagname=None, value=None, namespace=None):
41
+ namespace = getattr(self, "namespace", namespace)
42
+ if value is not None:
43
+ if namespace is not None:
44
+ tagname = "{%s}%s" % (namespace, tagname)
45
+ value = safe_string(value)
46
+ return Element(tagname, {self.attribute:value})
47
+
48
+
49
+ class NestedValue(Nested, Convertible):
50
+ """
51
+ Nested tag storing the value on the 'val' attribute
52
+ """
53
+ pass
54
+
55
+
56
+ class NestedText(NestedValue):
57
+ """
58
+ Represents any nested tag with the value as the contents of the tag
59
+ """
60
+
61
+
62
+ def from_tree(self, node):
63
+ return node.text
64
+
65
+
66
+ def to_tree(self, tagname=None, value=None, namespace=None):
67
+ namespace = getattr(self, "namespace", namespace)
68
+ if value is not None:
69
+ if namespace is not None:
70
+ tagname = "{%s}%s" % (namespace, tagname)
71
+ el = Element(tagname)
72
+ el.text = safe_string(value)
73
+ whitespace(el)
74
+ return el
75
+
76
+
77
+ class NestedFloat(NestedValue, Float):
78
+
79
+ pass
80
+
81
+
82
+ class NestedInteger(NestedValue, Integer):
83
+
84
+ pass
85
+
86
+
87
+ class NestedString(NestedValue, String):
88
+
89
+ pass
90
+
91
+
92
+ class NestedBool(NestedValue, Bool):
93
+
94
+
95
+ def from_tree(self, node):
96
+ return node.get("val", True)
97
+
98
+
99
+ class NestedNoneSet(Nested, NoneSet):
100
+
101
+ pass
102
+
103
+
104
+ class NestedSet(Nested, Set):
105
+
106
+ pass
107
+
108
+
109
+ class NestedMinMax(Nested, MinMax):
110
+
111
+ pass
112
+
113
+
114
+ class EmptyTag(Nested, Bool):
115
+
116
+ """
117
+ Boolean if a tag exists or not.
118
+ """
119
+
120
+ def from_tree(self, node):
121
+ return True
122
+
123
+
124
+ def to_tree(self, tagname=None, value=None, namespace=None):
125
+ if value:
126
+ namespace = getattr(self, "namespace", namespace)
127
+ if namespace is not None:
128
+ tagname = "{%s}%s" % (namespace, tagname)
129
+ return Element(tagname)
@@ -0,0 +1,136 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ from openpyxl.compat import safe_string
4
+ from openpyxl.xml.functions import Element
5
+ from openpyxl.utils.indexed_list import IndexedList
6
+
7
+ from .base import Descriptor, Alias, _convert
8
+ from .namespace import namespaced
9
+
10
+
11
+ class Sequence(Descriptor):
12
+ """
13
+ A sequence (list or tuple) that may only contain objects of the declared
14
+ type
15
+ """
16
+
17
+ expected_type = type(None)
18
+ seq_types = (list, tuple)
19
+ idx_base = 0
20
+ unique = False
21
+ container = list
22
+
23
+
24
+ def __set__(self, instance, seq):
25
+ if not isinstance(seq, self.seq_types):
26
+ raise TypeError("Value must be a sequence")
27
+ seq = self.container(_convert(self.expected_type, value) for value in seq)
28
+ if self.unique:
29
+ seq = IndexedList(seq)
30
+
31
+ super().__set__(instance, seq)
32
+
33
+
34
+ def to_tree(self, tagname, obj, namespace=None):
35
+ """
36
+ Convert the sequence represented by the descriptor to an XML element
37
+ """
38
+ for idx, v in enumerate(obj, self.idx_base):
39
+ if hasattr(v, "to_tree"):
40
+ el = v.to_tree(tagname, idx)
41
+ else:
42
+ tagname = namespaced(obj, tagname, namespace)
43
+ el = Element(tagname)
44
+ el.text = safe_string(v)
45
+ yield el
46
+
47
+
48
+ class UniqueSequence(Sequence):
49
+ """
50
+ Use a set to keep values unique
51
+ """
52
+ seq_types = (list, tuple, set)
53
+ container = set
54
+
55
+
56
+ class ValueSequence(Sequence):
57
+ """
58
+ A sequence of primitive types that are stored as a single attribute.
59
+ "val" is the default attribute
60
+ """
61
+
62
+ attribute = "val"
63
+
64
+
65
+ def to_tree(self, tagname, obj, namespace=None):
66
+ tagname = namespaced(self, tagname, namespace)
67
+ for v in obj:
68
+ yield Element(tagname, {self.attribute:safe_string(v)})
69
+
70
+
71
+ def from_tree(self, node):
72
+
73
+ return node.get(self.attribute)
74
+
75
+
76
+ class NestedSequence(Sequence):
77
+ """
78
+ Wrap a sequence in an containing object
79
+ """
80
+
81
+ count = False
82
+
83
+ def to_tree(self, tagname, obj, namespace=None):
84
+ tagname = namespaced(self, tagname, namespace)
85
+ container = Element(tagname)
86
+ if self.count:
87
+ container.set('count', str(len(obj)))
88
+ for v in obj:
89
+ container.append(v.to_tree())
90
+ return container
91
+
92
+
93
+ def from_tree(self, node):
94
+ return [self.expected_type.from_tree(el) for el in node]
95
+
96
+
97
+ class MultiSequence(Sequence):
98
+ """
99
+ Sequences can contain objects with different tags
100
+ """
101
+
102
+ def __set__(self, instance, seq):
103
+ if not isinstance(seq, (tuple, list)):
104
+ raise ValueError("Value must be a sequence")
105
+ seq = list(seq)
106
+ Descriptor.__set__(self, instance, seq)
107
+
108
+
109
+ def to_tree(self, tagname, obj, namespace=None):
110
+ """
111
+ Convert the sequence represented by the descriptor to an XML element
112
+ """
113
+ for v in obj:
114
+ el = v.to_tree(namespace=namespace)
115
+ yield el
116
+
117
+
118
+ class MultiSequencePart(Alias):
119
+ """
120
+ Allow a multisequence to be built up from parts
121
+
122
+ Excluded from the instance __elements__ or __attrs__ as is effectively an Alias
123
+ """
124
+
125
+ def __init__(self, expected_type, store):
126
+ self.expected_type = expected_type
127
+ self.store = store
128
+
129
+
130
+ def __set__(self, instance, value):
131
+ value = _convert(self.expected_type, value)
132
+ instance.__dict__[self.store].append(value)
133
+
134
+
135
+ def __get__(self, instance, cls):
136
+ return self