Skip to content

Commit 545fef6

Browse files
author
Fernando Governatore
committed
Facilitates sub-classing and user customization by using self
This allows changing the default_writer/default_writer_options for some sub-classes of Barcode without affecting all of them.
1 parent 95d3f05 commit 545fef6

5 files changed

Lines changed: 6 additions & 6 deletions

File tree

barcode/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def render(self, writer_options=None, text=None):
9393
9494
:returns: Output of the writers render method.
9595
"""
96-
options = Barcode.default_writer_options.copy()
96+
options = self.default_writer_options.copy()
9797
options.update(writer_options or {})
9898
if options["write_text"] or text is not None:
9999
if text is not None:

barcode/codex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, code: str, writer=None, add_checksum: bool = True):
4545
self.code = code.upper()
4646
if add_checksum:
4747
self.code += self.calculate_checksum()
48-
self.writer = writer or Barcode.default_writer()
48+
self.writer = writer or self.default_writer()
4949
check_code(self.code, self.name, code39.REF)
5050

5151
def __str__(self):
@@ -133,7 +133,7 @@ class Code128(Barcode):
133133

134134
def __init__(self, code, writer=None):
135135
self.code = code
136-
self.writer = writer or Barcode.default_writer()
136+
self.writer = writer or self.default_writer()
137137
self._charset = "B"
138138
self._buffer = ""
139139
check_code(self.code, self.name, code128.ALL)

barcode/ean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self, ean, writer=None, no_checksum=False, guardbar=False):
7272
else:
7373
self.EDGE = _ean.EDGE
7474
self.MIDDLE = _ean.MIDDLE
75-
self.writer = writer or Barcode.default_writer()
75+
self.writer = writer or self.default_writer()
7676

7777
def __str__(self):
7878
return self.ean

barcode/itf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self, code, writer=None, narrow=2, wide=5):
3636
if len(code) % 2 != 0:
3737
code = "0" + code
3838
self.code = code
39-
self.writer = writer or Barcode.default_writer()
39+
self.writer = writer or self.default_writer()
4040
self.narrow = narrow
4141
self.wide = wide
4242

barcode/upc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, upc, writer=None, make_ean=False):
4141
)
4242
self.upc = upc
4343
self.upc = "{}{}".format(upc, self.calculate_checksum())
44-
self.writer = writer or Barcode.default_writer()
44+
self.writer = writer or self.default_writer()
4545

4646
def __str__(self):
4747
if self.ean:

0 commit comments

Comments
 (0)