Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/openpyxl/packaging/core.py : 58%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright (c) 2010-2020 openpyxl
3import datetime
5from openpyxl.compat import safe_string
6from openpyxl.utils.datetime import (
7 CALENDAR_WINDOWS_1900,
8 to_ISO8601,
9 from_ISO8601,
10)
11from openpyxl.descriptors import (
12 String,
13 DateTime,
14 Alias,
15 )
16from openpyxl.descriptors.serialisable import Serialisable
17from openpyxl.descriptors.nested import NestedText
18from openpyxl.xml.functions import (Element, QName, tostring)
19from openpyxl.xml.constants import (
20 COREPROPS_NS,
21 DCORE_NS,
22 XSI_NS,
23 DCTERMS_NS,
24 DCTERMS_PREFIX
25)
27class NestedDateTime(DateTime, NestedText):
29 expected_type = datetime.datetime
31 def to_tree(self, tagname=None, value=None, namespace=None):
32 namespace = getattr(self, "namespace", namespace)
33 if namespace is not None:
34 tagname = "{%s}%s" % (namespace, tagname)
35 el = Element(tagname)
36 if value is not None:
37 el.text = to_ISO8601(value)
38 return el
41class QualifiedDateTime(NestedDateTime):
43 """In certain situations Excel will complain if the additional type
44 attribute isn't set"""
46 def to_tree(self, tagname=None, value=None, namespace=None):
47 el = super(QualifiedDateTime, self).to_tree(tagname, value, namespace)
48 el.set("{%s}type" % XSI_NS, QName(DCTERMS_NS, "W3CDTF"))
49 return el
52class DocumentProperties(Serialisable):
53 """High-level properties of the document.
54 Defined in ECMA-376 Par2 Annex D
55 """
57 tagname = "coreProperties"
58 namespace = COREPROPS_NS
60 category = NestedText(expected_type=str, allow_none=True)
61 contentStatus = NestedText(expected_type=str, allow_none=True)
62 keywords = NestedText(expected_type=str, allow_none=True)
63 lastModifiedBy = NestedText(expected_type=str, allow_none=True)
64 lastPrinted = NestedDateTime(allow_none=True)
65 revision = NestedText(expected_type=str, allow_none=True)
66 version = NestedText(expected_type=str, allow_none=True)
67 last_modified_by = Alias("lastModifiedBy")
69 # Dublin Core Properties
70 subject = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
71 title = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
72 creator = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
73 description = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
74 identifier = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
75 language = NestedText(expected_type=str, allow_none=True, namespace=DCORE_NS)
76 # Dublin Core Terms
77 created = QualifiedDateTime(allow_none=True, namespace=DCTERMS_NS)
78 modified = QualifiedDateTime(allow_none=True, namespace=DCTERMS_NS)
80 __elements__ = ("creator", "title", "description", "subject","identifier",
81 "language", "created", "modified", "lastModifiedBy", "category",
82 "contentStatus", "version", "revision", "keywords", "lastPrinted",
83 )
86 def __init__(self,
87 category=None,
88 contentStatus=None,
89 keywords=None,
90 lastModifiedBy=None,
91 lastPrinted=None,
92 revision=None,
93 version=None,
94 created=datetime.datetime.now(),
95 creator="openpyxl",
96 description=None,
97 identifier=None,
98 language=None,
99 modified=datetime.datetime.now(),
100 subject=None,
101 title=None,
102 ):
103 self.contentStatus = contentStatus
104 self.lastPrinted = lastPrinted
105 self.revision = revision
106 self.version = version
107 self.creator = creator
108 self.lastModifiedBy = lastModifiedBy
109 self.modified = modified
110 self.created = created
111 self.title = title
112 self.subject = subject
113 self.description = description
114 self.identifier = identifier
115 self.language = language
116 self.keywords = keywords
117 self.category = category