Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions plotly/io/_orca.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def raise_format_value_error(val):

An image format must be specified as one of the following string values:
{valid_formats}""".format(
typ=type(val), v=val, valid_formats=sorted(format_conversions.keys())
typ=type(val),
v=val,
valid_formats=", ".join(sorted(format_conversions.keys())),
)
)

Expand Down Expand Up @@ -78,14 +80,20 @@ def validate_coerce_format(fmt):
if not isinstance(fmt, str) or not fmt:
raise_format_value_error(fmt)

# Make lower case
fmt = fmt.lower()

# Remove leading period, if any.
# For example '.png' is accepted and converted to 'png'
if fmt[0] == ".":
fmt_len = len(fmt)
if fmt_len and fmt[0] == ".":
# Avoids creation of intermediate lower-case string if only leading
# period needs stripping; also avoids extra slice for empty string.
fmt = fmt[1:]

# Check string value
if not fmt:
raise_format_value_error(".")
# Lower after removing dot, only once
fmt = fmt.lower()
else:
fmt = fmt.lower()

# Check string value
if fmt not in format_conversions:
raise_format_value_error(fmt)
Expand Down