@v587d/capital-generation 2.28.0 → 2.30.0
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.
- package/CHANGELOG.md +59 -0
- package/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +16 -0
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/collector-runtime.js +56 -1
- package/lib/data-collector/catalog-taxonomy.d.ts +1 -1
- package/lib/data-collector/catalog-taxonomy.js +33 -0
- package/lib/data-collector/tools.js +7 -7
- package/lib/host-version.d.ts +9 -0
- package/lib/host-version.js +57 -0
- package/lib/python-runtime/errors.d.ts +1 -1
- package/lib/python-runtime/errors.js +2 -0
- package/lib/python-runtime/manager.d.ts +28 -1
- package/lib/python-runtime/manager.js +141 -5
- package/lib/python-runtime/probe.d.ts +24 -0
- package/lib/python-runtime/probe.js +66 -50
- package/lib/runtime-entry.js +8 -0
- package/lib/sources/csindex-http.d.ts +4 -0
- package/lib/sources/csindex-http.js +233 -0
- package/lib/sources/eastmoney-http.js +1504 -1
- package/lib/sources/fuyao-rest.js +168 -8
- package/lib/sources/official-http.d.ts +4 -0
- package/lib/sources/official-http.js +477 -0
- package/lib/sources/python-remote.d.ts +25 -0
- package/lib/sources/python-remote.js +461 -0
- package/lib/sources/sina-http.d.ts +2 -0
- package/lib/sources/sina-http.js +484 -0
- package/lib/sources/tencent-http.js +23 -8
- package/lib/sources/ths-http.d.ts +2 -0
- package/lib/sources/ths-http.js +514 -0
- package/lib/time/tools.js +19 -0
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/sources.d.ts +7 -0
- package/lib/web-retriever/sources.js +46 -21
- package/lib/web-retriever/throttle.d.ts +8 -0
- package/lib/web-retriever/throttle.js +13 -0
- package/lib/web-retriever/tools.js +1 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +6 -3
- package/preset/capital-generation/agent.patch.yml +7 -5
- package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +16 -16
- package/python/scripts/baostock_stock_basic.py +129 -0
- package/python/scripts/baostock_valuation_history.py +141 -0
- package/python/scripts/pbc_social_financing.py +291 -0
- package/python/vendor/baostock/LICENSE +19 -0
- package/python/vendor/baostock/__init__.py +42 -0
- package/python/vendor/baostock/common/__init__.py +0 -0
- package/python/vendor/baostock/common/contants.py +189 -0
- package/python/vendor/baostock/common/context.py +4 -0
- package/python/vendor/baostock/corpreport/__init__.py +0 -0
- package/python/vendor/baostock/corpreport/corp_performance.py +202 -0
- package/python/vendor/baostock/data/__init__.py +0 -0
- package/python/vendor/baostock/data/messageheader.py +17 -0
- package/python/vendor/baostock/data/msg.py +21 -0
- package/python/vendor/baostock/data/resultset.py +200 -0
- package/python/vendor/baostock/demo/__init__.py +0 -0
- package/python/vendor/baostock/demo/demo_A_stock_5mk-data.py +34 -0
- package/python/vendor/baostock/demo/demo_A_stock_k_data.py +36 -0
- package/python/vendor/baostock/demo/demo_AllStock.py +27 -0
- package/python/vendor/baostock/demo/demo_Balance_data.py +22 -0
- package/python/vendor/baostock/demo/demo_CashFlow_data.py +22 -0
- package/python/vendor/baostock/demo/demo_Dividend_data.py +35 -0
- package/python/vendor/baostock/demo/demo_Dupont_data.py +25 -0
- package/python/vendor/baostock/demo/demo_Forecast_report.py +24 -0
- package/python/vendor/baostock/demo/demo_Growth_data.py +22 -0
- package/python/vendor/baostock/demo/demo_Index_k_data.py +39 -0
- package/python/vendor/baostock/demo/demo_Operation_data.py +22 -0
- package/python/vendor/baostock/demo/demo_PerformanceExpress_report.py +25 -0
- package/python/vendor/baostock/demo/demo_Profit_data.py +22 -0
- package/python/vendor/baostock/demo/demo_TradeDates.py +27 -0
- package/python/vendor/baostock/demo/demo_adjust_factor_data.py +23 -0
- package/python/vendor/baostock/demo/demo_assignDayData.py +23 -0
- package/python/vendor/baostock/demo/demo_daily_adjust_factor_data.py +28 -0
- package/python/vendor/baostock/demo/demo_daily_k_4_AStock.py +28 -0
- package/python/vendor/baostock/demo/demo_daily_k_4_ETF.py +28 -0
- package/python/vendor/baostock/demo/demo_depositRate_data.py +26 -0
- package/python/vendor/baostock/demo/demo_hs300_stocks.py +26 -0
- package/python/vendor/baostock/demo/demo_loanRate_data.py +26 -0
- package/python/vendor/baostock/demo/demo_moneySupplyDataMonth_data.py +26 -0
- package/python/vendor/baostock/demo/demo_moneySupplyDataYear_data.py +26 -0
- package/python/vendor/baostock/demo/demo_requiredReserveRatio_data.py +26 -0
- package/python/vendor/baostock/demo/demo_set_API_key.py +37 -0
- package/python/vendor/baostock/demo/demo_stockBasic_data.py +27 -0
- package/python/vendor/baostock/demo/demo_stock_Valuation_indicator_data.py +34 -0
- package/python/vendor/baostock/demo/demo_stock_industry.py +26 -0
- package/python/vendor/baostock/demo/demo_sz50stocks.py +26 -0
- package/python/vendor/baostock/demo/demo_zz500_stock.py +26 -0
- package/python/vendor/baostock/evaluation/__init__.py +0 -0
- package/python/vendor/baostock/evaluation/season_index.py +758 -0
- package/python/vendor/baostock/login/__init__.py +0 -0
- package/python/vendor/baostock/login/loginout.py +230 -0
- package/python/vendor/baostock/macroscopic/__init__.py +0 -0
- package/python/vendor/baostock/macroscopic/economic_data.py +723 -0
- package/python/vendor/baostock/metadata/__init__.py +0 -0
- package/python/vendor/baostock/metadata/stock_metadata.py +207 -0
- package/python/vendor/baostock/security/__init__.py +0 -0
- package/python/vendor/baostock/security/history.py +265 -0
- package/python/vendor/baostock/security/sectorinfo.py +1024 -0
- package/python/vendor/baostock/util/__init__.py +0 -0
- package/python/vendor/baostock/util/socketutil.py +97 -0
- package/python/vendor/baostock/util/stringutil.py +83 -0
- package/python/vendor/et_xmlfile/LICENSE +23 -0
- package/python/vendor/et_xmlfile/LICENSE.python +298 -0
- package/python/vendor/et_xmlfile/__init__.py +8 -0
- package/python/vendor/et_xmlfile/incremental_tree.py +917 -0
- package/python/vendor/et_xmlfile/xmlfile.py +158 -0
- package/python/vendor/openpyxl/LICENSE +23 -0
- package/python/vendor/openpyxl/__init__.py +19 -0
- package/python/vendor/openpyxl/_constants.py +13 -0
- package/python/vendor/openpyxl/cell/__init__.py +4 -0
- package/python/vendor/openpyxl/cell/_writer.py +136 -0
- package/python/vendor/openpyxl/cell/cell.py +332 -0
- package/python/vendor/openpyxl/cell/read_only.py +136 -0
- package/python/vendor/openpyxl/cell/rich_text.py +202 -0
- package/python/vendor/openpyxl/cell/text.py +184 -0
- package/python/vendor/openpyxl/chart/_3d.py +105 -0
- package/python/vendor/openpyxl/chart/__init__.py +19 -0
- package/python/vendor/openpyxl/chart/_chart.py +199 -0
- package/python/vendor/openpyxl/chart/area_chart.py +106 -0
- package/python/vendor/openpyxl/chart/axis.py +401 -0
- package/python/vendor/openpyxl/chart/bar_chart.py +144 -0
- package/python/vendor/openpyxl/chart/bubble_chart.py +67 -0
- package/python/vendor/openpyxl/chart/chartspace.py +195 -0
- package/python/vendor/openpyxl/chart/data_source.py +246 -0
- package/python/vendor/openpyxl/chart/descriptors.py +43 -0
- package/python/vendor/openpyxl/chart/error_bar.py +62 -0
- package/python/vendor/openpyxl/chart/label.py +127 -0
- package/python/vendor/openpyxl/chart/layout.py +74 -0
- package/python/vendor/openpyxl/chart/legend.py +75 -0
- package/python/vendor/openpyxl/chart/line_chart.py +129 -0
- package/python/vendor/openpyxl/chart/marker.py +90 -0
- package/python/vendor/openpyxl/chart/picture.py +35 -0
- package/python/vendor/openpyxl/chart/pie_chart.py +177 -0
- package/python/vendor/openpyxl/chart/pivot.py +65 -0
- package/python/vendor/openpyxl/chart/plotarea.py +162 -0
- package/python/vendor/openpyxl/chart/print_settings.py +57 -0
- package/python/vendor/openpyxl/chart/radar_chart.py +55 -0
- package/python/vendor/openpyxl/chart/reader.py +32 -0
- package/python/vendor/openpyxl/chart/reference.py +124 -0
- package/python/vendor/openpyxl/chart/scatter_chart.py +53 -0
- package/python/vendor/openpyxl/chart/series.py +197 -0
- package/python/vendor/openpyxl/chart/series_factory.py +41 -0
- package/python/vendor/openpyxl/chart/shapes.py +89 -0
- package/python/vendor/openpyxl/chart/stock_chart.py +54 -0
- package/python/vendor/openpyxl/chart/surface_chart.py +119 -0
- package/python/vendor/openpyxl/chart/text.py +78 -0
- package/python/vendor/openpyxl/chart/title.py +76 -0
- package/python/vendor/openpyxl/chart/trendline.py +98 -0
- package/python/vendor/openpyxl/chart/updown_bars.py +31 -0
- package/python/vendor/openpyxl/chartsheet/__init__.py +3 -0
- package/python/vendor/openpyxl/chartsheet/chartsheet.py +107 -0
- package/python/vendor/openpyxl/chartsheet/custom.py +61 -0
- package/python/vendor/openpyxl/chartsheet/properties.py +28 -0
- package/python/vendor/openpyxl/chartsheet/protection.py +41 -0
- package/python/vendor/openpyxl/chartsheet/publish.py +58 -0
- package/python/vendor/openpyxl/chartsheet/relation.py +97 -0
- package/python/vendor/openpyxl/chartsheet/views.py +51 -0
- package/python/vendor/openpyxl/comments/__init__.py +4 -0
- package/python/vendor/openpyxl/comments/author.py +21 -0
- package/python/vendor/openpyxl/comments/comment_sheet.py +211 -0
- package/python/vendor/openpyxl/comments/comments.py +62 -0
- package/python/vendor/openpyxl/comments/shape_writer.py +112 -0
- package/python/vendor/openpyxl/compat/__init__.py +54 -0
- package/python/vendor/openpyxl/compat/abc.py +8 -0
- package/python/vendor/openpyxl/compat/numbers.py +43 -0
- package/python/vendor/openpyxl/compat/product.py +17 -0
- package/python/vendor/openpyxl/compat/singleton.py +40 -0
- package/python/vendor/openpyxl/compat/strings.py +25 -0
- package/python/vendor/openpyxl/descriptors/__init__.py +58 -0
- package/python/vendor/openpyxl/descriptors/base.py +272 -0
- package/python/vendor/openpyxl/descriptors/container.py +41 -0
- package/python/vendor/openpyxl/descriptors/excel.py +112 -0
- package/python/vendor/openpyxl/descriptors/namespace.py +12 -0
- package/python/vendor/openpyxl/descriptors/nested.py +129 -0
- package/python/vendor/openpyxl/descriptors/sequence.py +136 -0
- package/python/vendor/openpyxl/descriptors/serialisable.py +240 -0
- package/python/vendor/openpyxl/descriptors/slots.py +18 -0
- package/python/vendor/openpyxl/drawing/__init__.py +4 -0
- package/python/vendor/openpyxl/drawing/colors.py +435 -0
- package/python/vendor/openpyxl/drawing/connector.py +144 -0
- package/python/vendor/openpyxl/drawing/drawing.py +92 -0
- package/python/vendor/openpyxl/drawing/effect.py +407 -0
- package/python/vendor/openpyxl/drawing/fill.py +425 -0
- package/python/vendor/openpyxl/drawing/geometry.py +584 -0
- package/python/vendor/openpyxl/drawing/graphic.py +177 -0
- package/python/vendor/openpyxl/drawing/image.py +65 -0
- package/python/vendor/openpyxl/drawing/line.py +144 -0
- package/python/vendor/openpyxl/drawing/picture.py +144 -0
- package/python/vendor/openpyxl/drawing/properties.py +174 -0
- package/python/vendor/openpyxl/drawing/relation.py +17 -0
- package/python/vendor/openpyxl/drawing/spreadsheet_drawing.py +382 -0
- package/python/vendor/openpyxl/drawing/text.py +717 -0
- package/python/vendor/openpyxl/drawing/xdr.py +33 -0
- package/python/vendor/openpyxl/formatting/__init__.py +3 -0
- package/python/vendor/openpyxl/formatting/formatting.py +114 -0
- package/python/vendor/openpyxl/formatting/rule.py +291 -0
- package/python/vendor/openpyxl/formula/__init__.py +3 -0
- package/python/vendor/openpyxl/formula/tokenizer.py +446 -0
- package/python/vendor/openpyxl/formula/translate.py +166 -0
- package/python/vendor/openpyxl/packaging/__init__.py +3 -0
- package/python/vendor/openpyxl/packaging/core.py +115 -0
- package/python/vendor/openpyxl/packaging/custom.py +289 -0
- package/python/vendor/openpyxl/packaging/extended.py +137 -0
- package/python/vendor/openpyxl/packaging/interface.py +56 -0
- package/python/vendor/openpyxl/packaging/manifest.py +194 -0
- package/python/vendor/openpyxl/packaging/relationship.py +158 -0
- package/python/vendor/openpyxl/packaging/workbook.py +185 -0
- package/python/vendor/openpyxl/pivot/__init__.py +1 -0
- package/python/vendor/openpyxl/pivot/cache.py +965 -0
- package/python/vendor/openpyxl/pivot/fields.py +326 -0
- package/python/vendor/openpyxl/pivot/record.py +111 -0
- package/python/vendor/openpyxl/pivot/table.py +1261 -0
- package/python/vendor/openpyxl/reader/__init__.py +1 -0
- package/python/vendor/openpyxl/reader/drawings.py +71 -0
- package/python/vendor/openpyxl/reader/excel.py +349 -0
- package/python/vendor/openpyxl/reader/strings.py +44 -0
- package/python/vendor/openpyxl/reader/workbook.py +133 -0
- package/python/vendor/openpyxl/styles/__init__.py +11 -0
- package/python/vendor/openpyxl/styles/alignment.py +62 -0
- package/python/vendor/openpyxl/styles/borders.py +103 -0
- package/python/vendor/openpyxl/styles/builtins.py +1397 -0
- package/python/vendor/openpyxl/styles/cell_style.py +206 -0
- package/python/vendor/openpyxl/styles/colors.py +172 -0
- package/python/vendor/openpyxl/styles/differential.py +95 -0
- package/python/vendor/openpyxl/styles/fills.py +224 -0
- package/python/vendor/openpyxl/styles/fonts.py +113 -0
- package/python/vendor/openpyxl/styles/named_styles.py +282 -0
- package/python/vendor/openpyxl/styles/numbers.py +200 -0
- package/python/vendor/openpyxl/styles/protection.py +17 -0
- package/python/vendor/openpyxl/styles/proxy.py +62 -0
- package/python/vendor/openpyxl/styles/styleable.py +151 -0
- package/python/vendor/openpyxl/styles/stylesheet.py +274 -0
- package/python/vendor/openpyxl/styles/table.py +94 -0
- package/python/vendor/openpyxl/utils/__init__.py +17 -0
- package/python/vendor/openpyxl/utils/bound_dictionary.py +26 -0
- package/python/vendor/openpyxl/utils/cell.py +240 -0
- package/python/vendor/openpyxl/utils/dataframe.py +87 -0
- package/python/vendor/openpyxl/utils/datetime.py +140 -0
- package/python/vendor/openpyxl/utils/escape.py +43 -0
- package/python/vendor/openpyxl/utils/exceptions.py +34 -0
- package/python/vendor/openpyxl/utils/formulas.py +24 -0
- package/python/vendor/openpyxl/utils/indexed_list.py +49 -0
- package/python/vendor/openpyxl/utils/inference.py +60 -0
- package/python/vendor/openpyxl/utils/protection.py +22 -0
- package/python/vendor/openpyxl/utils/units.py +108 -0
- package/python/vendor/openpyxl/workbook/__init__.py +4 -0
- package/python/vendor/openpyxl/workbook/_writer.py +197 -0
- package/python/vendor/openpyxl/workbook/child.py +166 -0
- package/python/vendor/openpyxl/workbook/defined_name.py +189 -0
- package/python/vendor/openpyxl/workbook/external_link/__init__.py +3 -0
- package/python/vendor/openpyxl/workbook/external_link/external.py +190 -0
- package/python/vendor/openpyxl/workbook/external_reference.py +18 -0
- package/python/vendor/openpyxl/workbook/function_group.py +36 -0
- package/python/vendor/openpyxl/workbook/properties.py +151 -0
- package/python/vendor/openpyxl/workbook/protection.py +163 -0
- package/python/vendor/openpyxl/workbook/smart_tags.py +56 -0
- package/python/vendor/openpyxl/workbook/views.py +155 -0
- package/python/vendor/openpyxl/workbook/web.py +98 -0
- package/python/vendor/openpyxl/workbook/workbook.py +438 -0
- package/python/vendor/openpyxl/worksheet/__init__.py +1 -0
- package/python/vendor/openpyxl/worksheet/_read_only.py +190 -0
- package/python/vendor/openpyxl/worksheet/_reader.py +472 -0
- package/python/vendor/openpyxl/worksheet/_write_only.py +160 -0
- package/python/vendor/openpyxl/worksheet/_writer.py +390 -0
- package/python/vendor/openpyxl/worksheet/cell_range.py +512 -0
- package/python/vendor/openpyxl/worksheet/cell_watch.py +34 -0
- package/python/vendor/openpyxl/worksheet/controls.py +107 -0
- package/python/vendor/openpyxl/worksheet/copier.py +70 -0
- package/python/vendor/openpyxl/worksheet/custom.py +35 -0
- package/python/vendor/openpyxl/worksheet/datavalidation.py +202 -0
- package/python/vendor/openpyxl/worksheet/dimensions.py +306 -0
- package/python/vendor/openpyxl/worksheet/drawing.py +14 -0
- package/python/vendor/openpyxl/worksheet/errors.py +93 -0
- package/python/vendor/openpyxl/worksheet/filters.py +486 -0
- package/python/vendor/openpyxl/worksheet/formula.py +51 -0
- package/python/vendor/openpyxl/worksheet/header_footer.py +270 -0
- package/python/vendor/openpyxl/worksheet/hyperlink.py +46 -0
- package/python/vendor/openpyxl/worksheet/merge.py +141 -0
- package/python/vendor/openpyxl/worksheet/ole.py +133 -0
- package/python/vendor/openpyxl/worksheet/page.py +174 -0
- package/python/vendor/openpyxl/worksheet/pagebreak.py +94 -0
- package/python/vendor/openpyxl/worksheet/picture.py +8 -0
- package/python/vendor/openpyxl/worksheet/print_settings.py +184 -0
- package/python/vendor/openpyxl/worksheet/properties.py +97 -0
- package/python/vendor/openpyxl/worksheet/protection.py +120 -0
- package/python/vendor/openpyxl/worksheet/related.py +17 -0
- package/python/vendor/openpyxl/worksheet/scenario.py +105 -0
- package/python/vendor/openpyxl/worksheet/smart_tag.py +78 -0
- package/python/vendor/openpyxl/worksheet/table.py +385 -0
- package/python/vendor/openpyxl/worksheet/views.py +155 -0
- package/python/vendor/openpyxl/worksheet/worksheet.py +907 -0
- package/python/vendor/openpyxl/writer/__init__.py +1 -0
- package/python/vendor/openpyxl/writer/excel.py +295 -0
- package/python/vendor/openpyxl/writer/theme.py +291 -0
- package/python/vendor/openpyxl/xml/__init__.py +42 -0
- package/python/vendor/openpyxl/xml/constants.py +129 -0
- package/python/vendor/openpyxl/xml/functions.py +87 -0
- package/watchlist/package.json +1 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
from copy import copy
|
|
4
|
+
|
|
5
|
+
from .numbers import (
|
|
6
|
+
BUILTIN_FORMATS,
|
|
7
|
+
BUILTIN_FORMATS_MAX_SIZE,
|
|
8
|
+
BUILTIN_FORMATS_REVERSE,
|
|
9
|
+
)
|
|
10
|
+
from .proxy import StyleProxy
|
|
11
|
+
from .cell_style import StyleArray
|
|
12
|
+
from .named_styles import NamedStyle
|
|
13
|
+
from .builtins import styles
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class StyleDescriptor:
|
|
17
|
+
|
|
18
|
+
def __init__(self, collection, key):
|
|
19
|
+
self.collection = collection
|
|
20
|
+
self.key = key
|
|
21
|
+
|
|
22
|
+
def __set__(self, instance, value):
|
|
23
|
+
coll = getattr(instance.parent.parent, self.collection)
|
|
24
|
+
if not getattr(instance, "_style"):
|
|
25
|
+
instance._style = StyleArray()
|
|
26
|
+
setattr(instance._style, self.key, coll.add(value))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def __get__(self, instance, cls):
|
|
30
|
+
coll = getattr(instance.parent.parent, self.collection)
|
|
31
|
+
if not getattr(instance, "_style"):
|
|
32
|
+
instance._style = StyleArray()
|
|
33
|
+
idx = getattr(instance._style, self.key)
|
|
34
|
+
return StyleProxy(coll[idx])
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class NumberFormatDescriptor:
|
|
38
|
+
|
|
39
|
+
key = "numFmtId"
|
|
40
|
+
collection = '_number_formats'
|
|
41
|
+
|
|
42
|
+
def __set__(self, instance, value):
|
|
43
|
+
coll = getattr(instance.parent.parent, self.collection)
|
|
44
|
+
if value in BUILTIN_FORMATS_REVERSE:
|
|
45
|
+
idx = BUILTIN_FORMATS_REVERSE[value]
|
|
46
|
+
else:
|
|
47
|
+
idx = coll.add(value) + BUILTIN_FORMATS_MAX_SIZE
|
|
48
|
+
|
|
49
|
+
if not getattr(instance, "_style"):
|
|
50
|
+
instance._style = StyleArray()
|
|
51
|
+
setattr(instance._style, self.key, idx)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def __get__(self, instance, cls):
|
|
55
|
+
if not getattr(instance, "_style"):
|
|
56
|
+
instance._style = StyleArray()
|
|
57
|
+
idx = getattr(instance._style, self.key)
|
|
58
|
+
if idx < BUILTIN_FORMATS_MAX_SIZE:
|
|
59
|
+
return BUILTIN_FORMATS.get(idx, "General")
|
|
60
|
+
coll = getattr(instance.parent.parent, self.collection)
|
|
61
|
+
return coll[idx - BUILTIN_FORMATS_MAX_SIZE]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class NamedStyleDescriptor:
|
|
65
|
+
|
|
66
|
+
key = "xfId"
|
|
67
|
+
collection = "_named_styles"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def __set__(self, instance, value):
|
|
71
|
+
if not getattr(instance, "_style"):
|
|
72
|
+
instance._style = StyleArray()
|
|
73
|
+
coll = getattr(instance.parent.parent, self.collection)
|
|
74
|
+
if isinstance(value, NamedStyle):
|
|
75
|
+
style = value
|
|
76
|
+
if style not in coll:
|
|
77
|
+
instance.parent.parent.add_named_style(style)
|
|
78
|
+
elif value not in coll.names:
|
|
79
|
+
if value in styles: # is it builtin?
|
|
80
|
+
style = styles[value]
|
|
81
|
+
if style not in coll:
|
|
82
|
+
instance.parent.parent.add_named_style(style)
|
|
83
|
+
else:
|
|
84
|
+
raise ValueError("{0} is not a known style".format(value))
|
|
85
|
+
else:
|
|
86
|
+
style = coll[value]
|
|
87
|
+
instance._style = copy(style.as_tuple())
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def __get__(self, instance, cls):
|
|
91
|
+
if not getattr(instance, "_style"):
|
|
92
|
+
instance._style = StyleArray()
|
|
93
|
+
idx = getattr(instance._style, self.key)
|
|
94
|
+
coll = getattr(instance.parent.parent, self.collection)
|
|
95
|
+
return coll.names[idx]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class StyleArrayDescriptor:
|
|
99
|
+
|
|
100
|
+
def __init__(self, key):
|
|
101
|
+
self.key = key
|
|
102
|
+
|
|
103
|
+
def __set__(self, instance, value):
|
|
104
|
+
if instance._style is None:
|
|
105
|
+
instance._style = StyleArray()
|
|
106
|
+
setattr(instance._style, self.key, value)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def __get__(self, instance, cls):
|
|
110
|
+
if instance._style is None:
|
|
111
|
+
return False
|
|
112
|
+
return bool(getattr(instance._style, self.key))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class StyleableObject:
|
|
116
|
+
"""
|
|
117
|
+
Base class for styleble objects implementing proxy and lookup functions
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
font = StyleDescriptor('_fonts', "fontId")
|
|
121
|
+
fill = StyleDescriptor('_fills', "fillId")
|
|
122
|
+
border = StyleDescriptor('_borders', "borderId")
|
|
123
|
+
number_format = NumberFormatDescriptor()
|
|
124
|
+
protection = StyleDescriptor('_protections', "protectionId")
|
|
125
|
+
alignment = StyleDescriptor('_alignments', "alignmentId")
|
|
126
|
+
style = NamedStyleDescriptor()
|
|
127
|
+
quotePrefix = StyleArrayDescriptor('quotePrefix')
|
|
128
|
+
pivotButton = StyleArrayDescriptor('pivotButton')
|
|
129
|
+
|
|
130
|
+
__slots__ = ('parent', '_style')
|
|
131
|
+
|
|
132
|
+
def __init__(self, sheet, style_array=None):
|
|
133
|
+
self.parent = sheet
|
|
134
|
+
if style_array is not None:
|
|
135
|
+
style_array = StyleArray(style_array)
|
|
136
|
+
self._style = style_array
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def style_id(self):
|
|
141
|
+
if self._style is None:
|
|
142
|
+
self._style = StyleArray()
|
|
143
|
+
return self.parent.parent._cell_styles.add(self._style)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@property
|
|
147
|
+
def has_style(self):
|
|
148
|
+
if self._style is None:
|
|
149
|
+
return False
|
|
150
|
+
return any(self._style)
|
|
151
|
+
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
from warnings import warn
|
|
4
|
+
|
|
5
|
+
from openpyxl.descriptors.serialisable import Serialisable
|
|
6
|
+
from openpyxl.descriptors import (
|
|
7
|
+
Typed,
|
|
8
|
+
)
|
|
9
|
+
from openpyxl.descriptors.sequence import NestedSequence
|
|
10
|
+
from openpyxl.descriptors.excel import ExtensionList
|
|
11
|
+
from openpyxl.utils.indexed_list import IndexedList
|
|
12
|
+
from openpyxl.xml.constants import ARC_STYLE, SHEET_MAIN_NS
|
|
13
|
+
from openpyxl.xml.functions import fromstring
|
|
14
|
+
|
|
15
|
+
from .builtins import styles
|
|
16
|
+
from .colors import ColorList
|
|
17
|
+
from .differential import DifferentialStyle
|
|
18
|
+
from .table import TableStyleList
|
|
19
|
+
from .borders import Border
|
|
20
|
+
from .fills import Fill
|
|
21
|
+
from .fonts import Font
|
|
22
|
+
from .numbers import (
|
|
23
|
+
NumberFormatList,
|
|
24
|
+
BUILTIN_FORMATS,
|
|
25
|
+
BUILTIN_FORMATS_MAX_SIZE,
|
|
26
|
+
BUILTIN_FORMATS_REVERSE,
|
|
27
|
+
is_date_format,
|
|
28
|
+
is_timedelta_format,
|
|
29
|
+
builtin_format_code
|
|
30
|
+
)
|
|
31
|
+
from .named_styles import (
|
|
32
|
+
_NamedCellStyleList,
|
|
33
|
+
NamedStyleList,
|
|
34
|
+
NamedStyle,
|
|
35
|
+
)
|
|
36
|
+
from .cell_style import CellStyle, CellStyleList
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Stylesheet(Serialisable):
|
|
40
|
+
|
|
41
|
+
tagname = "styleSheet"
|
|
42
|
+
|
|
43
|
+
numFmts = Typed(expected_type=NumberFormatList)
|
|
44
|
+
fonts = NestedSequence(expected_type=Font, count=True)
|
|
45
|
+
fills = NestedSequence(expected_type=Fill, count=True)
|
|
46
|
+
borders = NestedSequence(expected_type=Border, count=True)
|
|
47
|
+
cellStyleXfs = Typed(expected_type=CellStyleList)
|
|
48
|
+
cellXfs = Typed(expected_type=CellStyleList)
|
|
49
|
+
cellStyles = Typed(expected_type=_NamedCellStyleList)
|
|
50
|
+
dxfs = NestedSequence(expected_type=DifferentialStyle, count=True)
|
|
51
|
+
tableStyles = Typed(expected_type=TableStyleList, allow_none=True)
|
|
52
|
+
colors = Typed(expected_type=ColorList, allow_none=True)
|
|
53
|
+
extLst = Typed(expected_type=ExtensionList, allow_none=True)
|
|
54
|
+
|
|
55
|
+
__elements__ = ('numFmts', 'fonts', 'fills', 'borders', 'cellStyleXfs',
|
|
56
|
+
'cellXfs', 'cellStyles', 'dxfs', 'tableStyles', 'colors')
|
|
57
|
+
|
|
58
|
+
def __init__(self,
|
|
59
|
+
numFmts=None,
|
|
60
|
+
fonts=(),
|
|
61
|
+
fills=(),
|
|
62
|
+
borders=(),
|
|
63
|
+
cellStyleXfs=None,
|
|
64
|
+
cellXfs=None,
|
|
65
|
+
cellStyles=None,
|
|
66
|
+
dxfs=(),
|
|
67
|
+
tableStyles=None,
|
|
68
|
+
colors=None,
|
|
69
|
+
extLst=None,
|
|
70
|
+
):
|
|
71
|
+
if numFmts is None:
|
|
72
|
+
numFmts = NumberFormatList()
|
|
73
|
+
self.numFmts = numFmts
|
|
74
|
+
self.number_formats = IndexedList()
|
|
75
|
+
self.fonts = fonts
|
|
76
|
+
self.fills = fills
|
|
77
|
+
self.borders = borders
|
|
78
|
+
if cellStyleXfs is None:
|
|
79
|
+
cellStyleXfs = CellStyleList()
|
|
80
|
+
self.cellStyleXfs = cellStyleXfs
|
|
81
|
+
if cellXfs is None:
|
|
82
|
+
cellXfs = CellStyleList()
|
|
83
|
+
self.cellXfs = cellXfs
|
|
84
|
+
if cellStyles is None:
|
|
85
|
+
cellStyles = _NamedCellStyleList()
|
|
86
|
+
self.cellStyles = cellStyles
|
|
87
|
+
|
|
88
|
+
self.dxfs = dxfs
|
|
89
|
+
self.tableStyles = tableStyles
|
|
90
|
+
self.colors = colors
|
|
91
|
+
|
|
92
|
+
self.cell_styles = self.cellXfs._to_array()
|
|
93
|
+
self.alignments = self.cellXfs.alignments
|
|
94
|
+
self.protections = self.cellXfs.prots
|
|
95
|
+
self._normalise_numbers()
|
|
96
|
+
self.named_styles = self._merge_named_styles()
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@classmethod
|
|
100
|
+
def from_tree(cls, node):
|
|
101
|
+
# strip all attribs
|
|
102
|
+
attrs = dict(node.attrib)
|
|
103
|
+
for k in attrs:
|
|
104
|
+
del node.attrib[k]
|
|
105
|
+
return super().from_tree(node)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _merge_named_styles(self):
|
|
109
|
+
"""
|
|
110
|
+
Merge named style names "cellStyles" with their associated styles
|
|
111
|
+
"cellStyleXfs"
|
|
112
|
+
"""
|
|
113
|
+
style_refs = self.cellStyles.remove_duplicates()
|
|
114
|
+
from_ref = [self._expand_named_style(style_ref) for style_ref in style_refs]
|
|
115
|
+
|
|
116
|
+
return NamedStyleList(from_ref)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _expand_named_style(self, style_ref):
|
|
120
|
+
"""
|
|
121
|
+
Expand a named style reference element to a
|
|
122
|
+
named style object by binding the relevant
|
|
123
|
+
objects from the stylesheet
|
|
124
|
+
"""
|
|
125
|
+
xf = self.cellStyleXfs[style_ref.xfId]
|
|
126
|
+
named_style = NamedStyle(
|
|
127
|
+
name=style_ref.name,
|
|
128
|
+
hidden=style_ref.hidden,
|
|
129
|
+
builtinId=style_ref.builtinId,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
named_style.font = self.fonts[xf.fontId]
|
|
133
|
+
named_style.fill = self.fills[xf.fillId]
|
|
134
|
+
named_style.border = self.borders[xf.borderId]
|
|
135
|
+
if xf.numFmtId < BUILTIN_FORMATS_MAX_SIZE:
|
|
136
|
+
formats = BUILTIN_FORMATS
|
|
137
|
+
else:
|
|
138
|
+
formats = self.custom_formats
|
|
139
|
+
|
|
140
|
+
if xf.numFmtId in formats:
|
|
141
|
+
named_style.number_format = formats[xf.numFmtId]
|
|
142
|
+
if xf.alignment:
|
|
143
|
+
named_style.alignment = xf.alignment
|
|
144
|
+
if xf.protection:
|
|
145
|
+
named_style.protection = xf.protection
|
|
146
|
+
|
|
147
|
+
return named_style
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _split_named_styles(self, wb):
|
|
151
|
+
"""
|
|
152
|
+
Convert NamedStyle into separate CellStyle and Xf objects
|
|
153
|
+
|
|
154
|
+
"""
|
|
155
|
+
for style in wb._named_styles:
|
|
156
|
+
self.cellStyles.cellStyle.append(style.as_name())
|
|
157
|
+
self.cellStyleXfs.xf.append(style.as_xf())
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def custom_formats(self):
|
|
162
|
+
return dict([(n.numFmtId, n.formatCode) for n in self.numFmts.numFmt])
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _normalise_numbers(self):
|
|
166
|
+
"""
|
|
167
|
+
Rebase custom numFmtIds with a floor of 164 when reading stylesheet
|
|
168
|
+
And index datetime formats
|
|
169
|
+
"""
|
|
170
|
+
date_formats = set()
|
|
171
|
+
timedelta_formats = set()
|
|
172
|
+
custom = self.custom_formats
|
|
173
|
+
formats = self.number_formats
|
|
174
|
+
for idx, style in enumerate(self.cell_styles):
|
|
175
|
+
if style.numFmtId in custom:
|
|
176
|
+
fmt = custom[style.numFmtId]
|
|
177
|
+
if fmt in BUILTIN_FORMATS_REVERSE: # remove builtins
|
|
178
|
+
style.numFmtId = BUILTIN_FORMATS_REVERSE[fmt]
|
|
179
|
+
else:
|
|
180
|
+
style.numFmtId = formats.add(fmt) + BUILTIN_FORMATS_MAX_SIZE
|
|
181
|
+
else:
|
|
182
|
+
fmt = builtin_format_code(style.numFmtId)
|
|
183
|
+
if is_date_format(fmt):
|
|
184
|
+
# Create an index of which styles refer to datetimes
|
|
185
|
+
date_formats.add(idx)
|
|
186
|
+
if is_timedelta_format(fmt):
|
|
187
|
+
# Create an index of which styles refer to timedeltas
|
|
188
|
+
timedelta_formats.add(idx)
|
|
189
|
+
self.date_formats = date_formats
|
|
190
|
+
self.timedelta_formats = timedelta_formats
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def to_tree(self, tagname=None, idx=None, namespace=None):
|
|
194
|
+
tree = super().to_tree(tagname, idx, namespace)
|
|
195
|
+
tree.set("xmlns", SHEET_MAIN_NS)
|
|
196
|
+
return tree
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def apply_stylesheet(archive, wb):
|
|
200
|
+
"""
|
|
201
|
+
Add styles to workbook if present
|
|
202
|
+
"""
|
|
203
|
+
try:
|
|
204
|
+
src = archive.read(ARC_STYLE)
|
|
205
|
+
except KeyError:
|
|
206
|
+
return wb
|
|
207
|
+
|
|
208
|
+
node = fromstring(src)
|
|
209
|
+
stylesheet = Stylesheet.from_tree(node)
|
|
210
|
+
|
|
211
|
+
if stylesheet.cell_styles:
|
|
212
|
+
|
|
213
|
+
wb._borders = IndexedList(stylesheet.borders)
|
|
214
|
+
wb._fonts = IndexedList(stylesheet.fonts)
|
|
215
|
+
wb._fills = IndexedList(stylesheet.fills)
|
|
216
|
+
wb._differential_styles.styles = stylesheet.dxfs
|
|
217
|
+
wb._number_formats = stylesheet.number_formats
|
|
218
|
+
wb._protections = stylesheet.protections
|
|
219
|
+
wb._alignments = stylesheet.alignments
|
|
220
|
+
wb._table_styles = stylesheet.tableStyles
|
|
221
|
+
|
|
222
|
+
# need to overwrite openpyxl defaults in case workbook has different ones
|
|
223
|
+
wb._cell_styles = stylesheet.cell_styles
|
|
224
|
+
wb._named_styles = stylesheet.named_styles
|
|
225
|
+
wb._date_formats = stylesheet.date_formats
|
|
226
|
+
wb._timedelta_formats = stylesheet.timedelta_formats
|
|
227
|
+
|
|
228
|
+
for ns in wb._named_styles:
|
|
229
|
+
ns.bind(wb)
|
|
230
|
+
|
|
231
|
+
else:
|
|
232
|
+
warn("Workbook contains no stylesheet, using openpyxl's defaults")
|
|
233
|
+
|
|
234
|
+
if not wb._named_styles:
|
|
235
|
+
normal = styles['Normal']
|
|
236
|
+
wb.add_named_style(normal)
|
|
237
|
+
warn("Workbook contains no default style, apply openpyxl's default")
|
|
238
|
+
|
|
239
|
+
if stylesheet.colors is not None:
|
|
240
|
+
wb._colors = stylesheet.colors.index
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def write_stylesheet(wb):
|
|
244
|
+
stylesheet = Stylesheet()
|
|
245
|
+
stylesheet.fonts = wb._fonts
|
|
246
|
+
stylesheet.fills = wb._fills
|
|
247
|
+
stylesheet.borders = wb._borders
|
|
248
|
+
stylesheet.dxfs = wb._differential_styles.styles
|
|
249
|
+
stylesheet.colors = ColorList(indexedColors=wb._colors)
|
|
250
|
+
|
|
251
|
+
from .numbers import NumberFormat
|
|
252
|
+
fmts = []
|
|
253
|
+
for idx, code in enumerate(wb._number_formats, BUILTIN_FORMATS_MAX_SIZE):
|
|
254
|
+
fmt = NumberFormat(idx, code)
|
|
255
|
+
fmts.append(fmt)
|
|
256
|
+
|
|
257
|
+
stylesheet.numFmts.numFmt = fmts
|
|
258
|
+
|
|
259
|
+
xfs = []
|
|
260
|
+
for style in wb._cell_styles:
|
|
261
|
+
xf = CellStyle.from_array(style)
|
|
262
|
+
|
|
263
|
+
if style.alignmentId:
|
|
264
|
+
xf.alignment = wb._alignments[style.alignmentId]
|
|
265
|
+
|
|
266
|
+
if style.protectionId:
|
|
267
|
+
xf.protection = wb._protections[style.protectionId]
|
|
268
|
+
xfs.append(xf)
|
|
269
|
+
stylesheet.cellXfs = CellStyleList(xf=xfs)
|
|
270
|
+
|
|
271
|
+
stylesheet._split_named_styles(wb)
|
|
272
|
+
stylesheet.tableStyles = wb._table_styles
|
|
273
|
+
|
|
274
|
+
return stylesheet.to_tree()
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
from openpyxl.descriptors.serialisable import Serialisable
|
|
4
|
+
from openpyxl.descriptors import (
|
|
5
|
+
Typed,
|
|
6
|
+
Float,
|
|
7
|
+
Bool,
|
|
8
|
+
Set,
|
|
9
|
+
Integer,
|
|
10
|
+
NoneSet,
|
|
11
|
+
String,
|
|
12
|
+
Sequence
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
from .colors import Color
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TableStyleElement(Serialisable):
|
|
19
|
+
|
|
20
|
+
tagname = "tableStyleElement"
|
|
21
|
+
|
|
22
|
+
type = Set(values=(['wholeTable', 'headerRow', 'totalRow', 'firstColumn',
|
|
23
|
+
'lastColumn', 'firstRowStripe', 'secondRowStripe', 'firstColumnStripe',
|
|
24
|
+
'secondColumnStripe', 'firstHeaderCell', 'lastHeaderCell',
|
|
25
|
+
'firstTotalCell', 'lastTotalCell', 'firstSubtotalColumn',
|
|
26
|
+
'secondSubtotalColumn', 'thirdSubtotalColumn', 'firstSubtotalRow',
|
|
27
|
+
'secondSubtotalRow', 'thirdSubtotalRow', 'blankRow',
|
|
28
|
+
'firstColumnSubheading', 'secondColumnSubheading',
|
|
29
|
+
'thirdColumnSubheading', 'firstRowSubheading', 'secondRowSubheading',
|
|
30
|
+
'thirdRowSubheading', 'pageFieldLabels', 'pageFieldValues']))
|
|
31
|
+
size = Integer(allow_none=True)
|
|
32
|
+
dxfId = Integer(allow_none=True)
|
|
33
|
+
|
|
34
|
+
def __init__(self,
|
|
35
|
+
type=None,
|
|
36
|
+
size=None,
|
|
37
|
+
dxfId=None,
|
|
38
|
+
):
|
|
39
|
+
self.type = type
|
|
40
|
+
self.size = size
|
|
41
|
+
self.dxfId = dxfId
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class TableStyle(Serialisable):
|
|
45
|
+
|
|
46
|
+
tagname = "tableStyle"
|
|
47
|
+
|
|
48
|
+
name = String()
|
|
49
|
+
pivot = Bool(allow_none=True)
|
|
50
|
+
table = Bool(allow_none=True)
|
|
51
|
+
count = Integer(allow_none=True)
|
|
52
|
+
tableStyleElement = Sequence(expected_type=TableStyleElement, allow_none=True)
|
|
53
|
+
|
|
54
|
+
__elements__ = ('tableStyleElement',)
|
|
55
|
+
|
|
56
|
+
def __init__(self,
|
|
57
|
+
name=None,
|
|
58
|
+
pivot=None,
|
|
59
|
+
table=None,
|
|
60
|
+
count=None,
|
|
61
|
+
tableStyleElement=(),
|
|
62
|
+
):
|
|
63
|
+
self.name = name
|
|
64
|
+
self.pivot = pivot
|
|
65
|
+
self.table = table
|
|
66
|
+
self.count = count
|
|
67
|
+
self.tableStyleElement = tableStyleElement
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class TableStyleList(Serialisable):
|
|
71
|
+
|
|
72
|
+
tagname = "tableStyles"
|
|
73
|
+
|
|
74
|
+
defaultTableStyle = String(allow_none=True)
|
|
75
|
+
defaultPivotStyle = String(allow_none=True)
|
|
76
|
+
tableStyle = Sequence(expected_type=TableStyle, allow_none=True)
|
|
77
|
+
|
|
78
|
+
__elements__ = ('tableStyle',)
|
|
79
|
+
__attrs__ = ("count", "defaultTableStyle", "defaultPivotStyle")
|
|
80
|
+
|
|
81
|
+
def __init__(self,
|
|
82
|
+
count=None,
|
|
83
|
+
defaultTableStyle="TableStyleMedium9",
|
|
84
|
+
defaultPivotStyle="PivotStyleLight16",
|
|
85
|
+
tableStyle=(),
|
|
86
|
+
):
|
|
87
|
+
self.defaultTableStyle = defaultTableStyle
|
|
88
|
+
self.defaultPivotStyle = defaultPivotStyle
|
|
89
|
+
self.tableStyle = tableStyle
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def count(self):
|
|
94
|
+
return len(self.tableStyle)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from .cell import (
|
|
5
|
+
absolute_coordinate,
|
|
6
|
+
cols_from_range,
|
|
7
|
+
column_index_from_string,
|
|
8
|
+
coordinate_to_tuple,
|
|
9
|
+
get_column_letter,
|
|
10
|
+
get_column_interval,
|
|
11
|
+
quote_sheetname,
|
|
12
|
+
range_boundaries,
|
|
13
|
+
range_to_tuple,
|
|
14
|
+
rows_from_range,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from .formulas import FORMULAE
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
from collections import defaultdict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BoundDictionary(defaultdict):
|
|
7
|
+
"""
|
|
8
|
+
A default dictionary where elements are tightly coupled.
|
|
9
|
+
|
|
10
|
+
The factory method is responsible for binding the parent object to the child.
|
|
11
|
+
|
|
12
|
+
If a reference attribute is assigned then child objects will have the key assigned to this.
|
|
13
|
+
|
|
14
|
+
Otherwise it's just a defaultdict.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, reference=None, *args, **kw):
|
|
18
|
+
self.reference = reference
|
|
19
|
+
super().__init__(*args, **kw)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def __getitem__(self, key):
|
|
23
|
+
value = super().__getitem__(key)
|
|
24
|
+
if self.reference is not None:
|
|
25
|
+
setattr(value, self.reference, key)
|
|
26
|
+
return value
|