Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/openpyxl/packaging/core.py: 57%
58 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1# Copyright (c) 2010-2022 openpyxl
3import datetime
5from openpyxl.compat import safe_string
6from openpyxl.descriptors import (
7 String,
8 DateTime,
9 Alias,
10 )
11from openpyxl.descriptors.serialisable import Serialisable
12from openpyxl.descriptors.nested import NestedText
13from openpyxl.xml.functions import (Element, QName, tostring)
14from openpyxl.xml.constants import (
15 COREPROPS_NS,
16 DCORE_NS,
17 XSI_NS,
18 DCTERMS_NS,
19 DCTERMS_PREFIX
20)
22class NestedDateTime(DateTime, NestedText):
24 expected_type = datetime.datetime
26 def to_tree(self, tagname=None, value=None, namespace=None):
27 namespace = getattr(self, "namespace", namespace)
28 if namespace is not None:
29 tagname = "{%s}%s" % (namespace, tagname)
30 el = Element(tagname)
31 if value is not None:
32 el.text = value.isoformat(timespec="seconds") + 'Z'
33 return el
36class QualifiedDateTime(NestedDateTime):
38 """In certain situations Excel will complain if the additional type
39 attribute isn't set"""
41 def to_tree(self, tagname=None, value=None, namespace=None):
42 el = super(QualifiedDateTime, self).to_tree(tagname, value, namespace)
43 el.set("{%s}type" % XSI_NS, QName(DCTERMS_NS, "W3CDTF"))
44 return el
47class DocumentProperties(Serialisable):
48 """High-level properties of the document.
49 Defined in ECMA-376 Par2 Annex D
50 """
52 tagname = "coreProperties"
53 namespace = COREPROPS_NS
55 category = NestedText(expected_type=str, allow_none=True)
56 contentStatus = NestedText(expected_type=str, allow_none=True)
57 keywords = NestedText(expected_type=str, allow_none=True)
58 lastModifiedBy = NestedText(expected_type=str, allow_none=True)
59 lastPrinted = NestedDateTime(allow_none=True)
60 revision = NestedText(expected_type=str, allow_none=True)
61 version = NestedText(expected_type=str, allow_none=True)
62 last_modified_by = Alias("lastModifiedBy")
64 # Dublin Core Properties
65 subject = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
66 title = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
67 creator = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
68 description = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
69 identifier = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
70 language = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
71 # Dublin Core Terms
72 created = QualifiedDateTime(allow_none=True, namespace=DCTERMS_NS)
73 modified = QualifiedDateTime(allow_none=True, namespace=DCTERMS_NS)
75 __elements__ = ("creator", "title", "description", "subject","identifier",
76 "language", "created", "modified", "lastModifiedBy", "category",
77 "contentStatus", "version", "revision", "keywords", "lastPrinted",
78 )
81 def __init__(self,
82 category=None,
83 contentStatus=None,
84 keywords=None,
85 lastModifiedBy=None,
86 lastPrinted=None,
87 revision=None,
88 version=None,
89 created=datetime.datetime.utcnow(),
90 creator="openpyxl",
91 description=None,
92 identifier=None,
93 language=None,
94 modified=datetime.datetime.utcnow(),
95 subject=None,
96 title=None,
97 ):
98 self.contentStatus = contentStatus
99 self.lastPrinted = lastPrinted
100 self.revision = revision
101 self.version = version
102 self.creator = creator
103 self.lastModifiedBy = lastModifiedBy
104 self.modified = modified
105 self.created = created
106 self.title = title
107 self.subject = subject
108 self.description = description
109 self.identifier = identifier
110 self.language = language
111 self.keywords = keywords
112 self.category = category