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

Function check_color

_plotly_utils/png.py:301–325  ·  view source on GitHub ↗

Checks that a colour argument for transparent or background options is the right form. Returns the colour (which, if it's a bare integer, is "corrected" to a 1-tuple).

(c, greyscale, which)

Source from the content-addressed store, hash-verified

299
300
301def check_color(c, greyscale, which):
302 """
303 Checks that a colour argument for transparent or background options
304 is the right form.
305 Returns the colour
306 (which, if it's a bare integer, is "corrected" to a 1-tuple).
307 """
308
309 if c is None:
310 return c
311 if greyscale:
312 try:
313 len(c)
314 except TypeError:
315 c = (c,)
316 if len(c) != 1:
317 raise ProtocolError("%s for greyscale must be 1-tuple" % which)
318 if not is_natural(c[0]):
319 raise ProtocolError("%s colour for greyscale must be integer" % which)
320 else:
321 if not (
322 len(c) == 3 and is_natural(c[0]) and is_natural(c[1]) and is_natural(c[2])
323 ):
324 raise ProtocolError("%s colour must be a triple of integers" % which)
325 return c
326
327
328class Error(Exception):

Callers 1

__init__Method · 0.85

Calls 2

ProtocolErrorClass · 0.85
is_naturalFunction · 0.85

Tested by

no test coverage detected