Simplified code by removing support for Python 2, leaving only support for Python 3.

This commit is contained in:
Project Nayuki 2020-04-24 17:40:17 +00:00
parent 71c75cfeb0
commit f93ce5217e
5 changed files with 27 additions and 36 deletions

View File

@ -1,5 +1,5 @@
#
# QR Code generator batch test (Python 3)
# QR Code generator batch test (Python)
#
# Runs various versions of the QR Code generator test worker as subprocesses,
# feeds each one the same random input, and compares their output for equality.
@ -25,13 +25,10 @@
#
import itertools, random, subprocess, sys, time
if sys.version_info.major < 3:
raise RuntimeError("Requires Python 3+")
CHILD_PROGRAMS = [
["python2", "-B", "../python/qrcodegen-worker.py"], # Python 2 program
["python3", "-B", "../python/qrcodegen-worker.py"], # Python 3 program
["python3", "-B", "../python/qrcodegen-worker.py"], # Python program
["java", "-cp", "../java/src/main/java", "-ea:io.nayuki.qrcodegen...", "io/nayuki/qrcodegen/QrCodeGeneratorWorker"], # Java program
["node", "../typescript-javascript/qrcodegen-worker.js"], # TypeScript program
["../c/qrcodegen-worker"], # C program

View File

@ -1,5 +1,5 @@
#
# QR Code generator demo (Python 2, 3)
# QR Code generator demo (Python)
#
# Run this command-line program with no arguments. The program computes a bunch of demonstration
# QR Codes and prints them to the console. Also, the SVG code for one QR Code is printed as a sample.
@ -24,7 +24,6 @@
# Software.
#
from __future__ import print_function
from qrcodegen import QrCode, QrSegment
@ -41,7 +40,7 @@ def main():
def do_basic_demo():
"""Creates a single QR Code, then prints it to the console."""
text = u"Hello, world!" # User-supplied Unicode text
text = "Hello, world!" # User-supplied Unicode text
errcorlvl = QrCode.Ecc.LOW # Error correction level
# Make and print the QR Code symbol
@ -62,7 +61,7 @@ def do_variety_demo():
print_qr(qr)
# Unicode text as UTF-8
qr = QrCode.encode_text(u"\u3053\u3093\u306B\u3061\u0077\u0061\u3001\u4E16\u754C\uFF01\u0020\u03B1\u03B2\u03B3\u03B4", QrCode.Ecc.QUARTILE)
qr = QrCode.encode_text("\u3053\u3093\u306B\u3061\u0077\u0061\u3001\u4E16\u754C\uFF01\u0020\u03B1\u03B2\u03B3\u03B4", QrCode.Ecc.QUARTILE)
print_qr(qr)
# Moderately large QR Code using longer text (from Lewis Carroll's Alice in Wonderland)
@ -93,9 +92,9 @@ def do_segment_demo():
print_qr(qr)
# Illustration "golden"
golden0 = u"Golden ratio \u03C6 = 1."
golden1 = u"6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374"
golden2 = u"......"
golden0 = "Golden ratio \u03C6 = 1."
golden1 = "6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374"
golden2 = "......"
qr = QrCode.encode_text(golden0 + golden1 + golden2, QrCode.Ecc.LOW)
print_qr(qr)
@ -107,7 +106,7 @@ def do_segment_demo():
print_qr(qr)
# Illustration "Madoka": kanji, kana, Cyrillic, full-width Latin, Greek characters
madoka = u"\u300C\u9B54\u6CD5\u5C11\u5973\u307E\u3069\u304B\u2606\u30DE\u30AE\u30AB\u300D\u3063\u3066\u3001\u3000\u0418\u0410\u0418\u3000\uFF44\uFF45\uFF53\uFF55\u3000\u03BA\u03B1\uFF1F"
madoka = "\u300C\u9B54\u6CD5\u5C11\u5973\u307E\u3069\u304B\u2606\u30DE\u30AE\u30AB\u300D\u3063\u3066\u3001\u3000\u0418\u0410\u0418\u3000\uFF44\uFF45\uFF53\uFF55\u3000\u03BA\u03B1\uFF1F"
qr = QrCode.encode_text(madoka, QrCode.Ecc.LOW)
print_qr(qr)
@ -157,7 +156,7 @@ def do_mask_demo():
# Chinese text as UTF-8
segs = QrSegment.make_segments(
u"\u7DAD\u57FA\u767E\u79D1\uFF08\u0057\u0069\u006B\u0069\u0070\u0065\u0064\u0069\u0061\uFF0C"
"\u7DAD\u57FA\u767E\u79D1\uFF08\u0057\u0069\u006B\u0069\u0070\u0065\u0064\u0069\u0061\uFF0C"
"\u8046\u807D\u0069\u002F\u02CC\u0077\u026A\u006B\u1D7B\u02C8\u0070\u0069\u02D0\u0064\u0069"
"\u002E\u0259\u002F\uFF09\u662F\u4E00\u500B\u81EA\u7531\u5167\u5BB9\u3001\u516C\u958B\u7DE8"
"\u8F2F\u4E14\u591A\u8A9E\u8A00\u7684\u7DB2\u8DEF\u767E\u79D1\u5168\u66F8\u5354\u4F5C\u8A08"
@ -176,7 +175,7 @@ def print_qr(qrcode):
border = 4
for y in range(-border, qrcode.get_size() + border):
for x in range(-border, qrcode.get_size() + border):
print(u"\u2588 "[1 if qrcode.get_module(x,y) else 0] * 2, end="")
print("\u2588 "[1 if qrcode.get_module(x,y) else 0] * 2, end="")
print()
print()

View File

@ -1,5 +1,5 @@
#
# QR Code generator test worker (Python 2, 3)
# QR Code generator test worker (Python)
#
# This program reads data and encoding parameters from standard input and writes
# QR Code bitmaps to standard output. The I/O format is one integer per line.
@ -28,11 +28,10 @@
import sys
import qrcodegen
py3 = sys.version_info.major >= 3
def read_int():
return int((input if py3 else raw_input)())
return int(input())
def main():

View File

@ -1,5 +1,5 @@
#
# QR Code generator library (Python 2, 3)
# QR Code generator library (Python)
#
# Copyright (c) Project Nayuki. (MIT License)
# https://www.nayuki.io/page/qr-code-generator-library
@ -21,7 +21,7 @@
# Software.
#
import collections, itertools, re, sys
import collections, itertools, re
"""
@ -60,7 +60,7 @@ This module "qrcodegen", public members:
# ---- QR Code symbol class ----
class QrCode(object):
class QrCode:
"""A QR Code symbol, which is a type of two-dimension barcode.
Invented by Denso Wave and described in the ISO/IEC 18004 standard.
Instances of this class represent an immutable square grid of black and white cells.
@ -678,7 +678,7 @@ class QrCode(object):
# ---- Public helper enumeration ----
class Ecc(object):
class Ecc:
"""The error correction level in a QR Code symbol. Immutable."""
# Private constructor
def __init__(self, i, fb):
@ -695,7 +695,7 @@ class QrCode(object):
# ---- Data segment class ----
class QrSegment(object):
class QrSegment:
"""A segment of character/binary/control data in a QR Code symbol.
Instances of this class are immutable.
The mid-level way to create a segment is to take the payload data
@ -713,11 +713,8 @@ class QrSegment(object):
"""Returns a segment representing the given binary data encoded in byte mode.
All input byte lists are acceptable. Any text string can be converted to
UTF-8 bytes (s.encode("UTF-8")) and encoded as a byte mode segment."""
py3 = sys.version_info.major >= 3
if (py3 and isinstance(data, str)) or (not py3 and isinstance(data, unicode)):
if isinstance(data, str):
raise TypeError("Byte string/list expected")
if not py3 and isinstance(data, str):
data = bytearray(data)
bb = _BitBuffer()
for b in data:
bb.append_bits(b, 8)
@ -759,7 +756,7 @@ class QrSegment(object):
def make_segments(text):
"""Returns a new mutable list of zero or more segments to represent the given Unicode text string.
The result may use various segment modes and switch modes to optimize the length of the bit stream."""
if not (isinstance(text, str) or (sys.version_info.major < 3 and isinstance(text, unicode))):
if not isinstance(text, str):
raise TypeError("Text string expected")
# Select the most efficient segment encoding automatically
@ -867,7 +864,7 @@ class QrSegment(object):
# ---- Public helper enumeration ----
class Mode(object):
class Mode:
"""Describes how a segment's data bits are interpreted. Immutable."""
# Private constructor

View File

@ -1,5 +1,5 @@
#
# QR Code generator Distutils script (Python 2, 3)
# QR Code generator Distutils script (Python)
#
# Copyright (c) Project Nayuki. (MIT License)
# https://www.nayuki.io/page/qr-code-generator-library
@ -26,7 +26,7 @@ import setuptools
setuptools.setup(
name = "qrcodegen",
description = "High quality QR Code generator library for Python 2 and 3",
description = "High quality QR Code generator library for Python",
version = "1.6.0",
platforms = "OS Independent",
license = "MIT License",
@ -42,7 +42,6 @@ setuptools.setup(
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Topic :: Multimedia :: Graphics",
"Topic :: Software Development :: Libraries :: Python Modules",