Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def palette_epilogue(book):
# Check colour indexes in fonts etc.
# This must be done here as FONT records
# come *before* the PALETTE record :-(
for font in book.font_list:
if font.font_index == 4: # the missing font record
continue
cx = font.colour_index
if cx == 0x7fff: # system window text colour
continue
if cx in book.colour_map:
book.colour_indexes_used[cx] = 1
elif book.verbosity:
print("Size of colour table:", len(book.colour_map), file=book.logfile)
fprintf(book.logfile, "*** Font #%d (%r): colour index 0x%04x is unknown\n",
font.font_index, font.name, cx)
if book.verbosity >= 1:
used = sorted(book.colour_indexes_used.keys())
print("\nColour indexes used:\n%r\n" % used, file=book.logfile)
fmt = self.format_map[xf.format_key]
cellty = _cellty_from_fmtty[fmt.type]
except KeyError:
cellty = XL_CELL_NUMBER
self._xf_index_to_xl_type_map[xf.xf_index] = cellty
# Now for some assertions ...
if self.formatting_info:
if self.verbosity and xf.is_style and xf.parent_style_index != 0x0FFF:
msg = "WARNING *** XF[%d] is a style XF but parent_style_index is 0x%04x, not 0x0fff\n"
fprintf(self.logfile, msg, xf.xf_index, xf.parent_style_index)
check_colour_indexes_in_obj(self, xf, xf.xf_index)
if xf.format_key not in self.format_map:
msg = "WARNING *** XF[%d] unknown (raw) format key (%d, 0x%04x)\n"
if self.verbosity:
fprintf(self.logfile, msg,
xf.xf_index, xf.format_key, xf.format_key)
xf.format_key = 0
level = 0
if bv >= 80:
try:
name = unpack_unicode(data, 2, lenlen=2)
except UnicodeDecodeError:
print("STYLE: built_in=%d xf_index=%d built_in_id=%d level=%d"
% (built_in, xf_index, built_in_id, level), file=book.logfile)
print("raw bytes:", repr(data[2:]), file=book.logfile)
raise
else:
name = unpack_string(data, 2, book.encoding, lenlen=1)
if blah and not name:
print("WARNING *** A user-defined style has a zero-length name", file=book.logfile)
book.style_name_map[name] = (built_in, xf_index)
if blah:
fprintf(book.logfile, "STYLE: built_in=%d xf_index=%d built_in_id=%d level=%d name=%r\n",
built_in, xf_index, built_in_id, level, name)
xf = self.xf_list[xfx]
try:
fmt = self.format_map[xf.format_key]
cellty = _cellty_from_fmtty[fmt.type]
except KeyError:
cellty = XL_CELL_TEXT
self._xf_index_to_xl_type_map[xf.xf_index] = cellty
# Now for some assertions etc
if not self.formatting_info:
continue
if xf.is_style:
continue
if not(0 <= xf.parent_style_index < num_xfs):
if blah1:
fprintf(self.logfile,
"WARNING *** XF[%d]: is_style=%d but parent_style_index=%d\n",
xf.xf_index, xf.is_style, xf.parent_style_index)
# make it conform
xf.parent_style_index = 0
if self.biff_version >= 30:
if blah1:
if xf.parent_style_index == xf.xf_index:
fprintf(self.logfile,
"NOTE !!! XF[%d]: parent_style_index is also %d\n",
xf.xf_index, xf.parent_style_index)
elif not self.xf_list[xf.parent_style_index].is_style:
fprintf(self.logfile,
"NOTE !!! XF[%d]: parent_style_index is %d; style flag not set\n",
xf.xf_index, xf.parent_style_index)
if blah1 and xf.parent_style_index > xf.xf_index:
fprintf(self.logfile,
def check_same(book_arg, xf_arg, parent_arg, attr):
# the _arg caper is to avoid a Warning msg from Python 2.1 :-(
if getattr(xf_arg, attr) != getattr(parent_arg, attr):
fprintf(book_arg.logfile,
"NOTE !!! XF[%d] parent[%d] %s different\n",
xf_arg.xf_index, parent_arg.xf_index, attr)
if blah:
fprintf(self.logfile,
"FORMAT: count=%d fmtkey=0x%04x (%d) s=%r\n",
self.actualfmtcount, fmtkey, fmtkey, unistrg)
is_date_s = self.is_date_format_string(unistrg)
ty = [FGE, FDT][is_date_s]
if not(fmtkey > 163 or bv < 50):
# user_defined if fmtkey > 163
# N.B. Gnumeric incorrectly starts these at 50 instead of 164 :-(
# if earlier than BIFF 5, standard info is useless
std_ty = std_format_code_types.get(fmtkey, FUN)
# print "std ty", std_ty
is_date_c = std_ty == FDT
if self.verbosity and 0 < fmtkey < 50 and (is_date_c ^ is_date_s):
DEBUG = 2
fprintf(self.logfile,
"WARNING *** Conflict between "
"std format key %d and its format string %r\n",
fmtkey, unistrg)
if DEBUG == 2:
fprintf(self.logfile,
"ty: %d; is_date_c: %r; is_date_s: %r; fmt_strg: %r",
ty, is_date_c, is_date_s, unistrg)
fmtobj = Format(fmtkey, ty, unistrg)
if blah:
fmtobj.dump(self.logfile,
header="--- handle_format [%d] ---" % (self.actualfmtcount-1, ))
self.format_map[fmtkey] = fmtobj
self.format_list.append(fmtobj)
self.derive_encoding()
strpos = 2
if bv >= 50:
fmtkey = unpack('= 80:
unistrg = unpack_unicode(data, 2)
else:
unistrg = unpack_string(data, strpos, self.encoding, lenlen=1)
blah = DEBUG or self.verbosity >= 3
if blah:
fprintf(self.logfile,
"FORMAT: count=%d fmtkey=0x%04x (%d) s=%r\n",
self.actualfmtcount, fmtkey, fmtkey, unistrg)
is_date_s = self.is_date_format_string(unistrg)
ty = [FGE, FDT][is_date_s]
if not(fmtkey > 163 or bv < 50):
# user_defined if fmtkey > 163
# N.B. Gnumeric incorrectly starts these at 50 instead of 164 :-(
# if earlier than BIFF 5, standard info is useless
std_ty = std_format_code_types.get(fmtkey, FUN)
# print "std ty", std_ty
is_date_c = std_ty == FDT
if self.verbosity and 0 < fmtkey < 50 and (is_date_c ^ is_date_s):
DEBUG = 2
fprintf(self.logfile,
"WARNING *** Conflict between "
"std format key %d and its format string %r\n",
if blah1 and xf.parent_style_index > xf.xf_index:
fprintf(self.logfile,
"NOTE !!! XF[%d]: parent_style_index is %d; out of order?\n",
xf.xf_index, xf.parent_style_index)
parent = self.xf_list[xf.parent_style_index]
if not xf._alignment_flag and not parent._alignment_flag:
if blah1: check_same(self, xf, parent, 'alignment')
if not xf._background_flag and not parent._background_flag:
if blah1: check_same(self, xf, parent, 'background')
if not xf._border_flag and not parent._border_flag:
if blah1: check_same(self, xf, parent, 'border')
if not xf._protection_flag and not parent._protection_flag:
if blah1: check_same(self, xf, parent, 'protection')
if not xf._format_flag and not parent._format_flag:
if blah1 and xf.format_key != parent.format_key:
fprintf(self.logfile,
"NOTE !!! XF[%d] fmtk=%d, parent[%d] fmtk=%r\n%r / %r\n",
xf.xf_index, xf.format_key, parent.xf_index, parent.format_key,
self.format_map[xf.format_key].format_str,
self.format_map[parent.format_key].format_str)
if not xf._font_flag and not parent._font_flag:
if blah1 and xf.font_index != parent.font_index:
fprintf(self.logfile,
"NOTE !!! XF[%d] fontx=%d, parent[%d] fontx=%r\n",
xf.xf_index, xf.font_index, parent.xf_index, parent.font_index)