/usr/lib/python3/dist-packages/xlsxwriter/core.py is in python3-xlsxwriter 0.7.3-1.
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | ###############################################################################
#
# Core - A class for writing the Excel XLSX Worksheet file.
#
# Copyright 2013-2015, John McNamara, jmcnamara@cpan.org
#
# Standard packages.
from datetime import datetime
# Package imports.
from . import xmlwriter
class Core(xmlwriter.XMLwriter):
"""
A class for writing the Excel XLSX Core file.
"""
###########################################################################
#
# Public API.
#
###########################################################################
def __init__(self):
"""
Constructor.
"""
super(Core, self).__init__()
self.properties = {}
###########################################################################
#
# Private API.
#
###########################################################################
def _assemble_xml_file(self):
# Assemble and write the XML file.
# Write the XML declaration.
self._xml_declaration()
self._write_cp_core_properties()
self._write_dc_title()
self._write_dc_subject()
self._write_dc_creator()
self._write_cp_keywords()
self._write_dc_description()
self._write_cp_last_modified_by()
self._write_dcterms_created()
self._write_dcterms_modified()
self._write_cp_category()
self._write_cp_content_status()
self._xml_end_tag('cp:coreProperties')
# Close the file.
self._xml_close()
def _set_properties(self, properties):
# Set the document properties.
self.properties = properties
def _localtime_to_iso8601_date(self, date):
# Convert to a ISO 8601 style "2010-01-01T00:00:00Z" date.
if not date:
date = datetime.now()
return date.strftime("%Y-%m-%dT%H:%M:%SZ")
###########################################################################
#
# XML methods.
#
###########################################################################
def _write_cp_core_properties(self):
# Write the <cp:coreProperties> element.
xmlns_cp = ('http://schemas.openxmlformats.org/package/2006/' +
'metadata/core-properties')
xmlns_dc = 'http://purl.org/dc/elements/1.1/'
xmlns_dcterms = 'http://purl.org/dc/terms/'
xmlns_dcmitype = 'http://purl.org/dc/dcmitype/'
xmlns_xsi = 'http://www.w3.org/2001/XMLSchema-instance'
attributes = [
('xmlns:cp', xmlns_cp),
('xmlns:dc', xmlns_dc),
('xmlns:dcterms', xmlns_dcterms),
('xmlns:dcmitype', xmlns_dcmitype),
('xmlns:xsi', xmlns_xsi),
]
self._xml_start_tag('cp:coreProperties', attributes)
def _write_dc_creator(self):
# Write the <dc:creator> element.
data = self.properties.get('author', '')
self._xml_data_element('dc:creator', data)
def _write_cp_last_modified_by(self):
# Write the <cp:lastModifiedBy> element.
data = self.properties.get('author', '')
self._xml_data_element('cp:lastModifiedBy', data)
def _write_dcterms_created(self):
# Write the <dcterms:created> element.
date = self.properties.get('created', datetime.now())
xsi_type = 'dcterms:W3CDTF'
date = self._localtime_to_iso8601_date(date)
attributes = [('xsi:type', xsi_type,)]
self._xml_data_element('dcterms:created', date, attributes)
def _write_dcterms_modified(self):
# Write the <dcterms:modified> element.
date = self.properties.get('created', datetime.now())
xsi_type = 'dcterms:W3CDTF'
date = self._localtime_to_iso8601_date(date)
attributes = [('xsi:type', xsi_type,)]
self._xml_data_element('dcterms:modified', date, attributes)
def _write_dc_title(self):
# Write the <dc:title> element.
if 'title' in self.properties:
data = self.properties['title']
else:
return
self._xml_data_element('dc:title', data)
def _write_dc_subject(self):
# Write the <dc:subject> element.
if 'subject' in self.properties:
data = self.properties['subject']
else:
return
self._xml_data_element('dc:subject', data)
def _write_cp_keywords(self):
# Write the <cp:keywords> element.
if 'keywords' in self.properties:
data = self.properties['keywords']
else:
return
self._xml_data_element('cp:keywords', data)
def _write_dc_description(self):
# Write the <dc:description> element.
if 'comments' in self.properties:
data = self.properties['comments']
else:
return
self._xml_data_element('dc:description', data)
def _write_cp_category(self):
# Write the <cp:category> element.
if 'category' in self.properties:
data = self.properties['category']
else:
return
self._xml_data_element('cp:category', data)
def _write_cp_content_status(self):
# Write the <cp:contentStatus> element.
if 'status' in self.properties:
data = self.properties['status']
else:
return
self._xml_data_element('cp:contentStatus', data)
|