Skip to content

Commit 541e65f

Browse files
author
Thorsten Weimann
committed
Merged in _Frky/python-barcode (pull request #8)
Fix inconsistency in documentation of writers + add an option to EAN-13 barcode generation
2 parents ebfae45 + a7800e0 commit 541e65f

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

barcode/ean.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,23 @@ class EuropeanArticleNumber13(Barcode):
3737

3838
digits = 12
3939

40-
def __init__(self, ean, writer=None):
40+
def __init__(self, ean, writer=None, **kwargs):
41+
no_checksum = False
42+
if "no_checksum" in kwargs.keys():
43+
no_checksum = kwargs["no_checksum"]
4144
ean = ean[:self.digits]
4245
if not ean.isdigit():
4346
raise IllegalCharacterError('EAN code can only contain numbers.')
4447
if len(ean) != self.digits:
4548
raise NumberOfDigitsError('EAN must have {0} digits, not '
4649
'{1}.'.format(self.digits, len(ean)))
4750
self.ean = ean
48-
self.ean = '{0}{1}'.format(ean, self.calculate_checksum())
51+
# If no checksum
52+
if no_checksum:
53+
# Add a thirteen char if given in parameter, otherwise pad with zero
54+
self.ean = '{0}{1}'.format(ean, ean[self.digits] if len(ean) > self.digits else 0)
55+
else:
56+
self.ean = '{0}{1}'.format(ean, self.calculate_checksum())
4957
self.writer = writer or Barcode.default_writer()
5058

5159
def __unicode__(self):

docs/writers/index.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Common Writer Options
77
---------------------
88

99
All writer take the following options (specified as keyword arguments
10-
to `Barcode.save(filename, option=value)` or set via
11-
`Writer.set_options(option=value)`).
10+
to `Barcode.save(filename, options)` or set via
11+
`Writer.set_options(options)`, where `options` is a dictionary where keys are option names and values are option
12+
values to be set).
1213

1314
.. note::
1415
See the documentation of the specific writer for special options,

0 commit comments

Comments
 (0)