MCPcopy Create free account
hub / github.com/WhyNotHugo/python-barcode / build

Method build

barcode/codabar.py:44–77  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

42 return self.code
43
44 def build(self) -> list[str]:
45 try:
46 data = (
47 codabar.STARTSTOP[self.code[0]] + "n"
48 ) # Start with [A-D], followed by a narrow space
49
50 except KeyError:
51 raise BarcodeError("Codabar should start with either A,B,C or D") from None
52
53 try:
54 data += "n".join(
55 [codabar.CODES[c] for c in self.code[1:-1]]
56 ) # separated by a narrow space
57 except KeyError:
58 raise IllegalCharacterError(
59 "Codabar can only contain numerics or $:/.+-"
60 ) from None
61
62 try:
63 data += "n" + codabar.STARTSTOP[self.code[-1]] # End with [A-D]
64 except KeyError:
65 raise BarcodeError("Codabar should end with either A,B,C or D") from None
66
67 raw = ""
68 for e in data:
69 if e == "W":
70 raw += "1" * self.wide
71 if e == "w":
72 raw += "0" * self.wide
73 if e == "N":
74 raw += "1" * self.narrow
75 if e == "n":
76 raw += "0" * self.narrow
77 return [raw]

Callers

nothing calls this directly

Calls 2

BarcodeErrorClass · 0.90

Tested by

no test coverage detected