This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # vim: noet nowrap number ts=4 | |
| import barcode | |
| #import bytes_as_braille as bab | |
| def mkBar( byte_content, ASCII = True ): | |
| decode_as_int = False | |
| if ASCII: | |
| try: | |
| string_content = byte_content.decode('ascii') | |
| except ValueError: | |
| decode_as_int = True | |
| else: | |
| decode_as_int = True | |
| if decode_as_int: | |
| 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')) | |
| def mkBar( byte_content, ASCII = True ): | |
| string_content = None | |
| if ASCII: | |
| try: | |
| string_content = byte_content.decode('ascii') | |
| except ValueError: | |
| pass | |
| if string_content is None: | |
| 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')) | |
| mkBar(b'123456789') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment