-
-
Notifications
You must be signed in to change notification settings - Fork 134
Update codex.py #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Update codex.py #56
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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) | ||
|
|
||
|
|
@@ -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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. List comprehension seems redundant here.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Completely agree, not sure how that line got changed.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| for k, v in code39.MAP.items(): | ||
| if check == v[0]: | ||
| return k | ||
|
|
@@ -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) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.