Skip to content

Commit

Permalink
delet argument picture_exist and add str checking
Browse files Browse the repository at this point in the history
  • Loading branch information
x-hw committed Sep 5, 2016
1 parent cb87de0 commit 99d98b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion mylibs/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def analyse(ver, ecl, str):
mode = 'numeric'
elif all(i in alphanum_list for i in str):
mode = 'alphanumeric'
elif all(ord(i.encode('iso-8859-1')) for i in str):
else:
mode = 'byte'

m = mindex[mode]
Expand Down
3 changes: 2 additions & 1 deletion mylibs/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from PIL import Image
import os

def draw_qrcode(abspath, qrmatrix, unit_len):
def draw_qrcode(abspath, qrmatrix):
unit_len = 3
x = y = 4*unit_len
pic = Image.new('1', [(len(qrmatrix)+8)*unit_len]*2, 'white')

Expand Down
40 changes: 20 additions & 20 deletions mylibs/theqrmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

from mylibs import data, ECC, structure, matrix, draw

supported_chars = r'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ·,.:;+-*/\~!@#$%^&`[]()?_{}|'

# ver: Version (from 1 to 40)
# ecl: Error Correction Level (L,M,Q,H)
def get_qrcode(ver, ecl, str, save_place, pic_exits = False):
# get a qrcode picture of 3*3 pixels per module
def get_qrcode(ver, ecl, str, save_place):
# ver == 0: default that is depending on str and ecl
if ver not in range(41):
print('Version Error: please choose a version from 1 to 40!')
print('WARNING: Version Error! Please choose a version from 1 to 40!')
if ecl not in 'LMQH':
print('Level Error: please choose one of L,M,Q,H!')
print('WARNING: Level Error! Please choose one of L,M,Q,H!')
if any(i not in supported_chars for i in str):
print('WARNING: Input Error! Please read the README file for the supported characters!!')
else:
try:
# Data Coding
ver, data_codewords = data.encode(ver, ecl, str)
# Data Coding
ver, data_codewords = data.encode(ver, ecl, str)

# Error Correction Coding
ecc = ECC.encode(ver, ecl, data_codewords)

# Structure final bits
final_bits = structure.structure_final_bits(ver, ecl, data_codewords, ecc)

# Get the QR Matrix
qrmatrix = matrix.get_qrmatrix(ver, ecl, final_bits)

# Draw the picture and Save it, then return the absolute path
unit_len = 3 if pic_exits else 9
return ver, draw.draw_qrcode(save_place, qrmatrix, unit_len)
# Error Correction Coding
ecc = ECC.encode(ver, ecl, data_codewords)

# Structure final bits
final_bits = structure.structure_final_bits(ver, ecl, data_codewords, ecc)

# Get the QR Matrix
qrmatrix = matrix.get_qrmatrix(ver, ecl, final_bits)

except UnicodeEncodeError:
print('Input Error: please read the README file for the supported characters!!')
# Draw the picture and Save it, then return the absolute path
return ver, draw.draw_qrcode(save_place, qrmatrix)

0 comments on commit 99d98b2

Please sign in to comment.