Skip to content

Commit

Permalink
Merge pull request #37 from MDziwny/master
Browse files Browse the repository at this point in the history
add support for gs1-128
  • Loading branch information
Hugo Osvaldo Barrera authored May 24, 2019
2 parents 0b23701 + 554c8a6 commit e6d1a3e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion barcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

from barcode.errors import BarcodeNotFoundError
from barcode.codex import Code39, PZN, Code128
from barcode.codex import Code39, PZN, Code128, Gs1_128
from barcode.ean import EAN8, EAN13, EAN14, JAN
from barcode.isxn import ISBN10, ISBN13, ISSN
from barcode.upc import UPCA
Expand Down Expand Up @@ -43,6 +43,7 @@
pzn=PZN,
code128=Code128,
itf=ITF,
gs1_128=Gs1_128,
)

PROVIDED_BARCODES = list(__BARCODE_MAP)
Expand Down
20 changes: 20 additions & 0 deletions barcode/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,25 @@ def render(self, writer_options=None, text=None):
return Barcode.render(self, options, text)


class Gs1_128(Code128):
"""
following the norm, a gs1-128 barcode is a subset of code 128 barcode,
it can be generated by prepending the code with the FNC1 character
https://en.wikipedia.org/wiki/GS1-128
https://www.gs1-128.info/
"""

name = 'GS1-128'

FNC1_CHAR = '\xf1'

def __init__(self, code, writer=None):
code = self.FNC1_CHAR + code
super(Gs1_128, self).__init__(code, writer)

def get_fullcode(self):
return super(Gs1_128, self).get_fullcode()[1:]


# For pre 0.8 compatibility
PZN = PZN7
4 changes: 4 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ def test_isbn13(self):
isbn = get_barcode('isbn13', '978376926085')
self.assertEqual('9783769260854', isbn.get_fullcode())

def test_gs1_128(self):
gs1_128 = get_barcode('gs1_128', '00376401856400470087')
self.assertEqual('00376401856400470087', gs1_128.get_fullcode())


if __name__ == '__main__':
test()
Expand Down

0 comments on commit e6d1a3e

Please sign in to comment.