Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions barcode/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def check_code(code, name, allowed):


class Code39(Barcode):
r"""Initializes a new Code39 instance.
"""Initializes a new Code39 instance.

:parameters:
code : String
Expand All @@ -44,11 +44,11 @@ class Code39(Barcode):
"""

name = 'Code 39'
add_checksum_default = True

def __init__(self, code, writer=None, add_checksum=True):
def __init__(self, code, writer=None):
self.checksum_added = False
self.code = code.upper()
if add_checksum:
self.code += self.calculate_checksum()
self.writer = writer or Barcode.default_writer()
check_code(self.code, self.name, code39.REF)

Expand All @@ -61,7 +61,7 @@ def get_fullcode(self):
return self.code

def calculate_checksum(self):
check = sum(code39.MAP[x][0] for x in self.code) % 43
check = sum([code39.MAP[x][0] for x in self.code]) % 43
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List comprehension seems redundant here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely agree, not sure how that line got changed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I didn't see an example of it being added twice, but if anyone called the render function twice then it would.
Agreed on list comprehension

for k, v in code39.MAP.items():
if check == v[0]:
return k
Expand All @@ -74,7 +74,12 @@ def build(self):
return [code39.MIDDLE.join(chars)]

def render(self, writer_options=None, text=None):
options = {'module_width': MIN_SIZE, 'quiet_zone': MIN_QUIET_ZONE}
options = dict(module_width=MIN_SIZE, quiet_zone=MIN_QUIET_ZONE)
# moved check sum logic here
add_checksum = writer_options.get('add_checksum', self.add_checksum_default)
if add_checksum and not self.checksum_added:
self.code += self.calculate_checksum()
self.checksum_added = True
options.update(writer_options or {})
return Barcode.render(self, options, text)

Expand Down