/usr/lib/python3/dist-packages/xlsxwriter/comments.py is in python3-xlsxwriter 0.5.2-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 193 194 195 196 197 198 199 200 201 202 203 204 205 | ###############################################################################
#
# Comments - A class for writing the Excel XLSX Worksheet file.
#
# Copyright 2013, John McNamara, jmcnamara@cpan.org
#
import re
from . import xmlwriter
from .utility import xl_rowcol_to_cell
class Comments(xmlwriter.XMLwriter):
"""
A class for writing the Excel XLSX Comments file.
"""
###########################################################################
#
# Public API.
#
###########################################################################
def __init__(self):
"""
Constructor.
"""
super(Comments, self).__init__()
self.author_ids = {}
###########################################################################
#
# Private API.
#
###########################################################################
def _assemble_xml_file(self, comments_data=[]):
# Assemble and write the XML file.
# Write the XML declaration.
self._xml_declaration()
# Write the comments element.
self._write_comments()
# Write the authors element.
self._write_authors(comments_data)
# Write the commentList element.
self._write_comment_list(comments_data)
self._xml_end_tag('comments')
# Close the file.
self._xml_close()
###########################################################################
#
# XML methods.
#
###########################################################################
def _write_comments(self):
# Write the <comments> element.
xmlns = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'
attributes = [('xmlns', xmlns)]
self._xml_start_tag('comments', attributes)
def _write_authors(self, comment_data):
# Write the <authors> element.
author_count = 0
self._xml_start_tag('authors')
for comment in comment_data:
author = comment[3]
if author is not None and not author in self.author_ids:
# Store the author id.
self.author_ids[author] = author_count
author_count += 1
# Write the author element.
self._write_author(author)
self._xml_end_tag('authors')
def _write_author(self, data):
# Write the <author> element.
self._xml_data_element('author', data)
def _write_comment_list(self, comment_data):
# Write the <commentList> element.
self._xml_start_tag('commentList')
for comment in comment_data:
row = comment[0]
col = comment[1]
text = comment[2]
author = comment[3]
# Look up the author id.
author_id = None
if author is not None:
author_id = self.author_ids[author]
# Write the comment element.
self._write_comment(row, col, text, author_id)
self._xml_end_tag('commentList')
def _write_comment(self, row, col, text, author_id):
# Write the <comment> element.
ref = xl_rowcol_to_cell(row, col)
attributes = [('ref', ref)]
if author_id is not None:
attributes.append(('authorId', author_id))
self._xml_start_tag('comment', attributes)
# Write the text element.
self._write_text(text)
self._xml_end_tag('comment')
def _write_text(self, text):
# Write the <text> element.
self._xml_start_tag('text')
# Write the text r element.
self._write_text_r(text)
self._xml_end_tag('text')
def _write_text_r(self, text):
# Write the <r> element.
self._xml_start_tag('r')
# Write the rPr element.
self._write_r_pr()
# Write the text r element.
self._write_text_t(text)
self._xml_end_tag('r')
def _write_text_t(self, text):
# Write the text <t> element.
attributes = []
if re.search('^\s', text) or re.search('\s$', text):
attributes.append(('xml:space', 'preserve'))
self._xml_data_element('t', text, attributes)
def _write_r_pr(self):
# Write the <rPr> element.
self._xml_start_tag('rPr')
# Write the sz element.
self._write_sz()
# Write the color element.
self._write_color()
# Write the rFont element.
self._write_r_font()
# Write the family element.
self._write_family()
self._xml_end_tag('rPr')
def _write_sz(self):
# Write the <sz> element.
attributes = [('val', 8)]
self._xml_empty_tag('sz', attributes)
def _write_color(self):
# Write the <color> element.
attributes = [('indexed', 81)]
self._xml_empty_tag('color', attributes)
def _write_r_font(self):
# Write the <rFont> element.
attributes = [('val', 'Tahoma')]
self._xml_empty_tag('rFont', attributes)
def _write_family(self):
# Write the <family> element.
attributes = [('val', 2)]
self._xml_empty_tag('family', attributes)
|