/usr/lib/python2.7/dist-packages/openpyxl/workbook/properties.py is in python-openpyxl 2.3.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | from __future__ import absolute_import
# Copyright (c) 2010-2015 openpyxl
import datetime
from openpyxl.compat import safe_string, unicode
from openpyxl.utils.datetime import CALENDAR_WINDOWS_1900, datetime_to_W3CDTF, W3CDTF_to_datetime
from openpyxl.descriptors import Strict, String, Typed, Alias
from openpyxl.xml.functions import ElementTree, Element, SubElement, tostring, fromstring, safe_iterator, localname
from openpyxl.xml.constants import COREPROPS_NS, DCORE_NS, XSI_NS, DCTERMS_NS, DCTERMS_PREFIX
class W3CDateTime(Typed):
expected_type = datetime.datetime
def __set__(self, instance, value):
if value is not None and isinstance(value, str):
try:
value = W3CDTF_to_datetime(value)
except ValueError:
raise ValueError("Value must be W3C datetime format")
super(W3CDateTime, self).__set__(instance, value)
class DocumentProperties(Strict):
"""High-level properties of the document.
Defined in ECMA-376 Par2 Annex D
"""
category = String(allow_none=True)
contentStatus = String(allow_none=True)
keywords = String(allow_none=True)
lastModifiedBy = String(allow_none=True)
lastPrinted = W3CDateTime(expected_type=datetime.datetime, allow_none=True)
revision = String(allow_none=True)
version = String(allow_none=True)
last_modified_by = Alias("lastModifiedBy")
# Dublin Core Properties
subject = String(allow_none=True)
title = String(allow_none=True)
creator = String(allow_none=True)
description = String(allow_none=True)
identifier = String(allow_none=True)
language = String(allow_none=True)
created = W3CDateTime(expected_type=datetime.datetime, allow_none=True)
modified = W3CDateTime(expected_type=datetime.datetime, allow_none=True)
__fields__ = ("category", "contentStatus", "lastModifiedBy", "keywords",
"lastPrinted", "revision", "version", "created", "creator", "description",
"identifier", "language", "modified", "subject", "title")
def __init__(self,
category=None,
contentStatus=None,
keywords=None,
lastModifiedBy=None,
lastPrinted=None,
revision=None,
version=None,
created=datetime.datetime.now(),
creator="openpyxl",
description=None,
identifier=None,
language=None,
modified=datetime.datetime.now(),
subject=None,
title=None,
):
self.contentStatus = contentStatus
self.lastPrinted = lastPrinted
self.revision = revision
self.version = version
self.creator = creator
self.lastModifiedBy = lastModifiedBy
self.modified = modified
self.created = created
self.title = title
self.subject = subject
self.description = description
self.identifier = identifier
self.language = language
self.keywords = keywords
self.category = category
def __iter__(self):
for attr in self.__fields__:
value = getattr(self, attr)
if value is not None:
yield attr, safe_string(value)
def write_properties(props):
"""Write the core properties to xml."""
root = Element('{%s}coreProperties' % COREPROPS_NS)
for attr in ("creator", "title", "description", "subject", "identifier",
"language"):
SubElement(root, '{%s}%s' % (DCORE_NS, attr)).text = getattr(props, attr)
for attr in ("created", "modified"):
value = datetime_to_W3CDTF(getattr(props, attr))
SubElement(root, '{%s}%s' % (DCTERMS_NS, attr),
{'{%s}type' % XSI_NS:'%s:W3CDTF' % DCTERMS_PREFIX}).text = value
for attr in ("lastModifiedBy", "category", "contentStatus", "version",
"revision", "keywords"):
SubElement(root, '{%s}%s' % (COREPROPS_NS, attr)).text = getattr(props, attr)
if props.lastPrinted is not None:
SubElement(root, "{%s}lastPrinted" % COREPROPS_NS).text = datetime_to_W3CDTF(props.lastPrinted
)
return tostring(root)
def read_properties(xml_source):
properties = DocumentProperties()
root = fromstring(xml_source)
for node in safe_iterator(root):
tag = localname(node)
setattr(properties, tag, node.text)
return properties
class DocumentSecurity(object):
"""Security information about the document."""
def __init__(self):
self.lock_revision = False
self.lock_structure = False
self.lock_windows = False
self.revision_password = ''
self.workbook_password = ''
|