MCPcopy Index your code
hub / github.com/lincolnloop/python-qrcode / __init__

Method __init__

qrcode/util.py:422–439  ·  view source on GitHub ↗

If ``mode`` isn't provided, the most compact QR data type possible is chosen.

(self, data, mode=None, check_data=True)

Source from the content-addressed store, hash-verified

420 """
421
422 def __init__(self, data, mode=None, check_data=True):
423 """
424 If ``mode`` isn't provided, the most compact QR data type possible is
425 chosen.
426 """
427 if check_data:
428 data = to_bytestring(data)
429
430 if mode is None:
431 self.mode = optimal_mode(data)
432 else:
433 self.mode = mode
434 if mode not in (MODE_NUMBER, MODE_ALPHA_NUM, MODE_8BIT_BYTE):
435 raise TypeError(f"Invalid mode ({mode})") # pragma: no cover
436 if check_data and mode < optimal_mode(data): # pragma: no cover
437 raise ValueError(f"Provided data can not be represented in mode {mode}")
438
439 self.data = data
440
441 def __len__(self):
442 return len(self.data)

Callers

nothing calls this directly

Calls 2

to_bytestringFunction · 0.85
optimal_modeFunction · 0.85

Tested by

no test coverage detected