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

python3 下支持 中文和emoji #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
7 changes: 4 additions & 3 deletions MyQR/mylibs/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ def alphanumeric_encoding(str):
return code

def byte_encoding(str):
str = bytes(str, encoding="utf8")
code = ''
for i in str:
c = bin(ord(i.encode('iso-8859-1')))[2:]
c = bin(i)[2:]
c = '0'*(8-len(c)) + c
code += c
return code
Expand All @@ -108,11 +109,11 @@ def get_cci(ver, mode, str):
else:
cci_len = (14, 13, 16, 12)[mindex[mode]]

cci = bin(len(str))[2:]
cci = bin(len(bytes(str, encoding="utf8")))[2:]
cci = '0' * (cci_len - len(cci)) + cci
return cci

if __name__ == '__main__':
s = '123456789'
v, datacode = encode(1, 'H', s)
print(v, datacode)
print(v, datacode)
7 changes: 2 additions & 5 deletions MyQR/myqr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
# See [https://github.com/sylnsfar/qrcode] for more details!
def run(words, version=1, level='H', picture=None, colorized=False, contrast=1.0, brightness=1.0, save_name=None, save_dir=os.getcwd()):

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


# check every parameter
if not isinstance(words, str) or any(i not in supported_chars for i in words):
if not isinstance(words, str):
raise ValueError('Wrong words! Make sure the characters are supported!')
if not isinstance(version, int) or version not in range(1, 41):
raise ValueError('Wrong version! Please choose a int-type value from 1 to 40!')
Expand Down Expand Up @@ -129,4 +126,4 @@ def combine(ver, qr_name, bg_name, colorized, contrast, brightness, save_dir, sa
finally:
import shutil
if os.path.exists(tempdir):
shutil.rmtree(tempdir)
shutil.rmtree(tempdir)