@v587d/capital-generation 2.29.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 +38 -0
- package/README.md +3 -3
- 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/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/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 +1 -1
- 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,194 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
File manifest
|
|
5
|
+
"""
|
|
6
|
+
from mimetypes import MimeTypes
|
|
7
|
+
import os.path
|
|
8
|
+
|
|
9
|
+
from openpyxl.descriptors.serialisable import Serialisable
|
|
10
|
+
from openpyxl.descriptors import String, Sequence
|
|
11
|
+
from openpyxl.xml.functions import fromstring
|
|
12
|
+
from openpyxl.xml.constants import (
|
|
13
|
+
ARC_CONTENT_TYPES,
|
|
14
|
+
ARC_THEME,
|
|
15
|
+
ARC_STYLE,
|
|
16
|
+
THEME_TYPE,
|
|
17
|
+
STYLES_TYPE,
|
|
18
|
+
CONTYPES_NS,
|
|
19
|
+
ACTIVEX,
|
|
20
|
+
CTRL,
|
|
21
|
+
VBA,
|
|
22
|
+
)
|
|
23
|
+
from openpyxl.xml.functions import tostring
|
|
24
|
+
|
|
25
|
+
# initialise mime-types
|
|
26
|
+
mimetypes = MimeTypes()
|
|
27
|
+
mimetypes.add_type('application/xml', ".xml")
|
|
28
|
+
mimetypes.add_type('application/vnd.openxmlformats-package.relationships+xml', ".rels")
|
|
29
|
+
mimetypes.add_type("application/vnd.ms-office.vbaProject", ".bin")
|
|
30
|
+
mimetypes.add_type("application/vnd.openxmlformats-officedocument.vmlDrawing", ".vml")
|
|
31
|
+
mimetypes.add_type("image/x-emf", ".emf")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class FileExtension(Serialisable):
|
|
35
|
+
|
|
36
|
+
tagname = "Default"
|
|
37
|
+
|
|
38
|
+
Extension = String()
|
|
39
|
+
ContentType = String()
|
|
40
|
+
|
|
41
|
+
def __init__(self, Extension, ContentType):
|
|
42
|
+
self.Extension = Extension
|
|
43
|
+
self.ContentType = ContentType
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class Override(Serialisable):
|
|
47
|
+
|
|
48
|
+
tagname = "Override"
|
|
49
|
+
|
|
50
|
+
PartName = String()
|
|
51
|
+
ContentType = String()
|
|
52
|
+
|
|
53
|
+
def __init__(self, PartName, ContentType):
|
|
54
|
+
self.PartName = PartName
|
|
55
|
+
self.ContentType = ContentType
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
DEFAULT_TYPES = [
|
|
59
|
+
FileExtension("rels", "application/vnd.openxmlformats-package.relationships+xml"),
|
|
60
|
+
FileExtension("xml", "application/xml"),
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
DEFAULT_OVERRIDE = [
|
|
64
|
+
Override("/" + ARC_STYLE, STYLES_TYPE), # Styles
|
|
65
|
+
Override("/" + ARC_THEME, THEME_TYPE), # Theme
|
|
66
|
+
Override("/docProps/core.xml", "application/vnd.openxmlformats-package.core-properties+xml"),
|
|
67
|
+
Override("/docProps/app.xml", "application/vnd.openxmlformats-officedocument.extended-properties+xml")
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Manifest(Serialisable):
|
|
72
|
+
|
|
73
|
+
tagname = "Types"
|
|
74
|
+
|
|
75
|
+
Default = Sequence(expected_type=FileExtension, unique=True)
|
|
76
|
+
Override = Sequence(expected_type=Override, unique=True)
|
|
77
|
+
path = "[Content_Types].xml"
|
|
78
|
+
|
|
79
|
+
__elements__ = ("Default", "Override")
|
|
80
|
+
|
|
81
|
+
def __init__(self,
|
|
82
|
+
Default=(),
|
|
83
|
+
Override=(),
|
|
84
|
+
):
|
|
85
|
+
if not Default:
|
|
86
|
+
Default = DEFAULT_TYPES
|
|
87
|
+
self.Default = Default
|
|
88
|
+
if not Override:
|
|
89
|
+
Override = DEFAULT_OVERRIDE
|
|
90
|
+
self.Override = Override
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def filenames(self):
|
|
95
|
+
return [part.PartName for part in self.Override]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def extensions(self):
|
|
100
|
+
"""
|
|
101
|
+
Map content types to file extensions
|
|
102
|
+
Skip parts without extensions
|
|
103
|
+
"""
|
|
104
|
+
exts = {os.path.splitext(part.PartName)[-1] for part in self.Override}
|
|
105
|
+
return [(ext[1:], mimetypes.types_map[True][ext]) for ext in sorted(exts) if ext]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def to_tree(self):
|
|
109
|
+
"""
|
|
110
|
+
Custom serialisation method to allow setting a default namespace
|
|
111
|
+
"""
|
|
112
|
+
defaults = [t.Extension for t in self.Default]
|
|
113
|
+
for ext, mime in self.extensions:
|
|
114
|
+
if ext not in defaults:
|
|
115
|
+
mime = FileExtension(ext, mime)
|
|
116
|
+
self.Default.append(mime)
|
|
117
|
+
tree = super().to_tree()
|
|
118
|
+
tree.set("xmlns", CONTYPES_NS)
|
|
119
|
+
return tree
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def __contains__(self, content_type):
|
|
123
|
+
"""
|
|
124
|
+
Check whether a particular content type is contained
|
|
125
|
+
"""
|
|
126
|
+
for t in self.Override:
|
|
127
|
+
if t.ContentType == content_type:
|
|
128
|
+
return True
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def find(self, content_type):
|
|
132
|
+
"""
|
|
133
|
+
Find specific content-type
|
|
134
|
+
"""
|
|
135
|
+
try:
|
|
136
|
+
return next(self.findall(content_type))
|
|
137
|
+
except StopIteration:
|
|
138
|
+
return
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def findall(self, content_type):
|
|
142
|
+
"""
|
|
143
|
+
Find all elements of a specific content-type
|
|
144
|
+
"""
|
|
145
|
+
for t in self.Override:
|
|
146
|
+
if t.ContentType == content_type:
|
|
147
|
+
yield t
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def append(self, obj):
|
|
151
|
+
"""
|
|
152
|
+
Add content object to the package manifest
|
|
153
|
+
# needs a contract...
|
|
154
|
+
"""
|
|
155
|
+
ct = Override(PartName=obj.path, ContentType=obj.mime_type)
|
|
156
|
+
self.Override.append(ct)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _write(self, archive, workbook):
|
|
160
|
+
"""
|
|
161
|
+
Write manifest to the archive
|
|
162
|
+
"""
|
|
163
|
+
self.append(workbook)
|
|
164
|
+
self._write_vba(workbook)
|
|
165
|
+
self._register_mimetypes(filenames=archive.namelist())
|
|
166
|
+
archive.writestr(self.path, tostring(self.to_tree()))
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _register_mimetypes(self, filenames):
|
|
170
|
+
"""
|
|
171
|
+
Make sure that the mime type for all file extensions is registered
|
|
172
|
+
"""
|
|
173
|
+
for fn in filenames:
|
|
174
|
+
ext = os.path.splitext(fn)[-1]
|
|
175
|
+
if not ext:
|
|
176
|
+
continue
|
|
177
|
+
mime = mimetypes.types_map[True][ext]
|
|
178
|
+
fe = FileExtension(ext[1:], mime)
|
|
179
|
+
self.Default.append(fe)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _write_vba(self, workbook):
|
|
183
|
+
"""
|
|
184
|
+
Add content types from cached workbook when keeping VBA
|
|
185
|
+
"""
|
|
186
|
+
if workbook.vba_archive:
|
|
187
|
+
node = fromstring(workbook.vba_archive.read(ARC_CONTENT_TYPES))
|
|
188
|
+
mf = Manifest.from_tree(node)
|
|
189
|
+
filenames = self.filenames
|
|
190
|
+
for override in mf.Override:
|
|
191
|
+
if override.PartName not in (ACTIVEX, CTRL, VBA):
|
|
192
|
+
continue
|
|
193
|
+
if override.PartName not in filenames:
|
|
194
|
+
self.Override.append(override)
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
import posixpath
|
|
4
|
+
from warnings import warn
|
|
5
|
+
|
|
6
|
+
from openpyxl.descriptors import (
|
|
7
|
+
String,
|
|
8
|
+
Alias,
|
|
9
|
+
Sequence,
|
|
10
|
+
)
|
|
11
|
+
from openpyxl.descriptors.serialisable import Serialisable
|
|
12
|
+
from openpyxl.descriptors.container import ElementList
|
|
13
|
+
|
|
14
|
+
from openpyxl.xml.constants import REL_NS, PKG_REL_NS
|
|
15
|
+
from openpyxl.xml.functions import (
|
|
16
|
+
Element,
|
|
17
|
+
fromstring,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Relationship(Serialisable):
|
|
22
|
+
"""Represents many kinds of relationships."""
|
|
23
|
+
|
|
24
|
+
tagname = "Relationship"
|
|
25
|
+
|
|
26
|
+
Type = String()
|
|
27
|
+
Target = String()
|
|
28
|
+
target = Alias("Target")
|
|
29
|
+
TargetMode = String(allow_none=True)
|
|
30
|
+
Id = String(allow_none=True)
|
|
31
|
+
id = Alias("Id")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def __init__(self,
|
|
35
|
+
Id=None,
|
|
36
|
+
Type=None,
|
|
37
|
+
type=None,
|
|
38
|
+
Target=None,
|
|
39
|
+
TargetMode=None
|
|
40
|
+
):
|
|
41
|
+
"""
|
|
42
|
+
`type` can be used as a shorthand with the default relationships namespace
|
|
43
|
+
otherwise the `Type` must be a fully qualified URL
|
|
44
|
+
"""
|
|
45
|
+
if type is not None:
|
|
46
|
+
Type = "{0}/{1}".format(REL_NS, type)
|
|
47
|
+
self.Type = Type
|
|
48
|
+
self.Target = Target
|
|
49
|
+
self.TargetMode = TargetMode
|
|
50
|
+
self.Id = Id
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class RelationshipList(ElementList):
|
|
54
|
+
|
|
55
|
+
tagname = "Relationships"
|
|
56
|
+
expected_type = Relationship
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def append(self, value):
|
|
60
|
+
super().append(value)
|
|
61
|
+
if not value.Id:
|
|
62
|
+
value.Id = f"rId{len(self)}"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def find(self, content_type):
|
|
66
|
+
"""
|
|
67
|
+
Find relationships by content-type
|
|
68
|
+
NB. these content-types namespaced objects and different to the MIME-types
|
|
69
|
+
in the package manifest :-(
|
|
70
|
+
"""
|
|
71
|
+
for r in self:
|
|
72
|
+
if r.Type == content_type:
|
|
73
|
+
yield r
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get(self, key):
|
|
77
|
+
for r in self:
|
|
78
|
+
if r.Id == key:
|
|
79
|
+
return r
|
|
80
|
+
raise KeyError("Unknown relationship: {0}".format(key))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def to_dict(self):
|
|
84
|
+
"""Return a dictionary of relations keyed by id"""
|
|
85
|
+
return {r.id:r for r in self}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def to_tree(self):
|
|
89
|
+
tree = super().to_tree()
|
|
90
|
+
tree.set("xmlns", PKG_REL_NS)
|
|
91
|
+
return tree
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def get_rels_path(path):
|
|
95
|
+
"""
|
|
96
|
+
Convert relative path to absolutes that can be loaded from a zip
|
|
97
|
+
archive.
|
|
98
|
+
The path to be passed in is that of containing object (workbook,
|
|
99
|
+
worksheet, etc.)
|
|
100
|
+
"""
|
|
101
|
+
folder, obj = posixpath.split(path)
|
|
102
|
+
filename = posixpath.join(folder, '_rels', '{0}.rels'.format(obj))
|
|
103
|
+
return filename
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def get_dependents(archive, filename):
|
|
107
|
+
"""
|
|
108
|
+
Normalise dependency file paths to absolute ones
|
|
109
|
+
|
|
110
|
+
Relative paths are relative to parent object
|
|
111
|
+
"""
|
|
112
|
+
src = archive.read(filename)
|
|
113
|
+
node = fromstring(src)
|
|
114
|
+
try:
|
|
115
|
+
rels = RelationshipList.from_tree(node)
|
|
116
|
+
except TypeError:
|
|
117
|
+
msg = "{0} contains invalid dependency definitions".format(filename)
|
|
118
|
+
warn(msg)
|
|
119
|
+
rels = RelationshipList()
|
|
120
|
+
folder = posixpath.dirname(filename)
|
|
121
|
+
parent = posixpath.split(folder)[0]
|
|
122
|
+
for r in rels:
|
|
123
|
+
if r.TargetMode == "External":
|
|
124
|
+
continue
|
|
125
|
+
elif r.target.startswith("/"):
|
|
126
|
+
r.target = r.target[1:]
|
|
127
|
+
else:
|
|
128
|
+
pth = posixpath.join(parent, r.target)
|
|
129
|
+
r.target = posixpath.normpath(pth)
|
|
130
|
+
return rels
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def get_rel(archive, deps, id=None, cls=None):
|
|
134
|
+
"""
|
|
135
|
+
Get related object based on id or rel_type
|
|
136
|
+
"""
|
|
137
|
+
if not any([id, cls]):
|
|
138
|
+
raise ValueError("Either the id or the content type are required")
|
|
139
|
+
if id is not None:
|
|
140
|
+
rel = deps.get(id)
|
|
141
|
+
else:
|
|
142
|
+
try:
|
|
143
|
+
rel = next(deps.find(cls.rel_type))
|
|
144
|
+
except StopIteration: # no known dependency
|
|
145
|
+
return
|
|
146
|
+
|
|
147
|
+
path = rel.target
|
|
148
|
+
src = archive.read(path)
|
|
149
|
+
tree = fromstring(src)
|
|
150
|
+
obj = cls.from_tree(tree)
|
|
151
|
+
|
|
152
|
+
rels_path = get_rels_path(path)
|
|
153
|
+
try:
|
|
154
|
+
obj.deps = get_dependents(archive, rels_path)
|
|
155
|
+
except KeyError:
|
|
156
|
+
obj.deps = []
|
|
157
|
+
|
|
158
|
+
return obj
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
from openpyxl.descriptors.serialisable import Serialisable
|
|
4
|
+
from openpyxl.descriptors import (
|
|
5
|
+
Alias,
|
|
6
|
+
Typed,
|
|
7
|
+
String,
|
|
8
|
+
Integer,
|
|
9
|
+
Bool,
|
|
10
|
+
NoneSet,
|
|
11
|
+
)
|
|
12
|
+
from openpyxl.descriptors.excel import ExtensionList, Relation
|
|
13
|
+
from openpyxl.descriptors.sequence import NestedSequence
|
|
14
|
+
from openpyxl.descriptors.nested import NestedString
|
|
15
|
+
|
|
16
|
+
from openpyxl.xml.constants import SHEET_MAIN_NS
|
|
17
|
+
|
|
18
|
+
from openpyxl.workbook.defined_name import DefinedNameList
|
|
19
|
+
from openpyxl.workbook.external_reference import ExternalReference
|
|
20
|
+
from openpyxl.workbook.function_group import FunctionGroupList
|
|
21
|
+
from openpyxl.workbook.properties import WorkbookProperties, CalcProperties, FileVersion
|
|
22
|
+
from openpyxl.workbook.protection import WorkbookProtection, FileSharing
|
|
23
|
+
from openpyxl.workbook.smart_tags import SmartTagList, SmartTagProperties
|
|
24
|
+
from openpyxl.workbook.views import CustomWorkbookView, BookView
|
|
25
|
+
from openpyxl.workbook.web import WebPublishing, WebPublishObjectList
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class FileRecoveryProperties(Serialisable):
|
|
29
|
+
|
|
30
|
+
tagname = "fileRecoveryPr"
|
|
31
|
+
|
|
32
|
+
autoRecover = Bool(allow_none=True)
|
|
33
|
+
crashSave = Bool(allow_none=True)
|
|
34
|
+
dataExtractLoad = Bool(allow_none=True)
|
|
35
|
+
repairLoad = Bool(allow_none=True)
|
|
36
|
+
|
|
37
|
+
def __init__(self,
|
|
38
|
+
autoRecover=None,
|
|
39
|
+
crashSave=None,
|
|
40
|
+
dataExtractLoad=None,
|
|
41
|
+
repairLoad=None,
|
|
42
|
+
):
|
|
43
|
+
self.autoRecover = autoRecover
|
|
44
|
+
self.crashSave = crashSave
|
|
45
|
+
self.dataExtractLoad = dataExtractLoad
|
|
46
|
+
self.repairLoad = repairLoad
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ChildSheet(Serialisable):
|
|
50
|
+
"""
|
|
51
|
+
Represents a reference to a worksheet or chartsheet in workbook.xml
|
|
52
|
+
|
|
53
|
+
It contains the title, order and state but only an indirect reference to
|
|
54
|
+
the objects themselves.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
tagname = "sheet"
|
|
58
|
+
|
|
59
|
+
name = String()
|
|
60
|
+
sheetId = Integer()
|
|
61
|
+
state = NoneSet(values=(['visible', 'hidden', 'veryHidden']))
|
|
62
|
+
id = Relation()
|
|
63
|
+
|
|
64
|
+
def __init__(self,
|
|
65
|
+
name=None,
|
|
66
|
+
sheetId=None,
|
|
67
|
+
state="visible",
|
|
68
|
+
id=None,
|
|
69
|
+
):
|
|
70
|
+
self.name = name
|
|
71
|
+
self.sheetId = sheetId
|
|
72
|
+
self.state = state
|
|
73
|
+
self.id = id
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class PivotCache(Serialisable):
|
|
77
|
+
|
|
78
|
+
tagname = "pivotCache"
|
|
79
|
+
|
|
80
|
+
cacheId = Integer()
|
|
81
|
+
id = Relation()
|
|
82
|
+
|
|
83
|
+
def __init__(self,
|
|
84
|
+
cacheId=None,
|
|
85
|
+
id=None
|
|
86
|
+
):
|
|
87
|
+
self.cacheId = cacheId
|
|
88
|
+
self.id = id
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class WorkbookPackage(Serialisable):
|
|
92
|
+
|
|
93
|
+
"""
|
|
94
|
+
Represent the workbook file in the archive
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
tagname = "workbook"
|
|
98
|
+
|
|
99
|
+
conformance = NoneSet(values=['strict', 'transitional'])
|
|
100
|
+
fileVersion = Typed(expected_type=FileVersion, allow_none=True)
|
|
101
|
+
fileSharing = Typed(expected_type=FileSharing, allow_none=True)
|
|
102
|
+
workbookPr = Typed(expected_type=WorkbookProperties, allow_none=True)
|
|
103
|
+
properties = Alias("workbookPr")
|
|
104
|
+
workbookProtection = Typed(expected_type=WorkbookProtection, allow_none=True)
|
|
105
|
+
bookViews = NestedSequence(expected_type=BookView)
|
|
106
|
+
sheets = NestedSequence(expected_type=ChildSheet)
|
|
107
|
+
functionGroups = Typed(expected_type=FunctionGroupList, allow_none=True)
|
|
108
|
+
externalReferences = NestedSequence(expected_type=ExternalReference)
|
|
109
|
+
definedNames = Typed(expected_type=DefinedNameList, allow_none=True)
|
|
110
|
+
calcPr = Typed(expected_type=CalcProperties, allow_none=True)
|
|
111
|
+
oleSize = NestedString(allow_none=True, attribute="ref")
|
|
112
|
+
customWorkbookViews = NestedSequence(expected_type=CustomWorkbookView)
|
|
113
|
+
pivotCaches = NestedSequence(expected_type=PivotCache, allow_none=True)
|
|
114
|
+
smartTagPr = Typed(expected_type=SmartTagProperties, allow_none=True)
|
|
115
|
+
smartTagTypes = Typed(expected_type=SmartTagList, allow_none=True)
|
|
116
|
+
webPublishing = Typed(expected_type=WebPublishing, allow_none=True)
|
|
117
|
+
fileRecoveryPr = Typed(expected_type=FileRecoveryProperties, allow_none=True)
|
|
118
|
+
webPublishObjects = Typed(expected_type=WebPublishObjectList, allow_none=True)
|
|
119
|
+
extLst = Typed(expected_type=ExtensionList, allow_none=True)
|
|
120
|
+
Ignorable = NestedString(namespace="http://schemas.openxmlformats.org/markup-compatibility/2006", allow_none=True)
|
|
121
|
+
|
|
122
|
+
__elements__ = ('fileVersion', 'fileSharing', 'workbookPr',
|
|
123
|
+
'workbookProtection', 'bookViews', 'sheets', 'functionGroups',
|
|
124
|
+
'externalReferences', 'definedNames', 'calcPr', 'oleSize',
|
|
125
|
+
'customWorkbookViews', 'pivotCaches', 'smartTagPr', 'smartTagTypes',
|
|
126
|
+
'webPublishing', 'fileRecoveryPr', 'webPublishObjects')
|
|
127
|
+
|
|
128
|
+
def __init__(self,
|
|
129
|
+
conformance=None,
|
|
130
|
+
fileVersion=None,
|
|
131
|
+
fileSharing=None,
|
|
132
|
+
workbookPr=None,
|
|
133
|
+
workbookProtection=None,
|
|
134
|
+
bookViews=(),
|
|
135
|
+
sheets=(),
|
|
136
|
+
functionGroups=None,
|
|
137
|
+
externalReferences=(),
|
|
138
|
+
definedNames=None,
|
|
139
|
+
calcPr=None,
|
|
140
|
+
oleSize=None,
|
|
141
|
+
customWorkbookViews=(),
|
|
142
|
+
pivotCaches=(),
|
|
143
|
+
smartTagPr=None,
|
|
144
|
+
smartTagTypes=None,
|
|
145
|
+
webPublishing=None,
|
|
146
|
+
fileRecoveryPr=None,
|
|
147
|
+
webPublishObjects=None,
|
|
148
|
+
extLst=None,
|
|
149
|
+
Ignorable=None,
|
|
150
|
+
):
|
|
151
|
+
self.conformance = conformance
|
|
152
|
+
self.fileVersion = fileVersion
|
|
153
|
+
self.fileSharing = fileSharing
|
|
154
|
+
if workbookPr is None:
|
|
155
|
+
workbookPr = WorkbookProperties()
|
|
156
|
+
self.workbookPr = workbookPr
|
|
157
|
+
self.workbookProtection = workbookProtection
|
|
158
|
+
self.bookViews = bookViews
|
|
159
|
+
self.sheets = sheets
|
|
160
|
+
self.functionGroups = functionGroups
|
|
161
|
+
self.externalReferences = externalReferences
|
|
162
|
+
self.definedNames = definedNames
|
|
163
|
+
self.calcPr = calcPr
|
|
164
|
+
self.oleSize = oleSize
|
|
165
|
+
self.customWorkbookViews = customWorkbookViews
|
|
166
|
+
self.pivotCaches = pivotCaches
|
|
167
|
+
self.smartTagPr = smartTagPr
|
|
168
|
+
self.smartTagTypes = smartTagTypes
|
|
169
|
+
self.webPublishing = webPublishing
|
|
170
|
+
self.fileRecoveryPr = fileRecoveryPr
|
|
171
|
+
self.webPublishObjects = webPublishObjects
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def to_tree(self):
|
|
175
|
+
tree = super().to_tree()
|
|
176
|
+
tree.set("xmlns", SHEET_MAIN_NS)
|
|
177
|
+
return tree
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
@property
|
|
181
|
+
def active(self):
|
|
182
|
+
for view in self.bookViews:
|
|
183
|
+
if view.activeTab is not None:
|
|
184
|
+
return view.activeTab
|
|
185
|
+
return 0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|