Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PIL>= 1.1.7
Pillow>= 1.1.7
reportlab>=2.5
CairoSVG>=0.4.4
zbar>=0.10
pyzbar>=0.1.8
4 changes: 2 additions & 2 deletions qrlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
OuterEyeStyleMissing, InvalidSize,
InvalidLanguage, InvalidEcLevel)

except ImportError, e:
print e
except ImportError as e:
print(e)
# import sys
# sys.stderr.write("Error: Can't find the file 'config.py' in the directory containing %r." % __file__)
sys.exit(1)
8 changes: 4 additions & 4 deletions qrlib/lib/pyqrcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ def MakeQR(data, minTypeNumber = 0, errorCorrectLevel = QRErrorCorrectLevel.Q, v

minTypeNumber = int(minTypeNumber)

for x in xrange(0, 50):
for x in range(0, 50):
try:
qr = QRCode(minTypeNumber + x, errorCorrectLevel)
qr.addData(data)
qr.make()

return qr
except CodeLengthOverflowError, x:
except CodeLengthOverflowError as x:
if VERBOSE:
print >> sys.stderr, "QRCode.Make - bad guess - trying again", x

Expand Down Expand Up @@ -1036,7 +1036,7 @@ def getRSBlocks(typeNumber, errorCorrectLevel):
if rsBlock == None:
raise Exception("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel)

length = len(rsBlock) / 3
length = int(len(rsBlock) / 3)

list = []

Expand Down Expand Up @@ -1073,7 +1073,7 @@ def __repr__(self):
def get(self, index):
bufIndex = math.floor(index / 8)
val = ( (self.buffer[bufIndex] >> (7 - index % 8) ) & 1) == 1
print "get ", val
print("get ", val)
return ( (self.buffer[bufIndex] >> (7 - index % 8) ) & 1) == 1
def put(self, num, length):
for i in range(length):
Expand Down
14 changes: 7 additions & 7 deletions qrlib/qrlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
ec_level_validation, size_validation,
style_validation, inner_eye_style_validation,
outer_eye_style_validation)
import cStringIO
import Image
import io
from PIL import Image
# Monkey patch ReportLab
# http://stackoverflow.com/questions/2227493/\
# reportlab-and-python-imaging-library-images-from-memory-issue
Expand All @@ -32,7 +32,7 @@ def _gen_pdf(qr_pil, instructions=True, bg_color='#FFFFFF', frame=True,
in a filelike (StringIO)
"""
(qr_width, qr_height) = qr_pil.size # qr_width == qr_height, always
filelike = cStringIO.StringIO()
filelike = io.BytesIO()
page_size = landscape(A4)
page_width, page_height = page_size
qr_canvas = canvas.Canvas(filelike, pagesize=page_size)
Expand Down Expand Up @@ -108,7 +108,7 @@ def _generate_pil(text, size='100', ec_level='L', style='default',
outer_eye_style=outer_eye_style,
outer_eye_color=outer_eye_color,
bg_color=bg_color)
converted_file = cStringIO.StringIO()
converted_file = io.BytesIO()
cairosvg.svg2png(generated_svg.getvalue(),
write_to=converted_file)
converted_file.seek(0)
Expand Down Expand Up @@ -147,7 +147,7 @@ def _gen_filelike(text, language='es', size=150, ec_level='L', qr_format='PDF',
return _gen_pdf(pil, instructions=instructions, bg_color=bg_color,
put_logo=True)
if qr_format in ['GIF', 'JPEG', 'PNG']:
filelike = cStringIO.StringIO()
filelike = io.BytesIO()
pil.save(filelike, qr_format)
return filelike
else:
Expand Down Expand Up @@ -210,7 +210,7 @@ def generate_qr_file(text, language='es', qr_format='PDF', app='interior',
format_validation(qr_format)
application_validation(app)
appsize_validation(app_size)
except Exception, e:
except Exception as e:
raise e

ec_level = None
Expand Down Expand Up @@ -316,7 +316,7 @@ def generate_custom_qr_file(text, language='es', qr_format='PDF', size=150,
style_validation(style)
inner_eye_style_validation(inner_eye_style)
outer_eye_style_validation(outer_eye_style)
except Exception, e:
except Exception as e:
raise e

if qr_format == 'PDF' and size > EXTERIOR_LARGE['size']:
Expand Down
10 changes: 5 additions & 5 deletions qrlib/qrsvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from os.path import join
import re
import cStringIO
import io
import copy


Expand Down Expand Up @@ -552,10 +552,10 @@ def _qrcode_to_svg(qrcode, style='default', style_color='#000000',
style_dict=style_dict, color=style_color,
block_scale=block_scale)

filelike = cStringIO.StringIO()
filelike.write('<?xml version=\"1.0\" standalone=\"no\"?>\n')
filelike.write('<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n')
filelike.write('\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n')
filelike = io.BytesIO()
filelike.write(str.encode('<?xml version=\"1.0\" standalone=\"no\"?>\n'))
filelike.write(str.encode('<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n'))
filelike.write(str.encode('\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n'))
filelike.write(et.tostring(svg_doc))
return filelike

Expand Down
12 changes: 6 additions & 6 deletions qrlib/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def _check_style(style_dir, style):
if not isinstance(style, (str, unicode)):
if not isinstance(style, (bytes, str)):
raise AttributeError('style must be str or unicode')
style = style.lower()
directory = join(style_dir, style)
Expand Down Expand Up @@ -56,36 +56,36 @@ def logo_margin_validation(margin):


def ec_level_validation(ec_level):
if not isinstance(ec_level, (unicode, str)) or \
if not isinstance(ec_level, (str, bytes)) or \
ec_level.upper() not in ('L', 'M', 'Q', 'H'):
raise InvalidEcLevel('Unrecognized QR error correction'
'level "%s"' % str(ec_level))
return True


def format_validation(qr_format):
if not isinstance(qr_format, (unicode, str)) or \
if not isinstance(qr_format, (str, bytes)) or \
qr_format.upper() not in ('SVG', 'PDF', 'GIF', 'PNG', 'JPEG'):
raise Exception('Unrecognized QR output format')
return True


def application_validation(application):
if not isinstance(application, (unicode, str)) or \
if not isinstance(application, (str, bytes)) or \
application.lower() not in ('interior', 'exterior'):
raise InvalidApplication('Unrecognized QR application')
return True


def appsize_validation(app_size):
if not isinstance(app_size, (unicode, str)) or \
if not isinstance(app_size, (str, bytes)) or \
app_size.lower() not in ('small', 'medium', 'large'):
raise InvalidAppSize('Unrecognized QR application size')
return True


def language_validation(language):
if not isinstance(language, (unicode, str)) or \
if not isinstance(language, (str, bytes)) or \
language.lower() not in ('es', 'en', 'br'):
raise InvalidLanguage('Unrecognized QR footer language')
return True
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def read(fname):
'static/styles/heavyround/*',
'static/styles/lightround/*',
'static/styles/sieve/*']},
install_requires=['PIL>=1.1.7', 'unittest2>=0.5.1', 'zbar>=0.10',
install_requires=['Pillow>=1.1.7', 'unittest2>=0.5.1', 'pyzbar>=0.1.8',
'CairoSVG>=0.4.4']
)