Skip to content

Commit 50d2e28

Browse files
maresbWhyNotHugo
authored andcommitted
Enforce singletons in ImageWriter and SVGWriter
1 parent a59f7ea commit 50d2e28

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

barcode/writer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ def __init__(self) -> None:
323323
self._group: xml.dom.minidom.Element
324324

325325
def _init(self, code: list[str]):
326-
width, height = self.calculate_size(len(code[0]), len(code))
326+
if len(code) != 1:
327+
raise NotImplementedError("Only one line of code is supported")
328+
line = code[0]
329+
width, height = self.calculate_size(len(line), 1)
327330
self._document = create_svg_object(self.with_doctype)
328331
self._root = self._document.documentElement
329332
attributes = {
@@ -443,7 +446,10 @@ def __init__(self, format="PNG", mode="RGB", dpi=300) -> None:
443446
def _init(self, code: list[str]) -> None:
444447
if ImageDraw is None:
445448
raise RuntimeError("Pillow not found. Cannot create image.")
446-
width, height = self.calculate_size(len(code[0]), len(code))
449+
if len(code) != 1:
450+
raise NotImplementedError("Only one line of code is supported")
451+
line = code[0]
452+
width, height = self.calculate_size(len(line), 1)
447453
size = (int(mm2px(width, self.dpi)), int(mm2px(height, self.dpi)))
448454
self._image = Image.new(self.mode, size, self.background)
449455
self._draw = ImageDraw.Draw(self._image)

0 commit comments

Comments
 (0)