| #!/usr/bin/python
|
| # vim: noet nowrap number ts=4
|
|
|
| import barcode
|
| #import bytes_as_braille as bab
|
|
|
| def mkBar( byte_content, ASCII = True ):
|
| if not ASCII:
|
| string_content = str(int.from_bytes(byte_content,'big'))
|
| else:
|
| try:
|
| try:
|
| int(byte_content)
|
| raise UnicodeDecodeError
|
| except ValueError:
|
| string_content = byte_content.decode('ascii')
|
| except UnicodeDecodeError:
|
| string_content = str(int.from_bytes(byte_content,'big'))
|
| print(string_content)
|
| b = barcode.Code128( string_content )
|
| b.write(open('/tmp/barcode.svg','wb'), text = byte_content.decode('utf-8'))
|
|
|
|
|
| if __name__ == '__main__':
|
| #while True:
|
| # #mkBar( bab.input() )
|
| # mkBar( input('> ').encode('utf-8') )
|
|
|
| # works as expected
|
| mkBar(b'abcdefg')
|
| mkBar('abcdéfg'.encode('utf-8'))
|
| # works not ?!?
|
| mkBar(b'123456789')
|