Skip to content

Commit d2b579e

Browse files
author
Thorsten Weimann
committed
Merged in lasley/python-barcode/feature/ean14 (pull request #11)
Feature/ean14
2 parents 0eb30d4 + 6f86694 commit d2b579e

5 files changed

Lines changed: 36 additions & 16 deletions

File tree

.hgsigs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
48436ba963f08285ddde3a0c91c27703e2143ebc 0 iQIcBAABCgAGBQJYd7+CAAoJEH3bpLqBuTTPC+UP/0/uJyy0llXpif0nRt3yIy9u+gl+6t8UdO6miPtvWzMHVRgGfgb/tip5MGWxiwR3aPyqnqSZ9m4+W62jIYUGs2pTHZPMK192yMNA8131NOUpugjAjxosigJsDH5NKFG7h9spWjggaBYD80jt2Vbr2YM/xtGWC1hQ3lfLchMXFNs3zjVGcAnA57Vy1uPHTZx0ETkc3vZocRqvrWReU1nZ14i1r6rH2lZIKRQ4kMEpEYYxL9U/gwAwJT/eAlZpr3FMR9FkiYXAdEK4sXxV989WGogPdI8MRAxAj6MA+rO4pdl0aAlQmO7rxePtgppI6d9qx7dm49cXwiroTMDhDpj8jNQoeBVJ+qzc+2o4+f5pdFJH3nGCDhDeiTsnQuAFBw+5B+T99VWODJQqlKgFnZxDuC/Mcg9DVt8O+yu9/+xy/x17ttt3d6yWNfSZ+kkKTLTpnLEWFKeDOYjXGZRu22hskV7sVy6T9gpI8rtShA7oUjOhIfhQ/DWGZphHFOnkBpsFul1Dj7hnAv0wNHlkRl0zkiq9byhHlFADL/TT3Pjuyc+lNScNWP3nC5WVKpepoSM30euYLEN3Ydg+1Tq1mLoM+f1geKiJ7+9tR/NfeoaPcz6FykcU6dYsKfFeo1Os+BK76O0DTSFV+xorzcHwtdQ6ADmQFq274kgDQ/CxqXlnhaEL

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The best way is to use pip: `pip install pyBarcode`.
3434
Provided Barcodes
3535
-----------------
3636

37-
EAN-8, EAN-13, UPC-A, JAN, ISBN-10, ISBN-13, ISSN, Code 39, Code 128, PZN
37+
EAN-8, EAN-13, EAN-14, UPC-A, JAN, ISBN-10, ISBN-13, ISSN, Code 39, Code 128, PZN
3838

3939

4040
Todo
@@ -147,4 +147,4 @@ Changelog
147147

148148
:v0.2: More tests added.
149149

150-
:v0.1: First release.
150+
:v0.1: First release.

barcode/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
from barcode.errors import BarcodeNotFoundError
3838
from barcode.codex import Code39, PZN, Code128
39-
from barcode.ean import EAN8, EAN13, JAN
39+
from barcode.ean import EAN8, EAN13, EAN14, JAN
4040
from barcode.isxn import ISBN10, ISBN13, ISSN
4141
from barcode.upc import UPCA
4242
from barcode.itf import ITF
@@ -51,7 +51,8 @@
5151
ean8=EAN8,
5252
ean13=EAN13,
5353
ean=EAN13,
54-
gtin=EAN13,
54+
gtin=EAN14,
55+
ean14=EAN14,
5556
jan=JAN,
5657
upc=UPCA,
5758
upca=UPCA,

barcode/ean.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
"""Module: barcode.ean
1010
11-
:Provided barcodes: EAN-13, EAN-8, JAN
11+
:Provided barcodes: EAN-14, EAN-13, EAN-8, JAN
1212
"""
1313
__docformat__ = 'restructuredtext en'
1414

@@ -149,17 +149,6 @@ class EuropeanArticleNumber8(EuropeanArticleNumber13):
149149
def __init__(self, ean, writer=None):
150150
EuropeanArticleNumber13.__init__(self, ean, writer)
151151

152-
def calculate_checksum(self):
153-
"""Calculates the checksum for EAN8-Code.
154-
155-
:returns: The checksum for `self.ean`.
156-
:rtype: Integer
157-
"""
158-
def sum_(x, y): return int(x) + int(y)
159-
evensum = reduce(sum_, self.ean[::2])
160-
oddsum = reduce(sum_, self.ean[1::2])
161-
return (10 - ((evensum * 3 + oddsum) % 10)) % 10
162-
163152
def build(self):
164153
"""Builds the barcode pattern from `self.ean`.
165154
@@ -176,7 +165,35 @@ def build(self):
176165
return [code]
177166

178167

168+
class EuropeanArticleNumber14(EuropeanArticleNumber13):
169+
"""Represents an EAN-14 barcode. See EAN13's __init__ for details.
170+
171+
:parameters:
172+
ean : String
173+
The ean number as string.
174+
writer : barcode.writer Instance
175+
The writer to render the barcode (default: SVGWriter).
176+
"""
177+
178+
name = 'EAN-14'
179+
digits = 13
180+
181+
def calculate_checksum(self):
182+
"""Calculates the checksum for EAN13-Code.
183+
184+
:returns: The checksum for `self.ean`.
185+
:rtype: Integer
186+
"""
187+
188+
def sum_(x, y): return int(x) + int(y)
189+
190+
evensum = reduce(sum_, self.ean[::2])
191+
oddsum = reduce(sum_, self.ean[1::2])
192+
return (10 - (((evensum * 3) + oddsum) % 10)) % 10
193+
194+
179195
# Shortcuts
196+
EAN14 = EuropeanArticleNumber14
180197
EAN13 = EuropeanArticleNumber13
181198
EAN8 = EuropeanArticleNumber8
182199
JAN = JapanArticleNumber

test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
TESTCODES = (
5151
('ean8', '40267708'),
5252
('ean13', '5901234123457'),
53+
('ean14', '12345678911230'),
5354
('upca', '36000291453'),
5455
('jan', '4901234567894'),
5556
('isbn10', '3-12-517154-7'),

0 commit comments

Comments
 (0)