Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python 3 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions python_pragmatic/strings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import hashlib
import random
import unicodedata
Expand All @@ -19,8 +20,8 @@ def barcode(code, args=None):
options[key] = int(value)

import barcode
from StringIO import StringIO
from thirdparty import BarcodeImageWriter
from io import BytesIO
from .thirdparty import BarcodeImageWriter
CODETYPE = 'code39'
bc = barcode.get_barcode(CODETYPE)
bc = bc(code, writer=BarcodeImageWriter(), add_checksum=False)
Expand All @@ -35,15 +36,16 @@ def barcode(code, args=None):
bc.default_writer_options.update(options)

#write PNG image
output = StringIO()
output = BytesIO()
bc.write(output)
contents = output.getvalue().encode("base64")
contents = output.getvalue()
output.close()

#return encoded base64
return str(contents)
content = base64.b64encode(contents)

return content.decode('utf8')


def remove_accents(input):
""" Normalise (normalize) unicode string to remove umlauts, accents etc. """
return unicodedata.normalize('NFKD', unicode(input)).encode('ASCII', 'ignore')
return unicodedata.normalize('NFKD', u''.__class__(input)).encode('ASCII', 'ignore')