Skip to content

Commit

Permalink
Minor sonarcloud fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcnamara committed May 21, 2023
1 parent 672ed68 commit 019c136
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 60 deletions.
12 changes: 1 addition & 11 deletions xlsxwriter/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3047,7 +3047,7 @@ def _write_a_p_formula(self, font):
self._xml_start_tag("a:p")

# Write the a:pPr element.
self._write_a_p_pr_formula(font)
self._write_a_p_pr_rich(font)

# Write the a:endParaRPr element.
self._write_a_end_para_rpr()
Expand All @@ -3064,16 +3064,6 @@ def _write_a_p_pr_rich(self, font):

self._xml_end_tag("a:pPr")

def _write_a_p_pr_formula(self, font):
# Write the <a:pPr> element for formula titles.

self._xml_start_tag("a:pPr")

# Write the a:defRPr element.
self._write_a_def_rpr(font)

self._xml_end_tag("a:pPr")

def _write_a_def_rpr(self, font):
# Write the <a:defRPr> element.
has_color = 0
Expand Down
4 changes: 2 additions & 2 deletions xlsxwriter/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def _write_worksheet_rels_files(self):
rels = Relationships()

for link_data in external_links:
rels._add_worksheet_relationship(*link_data)
rels._add_document_relationship(*link_data)

# Create .rels file such as /xl/worksheets/_rels/sheet1.xml.rels.
rels._set_xml_writer(
Expand All @@ -583,7 +583,7 @@ def _write_chartsheet_rels_files(self):
rels = Relationships()

for link_data in external_links:
rels._add_worksheet_relationship(*link_data)
rels._add_document_relationship(*link_data)

# Create .rels file such as /xl/chartsheets/_rels/sheet1.xml.rels.
rels._set_xml_writer(
Expand Down
6 changes: 0 additions & 6 deletions xlsxwriter/relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ def _add_ms_package_relationship(self, rel_type, target):

self.relationships.append((rel_type, target, None))

def _add_worksheet_relationship(self, rel_type, target, target_mode=None):
# Add worksheet relationship to sheet.rels xml files.
rel_type = document_schema + rel_type

self.relationships.append((rel_type, target, target_mode))

###########################################################################
#
# XML methods.
Expand Down
12 changes: 6 additions & 6 deletions xlsxwriter/workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,11 +1190,11 @@ def _prepare_drawings(self):

(
image_type,
width,
height,
name,
x_dpi,
y_dpi,
_,
_,
_,
_,
_,
digest,
) = self._get_image_properties(filename, image_data)

Expand Down Expand Up @@ -1313,7 +1313,7 @@ def _prepare_drawings(self):
self.images.append([filename, image_type, image_data])

sheet._prepare_header_image(
image_ref_id,
ref_id,
width,
height,
name,
Expand Down
71 changes: 36 additions & 35 deletions xlsxwriter/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,16 @@ def _write_token_as_string(self, token, row, col, *args):
if token.startswith("{=") and token.endswith("}"):
return self._write_formula(row, col, *args)

if ":" in token:
if self.strings_to_urls and re.match("(ftp|http)s?://", token):
return self._write_url(row, col, *args)
elif self.strings_to_urls and re.match("mailto:", token):
return self._write_url(row, col, *args)
elif self.strings_to_urls and re.match("(in|ex)ternal:", token):
return self._write_url(row, col, *args)
if (
":" in token
and self.strings_to_urls
and (
re.match("(ftp|http)s?://", token)
or re.match("mailto:", token)
or re.match("(in|ex)ternal:", token)
)
):
return self._write_url(row, col, *args)

if self.strings_to_numbers:
try:
Expand Down Expand Up @@ -2035,9 +2038,8 @@ def autofit(self):

# If the cell is in an autofilter header we add an
# additional 16 pixels for the dropdown arrow.
if self.filter_cells.get((row_num, col_num)):
if length > 0:
length += 16
if self.filter_cells.get((row_num, col_num)) and length > 0:
length += 16

# Add the string length to the lookup table.
width_max = col_width_max.get(col_num, 0)
Expand Down Expand Up @@ -2575,10 +2577,9 @@ def data_validation(self, first_row, first_col, last_row, last_col, options=None
# Format date number to the same precision as Excel.
options["value"] = "%.16g" % date_time

if options["maximum"]:
if supported_datetime(options["maximum"]):
date_time = self._convert_date_time(options["maximum"])
options["maximum"] = "%.16g" % date_time
if options["maximum"] and supported_datetime(options["maximum"]):
date_time = self._convert_date_time(options["maximum"])
options["maximum"] = "%.16g" % date_time

# Check that the input title doesn't exceed the maximum length.
if options.get("input_title") and len(options["input_title"]) > 32:
Expand Down Expand Up @@ -8296,47 +8297,47 @@ def _write_ignored_errors(self):
self._xml_start_tag("ignoredErrors")

if self.ignored_errors.get("number_stored_as_text"):
range = self.ignored_errors["number_stored_as_text"]
self._write_ignored_error("numberStoredAsText", range)
ignored_range = self.ignored_errors["number_stored_as_text"]
self._write_ignored_error("numberStoredAsText", ignored_range)

if self.ignored_errors.get("eval_error"):
range = self.ignored_errors["eval_error"]
self._write_ignored_error("evalError", range)
ignored_range = self.ignored_errors["eval_error"]
self._write_ignored_error("evalError", ignored_range)

if self.ignored_errors.get("formula_differs"):
range = self.ignored_errors["formula_differs"]
self._write_ignored_error("formula", range)
ignored_range = self.ignored_errors["formula_differs"]
self._write_ignored_error("formula", ignored_range)

if self.ignored_errors.get("formula_range"):
range = self.ignored_errors["formula_range"]
self._write_ignored_error("formulaRange", range)
if self.ignored_errors.get("formula_ignored_range"):
ignored_range = self.ignored_errors["formula_ignored_range"]
self._write_ignored_error("formulaIgnored_range", ignored_range)

if self.ignored_errors.get("formula_unlocked"):
range = self.ignored_errors["formula_unlocked"]
self._write_ignored_error("unlockedFormula", range)
ignored_range = self.ignored_errors["formula_unlocked"]
self._write_ignored_error("unlockedFormula", ignored_range)

if self.ignored_errors.get("empty_cell_reference"):
range = self.ignored_errors["empty_cell_reference"]
self._write_ignored_error("emptyCellReference", range)
ignored_range = self.ignored_errors["empty_cell_reference"]
self._write_ignored_error("emptyCellReference", ignored_range)

if self.ignored_errors.get("list_data_validation"):
range = self.ignored_errors["list_data_validation"]
self._write_ignored_error("listDataValidation", range)
ignored_range = self.ignored_errors["list_data_validation"]
self._write_ignored_error("listDataValidation", ignored_range)

if self.ignored_errors.get("calculated_column"):
range = self.ignored_errors["calculated_column"]
self._write_ignored_error("calculatedColumn", range)
ignored_range = self.ignored_errors["calculated_column"]
self._write_ignored_error("calculatedColumn", ignored_range)

if self.ignored_errors.get("two_digit_text_year"):
range = self.ignored_errors["two_digit_text_year"]
self._write_ignored_error("twoDigitTextYear", range)
ignored_range = self.ignored_errors["two_digit_text_year"]
self._write_ignored_error("twoDigitTextYear", ignored_range)

self._xml_end_tag("ignoredErrors")

def _write_ignored_error(self, type, range):
def _write_ignored_error(self, type, ignored_range):
# Write the <ignoredError> element.
attributes = [
("sqref", range),
("sqref", ignored_range),
(type, 1),
]

Expand Down

0 comments on commit 019c136

Please sign in to comment.