def __init__(self, ean, writer=None): ean = ean[:self.digits] if not ean.isdigit(): raise IllegalCharacterError('Code can only contain numbers.') self.ean = ean self.ean = '{0}{1}'.format(ean, self.calculate_checksum()) self.writer = writer or Barcode.default_writer()
def __init__(self, code, writer=None, narrow=2, wide=5): if not code.isdigit(): raise IllegalCharacterError('ITF code can only contain numbers.') #Length must be even, prepend 0 if necessary if len(code) % 2 != 0: code = '0' + code self.code = code self.writer = writer or Barcode.default_writer() self.narrow = narrow self.wide = wide
def __init__(self, ean, writer=None): ean = ean[:self.digits] if not ean.isdigit(): raise IllegalCharacterError('EAN code can only contain numbers.') if len(ean) != self.digits: raise NumberOfDigitsError('EAN must have {0} digits, not ' '{1}.'.format(self.digits, len(ean))) self.ean = ean self.ean = '{0}{1}'.format(ean, self.calculate_checksum()) self.writer = writer or Barcode.default_writer()
def render(self, writer_options): options = dict(module_width=MIN_SIZE / self.narrow, quiet_zone=MIN_QUIET_ZONE) options.update(writer_options or {}) return Barcode.render(self, options)
def __init__(self, code, writer=None): self.code = code self.writer = writer or Barcode.default_writer() self._charset = 'B' self._buffer = '' check_code(self.code, self.name, code128.ALL)
def __init__(self, code, writer=None, add_checksum=True): 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, REF)
def render(self, writer_options=None): options = dict(module_width=SIZES['SC2']) options.update(writer_options or {}) return Barcode.render(self, options)
def barcode(codetype, codestring, options=None, **kw): """ >>> barcode('nonexistent', '977147396801') Traceback (most recent call last): ... ValueError: No renderer for codetype nonexistent >>> barcode('qrcode', 'Hello Barcode Writer In Pure PostScript.', ... options=dict(version=9, eclevel='M'), margin=10, data_mode='8bits') # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('code128', '^104^102Count^0990123456789^101!', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('pdf417', '^453^178^121^239', ... options=dict(columns=2, rows=10), margin=1, scale=2) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('upca', '78858101497', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> barcode('upce', '0123456', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('royalmail', 'LE28HS9Z', ... options=dict(includetext=False), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('datamatrix', '^142^164^186', ... options=dict(columns=32, rows=32), margin=1, scale=2.0) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('code11', '0123456789', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('code25', '0123456789', ... options=dict(includetext=False, includecheck=False), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('code39', 'THIS IS CODE39', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('code93', 'THIS IS CODE93', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('japanpost', '1231FZ13XHS', ... options=dict(includetext=False), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('azteccode', '00100111001000000101001101111000010100111100101000000110', ... margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('auspost', '5956439111ABA 9', ... options=dict(includetext=False), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('ean13', '977147396801', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('interleaved2of5', '24012345678905', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('raw', '331132131313411122131311333213114131131221323', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('kix', '1231FZ13XHS', ... options=dict(includetext=False), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('postnet', '012345', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('pharmacode', '117480', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('plessey', '012345ABCD', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('symbol', 'fimd', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('onecode', '0123456709498765432101234567891', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('maxicode', '^059^042^041^059^040^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291^0471^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^030^062^004^063', ... options=dict(mode=2), margin=1, scale=4) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('msi', '0123456789', ... options=dict(includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('rss14', '24012345678905', ... options=dict(linkage=True, includetext=True), scale=2, margin=1) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('rationalizedCodabar', 'A0123456789B', ... options=dict(includetext=True, includecheck=True), scale=2, margin=10) # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() """ # search for codetype registry renderer = Barcode.resolve_codetype(codetype) if renderer: return renderer().render(codestring, options=options, **kw) raise ValueError(u'No renderer for codetype %s' %codetype)
'elaphe.japanpost', 'elaphe.msi', 'elaphe.plessey', 'elaphe.raw', 'elaphe.symbol', 'elaphe.pdf417', 'elaphe.datamatrix', 'elaphe.qrcode', 'elaphe.maxicode', 'elaphe.azteccode'] if __name__=="__main__": DEFAULT_PLUGINS = [s.replace('elaphe.', '') for s in DEFAULT_PLUGINS] def load_plugins(): for PL in DEFAULT_PLUGINS: try: __import__(PL, fromlist=[PL]) except ImportError, e: import sys sys.stdout.write(u'Warning: %s\n' %e) Barcode.update_codetype_registry() load_plugins() def barcode(codetype, codestring, options=None, **kw): """ >>> barcode('nonexistent', '977147396801') Traceback (most recent call last): ... ValueError: No renderer for codetype nonexistent >>> barcode('qrcode', 'Hello Barcode Writer In Pure PostScript.', ... options=dict(version=9, eclevel='M'), margin=10, data_mode='8bits') # doctest: +ELLIPSIS <PIL.EpsImagePlugin.EpsImageFile ...> >>> # _.show() >>> barcode('code128', '^104^102Count^0990123456789^101!',