Skip to content

Commit e6d1a3e

Browse files
author
Hugo Osvaldo Barrera
authored
Merge pull request #37 from MDziwny/master
add support for gs1-128
2 parents 0b23701 + 554c8a6 commit e6d1a3e

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

barcode/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"""
1313

1414
from barcode.errors import BarcodeNotFoundError
15-
from barcode.codex import Code39, PZN, Code128
15+
from barcode.codex import Code39, PZN, Code128, Gs1_128
1616
from barcode.ean import EAN8, EAN13, EAN14, JAN
1717
from barcode.isxn import ISBN10, ISBN13, ISSN
1818
from barcode.upc import UPCA
@@ -43,6 +43,7 @@
4343
pzn=PZN,
4444
code128=Code128,
4545
itf=ITF,
46+
gs1_128=Gs1_128,
4647
)
4748

4849
PROVIDED_BARCODES = list(__BARCODE_MAP)

barcode/codex.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,25 @@ def render(self, writer_options=None, text=None):
258258
return Barcode.render(self, options, text)
259259

260260

261+
class Gs1_128(Code128):
262+
"""
263+
following the norm, a gs1-128 barcode is a subset of code 128 barcode,
264+
it can be generated by prepending the code with the FNC1 character
265+
https://en.wikipedia.org/wiki/GS1-128
266+
https://www.gs1-128.info/
267+
"""
268+
269+
name = 'GS1-128'
270+
271+
FNC1_CHAR = '\xf1'
272+
273+
def __init__(self, code, writer=None):
274+
code = self.FNC1_CHAR + code
275+
super(Gs1_128, self).__init__(code, writer)
276+
277+
def get_fullcode(self):
278+
return super(Gs1_128, self).get_fullcode()[1:]
279+
280+
261281
# For pre 0.8 compatibility
262282
PZN = PZN7

test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ def test_isbn13(self):
149149
isbn = get_barcode('isbn13', '978376926085')
150150
self.assertEqual('9783769260854', isbn.get_fullcode())
151151

152+
def test_gs1_128(self):
153+
gs1_128 = get_barcode('gs1_128', '00376401856400470087')
154+
self.assertEqual('00376401856400470087', gs1_128.get_fullcode())
155+
152156

153157
if __name__ == '__main__':
154158
test()

0 commit comments

Comments
 (0)