MCPcopy Index your code
hub / github.com/plotly/plotly.py / validate_coerce_format

Function validate_coerce_format

plotly/io/_orca.py:46–94  ·  view source on GitHub ↗

Validate / coerce a user specified image format, and raise an informative exception if format is invalid. Parameters ---------- fmt A value that may or may not be a valid image format string. Returns ------- str or None A valid image format string a

(fmt)

Source from the content-addressed store, hash-verified

44
45
46def validate_coerce_format(fmt):
47 """
48 Validate / coerce a user specified image format, and raise an informative
49 exception if format is invalid.
50
51 Parameters
52 ----------
53 fmt
54 A value that may or may not be a valid image format string.
55
56 Returns
57 -------
58 str or None
59 A valid image format string as supported by orca. This may not
60 be identical to the input image designation. For example,
61 the resulting string will always be lower case and 'jpg' is
62 converted to 'jpeg'.
63
64 If the input format value is None, then no exception is raised and
65 None is returned.
66
67 Raises
68 ------
69 ValueError
70 if the input `fmt` cannot be interpreted as a valid image format.
71 """
72
73 # Let None pass through
74 if fmt is None:
75 return None
76
77 # Check format type
78 if not isinstance(fmt, str) or not fmt:
79 raise_format_value_error(fmt)
80
81 # Make lower case
82 fmt = fmt.lower()
83
84 # Remove leading period, if any.
85 # For example '.png' is accepted and converted to 'png'
86 if fmt[0] == ".":
87 fmt = fmt[1:]
88
89 # Check string value
90 if fmt not in format_conversions:
91 raise_format_value_error(fmt)
92
93 # Return converted string specification
94 return format_conversions[fmt]
95
96
97def find_open_port():

Callers 2

default_formatMethod · 0.85
to_imageFunction · 0.85

Calls 1

raise_format_value_errorFunction · 0.85

Tested by

no test coverage detected