[Python-modules-commits] [python-qrcode] 02/04: Imported Upstream version 5.3
Hugo Lefeuvre
hle at moszumanska.debian.org
Mon Aug 22 20:53:44 UTC 2016
This is an automated email from the git hooks/post-receive script.
hle pushed a commit to branch master
in repository python-qrcode.
commit cf68d7ef4f052cc1271dbaea8ec33f5c5ebb2384
Author: Hugo Lefeuvre <hle at debian.org>
Date: Mon Aug 22 21:18:55 2016 +0200
Imported Upstream version 5.3
---
CHANGES.rst | 55 +++++++
PACKAGING.rst | 25 +++
PKG-INFO | 233 ++++++++++++++++++++++++++-
doc/qr.1 | 11 +-
qrcode.egg-info/PKG-INFO | 233 ++++++++++++++++++++++++++-
qrcode.egg-info/SOURCES.txt | 14 +-
qrcode.egg-info/entry_points.txt | 3 +
qrcode.egg-info/pbr.json | 1 +
qrcode.egg-info/requires.txt | 2 +-
qrcode/__init__.py | 12 +-
qrcode/base.py | 14 +-
scripts/qr => qrcode/console_scripts.py | 46 +++++-
qrcode/image/base.py | 8 +-
qrcode/image/pil.py | 31 +++-
qrcode/main.py | 38 +++--
qrcode/mecard.py | 33 ----
qrcode/speedy.py | 8 -
qrcode/tests.py | 126 ---------------
qrcode/tests/__init__.py | 0
qrcode/tests/svg.py | 5 +
qrcode/tests/test_example.py | 18 +++
qrcode/tests/test_qrcode.py | 272 ++++++++++++++++++++++++++++++++
qrcode/tests/test_script.py | 64 ++++++++
qrcode/util.py | 32 ++--
setup.cfg | 3 +
setup.py | 41 ++++-
26 files changed, 1094 insertions(+), 234 deletions(-)
diff --git a/CHANGES.rst b/CHANGES.rst
index 645dd95..310b7f4 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -2,6 +2,58 @@
Change log
==========
+Version 5.3
+===========
+
+* Fix incomplete block table for QR version 15. Thanks Rodrigo Queiro for the
+ report and Jacob Welsh for the investigation and fix.
+
+* Avoid unnecessary dependency for non MS platforms, thanks to Noah Vesely.
+
+* Make ``BaseImage.get_image()`` actually work.
+
+
+Version 5.2
+===========
+
+* Add ``--error-correction`` option to qr script.
+
+* Fix script piping to stdout in Python 3 and reading non-UTF-8 characters in
+ Python 3.
+
+* Fix script piping in Windows.
+
+* Add some useful behind-the-curtain methods for tinkerers.
+
+* Fix terminal output when using Python 2.6
+
+* Fix terminal output to display correctly on MS command line.
+
+Version 5.2.1
+-------------
+
+* Small fix to terminal output in Python 3 (and fix tests)
+
+Version 5.2.2
+-------------
+
+* Revert some terminal changes from 5.2 that broke Python 3's real life tty
+ code generation and introduce a better way from Jacob Welsh.
+
+
+Version 5.1
+===========
+
+* Make ``qr`` script work in Windows. Thanks Ionel Cristian Mărieș
+
+* Fixed print_ascii function in Python 3.
+
+* Out-of-bounds code version numbers are handled more consistently with a
+ ValueError.
+
+* Much better test coverage (now only officially supporting Python 2.6+)
+
+
Version 5.0
===========
@@ -14,6 +66,9 @@ Version 5.0
* Substation speed optimizations to best-fit algorithm (thanks Jacob Welsh!).
+* Introduce a ``print_ascii`` method and use it as the default for the ``qr``
+ script rather than ``print_tty``.
+
Version 5.0.1
-------------
diff --git a/PACKAGING.rst b/PACKAGING.rst
new file mode 100644
index 0000000..4cb787c
--- /dev/null
+++ b/PACKAGING.rst
@@ -0,0 +1,25 @@
+Packaging quick reminder
+========================
+
+Ensure version numbers in ``setup.py`` and ``doc/qr.1`` have been updated.
+
+1. Check twine and wheel are up to date::
+
+ pip install --upgrade twine wheel
+
+2. Delete contents of ``dist/``::
+
+ rm -r dist
+
+3. Package it up::
+
+ python setup.py sdist bdist_wheel
+
+4. Sign it::
+
+ gpg --detach-sign -a dist/*.gz
+ gpg --detach-sign -a dist/*.whl
+
+5. Upload it::
+
+ twine upload dist/*
diff --git a/PKG-INFO b/PKG-INFO
index 279b81c..53ea657 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: qrcode
-Version: 5.0.1
+Version: 5.3
Summary: QR Code image generator
Home-page: https://github.com/lincolnloop/python-qrcode
Author: Lincoln Loop
@@ -148,15 +148,244 @@ Description: =============================
from qrcode.image.pure import PymagingImage
img = qrcode.make('Some data here', image_factory=PymagingImage)
+
+ ==========
+ Change log
+ ==========
+
+ Version 5.3
+ ===========
+
+ * Fix incomplete block table for QR version 15. Thanks Rodrigo Queiro for the
+ report and Jacob Welsh for the investigation and fix.
+
+ * Avoid unnecessary dependency for non MS platforms, thanks to Noah Vesely.
+
+ * Make ``BaseImage.get_image()`` actually work.
+
+
+ Version 5.2
+ ===========
+
+ * Add ``--error-correction`` option to qr script.
+
+ * Fix script piping to stdout in Python 3 and reading non-UTF-8 characters in
+ Python 3.
+
+ * Fix script piping in Windows.
+
+ * Add some useful behind-the-curtain methods for tinkerers.
+
+ * Fix terminal output when using Python 2.6
+
+ * Fix terminal output to display correctly on MS command line.
+
+ Version 5.2.1
+ -------------
+
+ * Small fix to terminal output in Python 3 (and fix tests)
+
+ Version 5.2.2
+ -------------
+
+ * Revert some terminal changes from 5.2 that broke Python 3's real life tty
+ code generation and introduce a better way from Jacob Welsh.
+
+
+ Version 5.1
+ ===========
+
+ * Make ``qr`` script work in Windows. Thanks Ionel Cristian Mărieș
+
+ * Fixed print_ascii function in Python 3.
+
+ * Out-of-bounds code version numbers are handled more consistently with a
+ ValueError.
+
+ * Much better test coverage (now only officially supporting Python 2.6+)
+
+
+ Version 5.0
+ ===========
+
+ * Speed optimizations.
+
+ * Change the output when using the ``qr`` script to use ASCII rather than
+ just colors, better using the terminal real estate.
+
+ * Fix a bug in passing bytecode data directly when in Python 3.
+
+ * Substation speed optimizations to best-fit algorithm (thanks Jacob Welsh!).
+
+ * Introduce a ``print_ascii`` method and use it as the default for the ``qr``
+ script rather than ``print_tty``.
+
+ Version 5.0.1
+ -------------
+
+ * Update version numbers correctly.
+
+
+ Version 4.0
+ ===========
+
+ * Made qrcode work on Python 2.4 - Thanks tcely.
+ Note: officially, qrcode only supports 2.5+.
+
+ * Support pure-python PNG generation (via pymaging) for Python 2.6+ -- thanks
+ Adam Wisniewski!
+
+ * SVG image generation now supports alternate sizing (the default box size of
+ 10 == 1mm per rectangle).
+
+ * SVG path image generation allows cleaner SVG output by combining all QR rects
+ into a single path. Thank you, Viktor Stískala.
+
+ * Added some extra simple SVG factories that fill the background white.
+
+ Version 4.0.1
+ -------------
+
+ * Fix the pymaging backend not able to save the image to a buffer. Thanks ilj!
+
+ Version 4.0.2
+ -------------
+
+ * Fix incorrect regex causing a comma to be considered part of the alphanumeric
+ set.
+
+ * Switch to using setuptools for setup.py.
+
+ Version 4.0.3
+ -------------
+
+ * Fix bad QR code generation due to the regex comma fix in version 4.0.2.
+
+ Version 4.0.4
+ -------------
+
+ * Bad version number for previous hotfix release.
+
+
+ Version 3.1
+ ===========
+
+ * Important fixes for incorrect matches of the alpha-numeric encoding mode.
+ Previously, the pattern would match if a single line was alpha-numeric only
+ (even if others wern't). Also, the two characters ``{`` and ``}`` had snuck
+ in as valid characters. Thanks to Eran Tromer for the report and fix.
+
+ * Optimized chunking -- if the parts of the data stream can be encoded more
+ efficiently, the data will be split into chunks of the most efficient modes.
+
+ Version 3.1.1
+ -------------
+
+ * Update change log to contain version 3.1 changes. :P
+
+ * Give the ``qr`` script an ``--optimize`` argument to control the chunk
+ optimization setting.
+
+
+ Version 3.0
+ ===========
+
+ * Python 3 support.
+
+ * Add QRCode.get_matrix, an easy way to get the matrix array of a QR code
+ including the border. Thanks Hugh Rawlinson.
+
+ * Add in a workaround so that Python 2.6 users can use SVG generation (they
+ must install ``lxml``).
+
+ * Some initial tests! And tox support (``pip install tox``) for testing across
+ Python platforms.
+
+
+ Version 2.7
+ ===========
+
+ * Fix incorrect termination padding.
+
+
+ Version 2.6
+ ===========
+
+ * Fix the first four columns incorrectly shifted by one. Thanks to Josep
+ Gómez-Suay for the report and fix.
+
+ * Fix strings within 4 bits of the QR version limit being incorrectly
+ terminated. Thanks to zhjie231 for the report.
+
+
+ Version 2.5
+ ===========
+
+ * The PilImage wrapper is more transparent - you can use any methods or
+ attributes available to the underlying PIL Image instance.
+
+ * Fixed the first column of the QR Code coming up empty! Thanks to BecoKo.
+
+ Version 2.5.1
+ -------------
+
+ * Fix installation error on Windows.
+
+
+ Version 2.4
+ ===========
+
+ * Use a pluggable backend system for generating images, thanks to Branko Čibej!
+ Comes with PIL and SVG backends built in.
+
+ Version 2.4.1
+ -------------
+
+ * Fix a packaging issue
+
+ Version 2.4.2
+ -------------
+
+ * Added a ``show`` method to the PIL image wrapper so the ``run_example``
+ function actually works.
+
+
+ Version 2.3
+ ===========
+
+ * When adding data, auto-select the more efficient encoding methods for numbers
+ and alphanumeric data (KANJI still not supported).
+
+ Version 2.3.1
+ -------------
+
+ * Encode unicode to utf-8 bytestrings when adding data to a QRCode.
+
+
+ Version 2.2
+ ===========
+
+ * Fixed tty output to work on both white and black backgrounds.
+
+ * Added `border` parameter to allow customizing of the number of boxes used to
+ create the border of the QR code
+
+
+ Version 2.1
+ ===========
+
+ * Added a ``qr`` script which can be used to output a qr code to the tty using
+ background colors, or to a file via a pipe.
+
Platform: any
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/doc/qr.1 b/doc/qr.1
index c86cdc7..09ee816 100644
--- a/doc/qr.1
+++ b/doc/qr.1
@@ -1,9 +1,9 @@
.\" Manpage for qr
-.TH QR 1 "25 Jun 2013" "5.0" "Python QR tool"
+.TH QR 1 "25 Jun 2013" "5.3" "Python QR tool"
.SH NAME
qr \- script to create QR codes at the command line
.SH SYNOPSIS
-qr [\-\-help] [\-\-factory=FACTORY] [\-\-optimize=OPTIMIZE] [data]
+qr [\-\-help] [\-\-factory=FACTORY] [\-\-optimize=OPTIMIZE] [\-\-error\-correction=LEVEL] [data]
.SH DESCRIPTION
This script uses the python qrcode module. It can take data from stdin or from the commandline and generate a QR code.
Normally it will output the QR code as ascii art to the terminal. If the output is piped to a file, it will output the image (default type of PNG).
@@ -32,6 +32,13 @@ method. Use 0 to turn off chunk optimization.
.RE
.PP
+\fB\ \-\-error\-correction=LEVEL\fR
+.RS 4
+The error correction level to use. Choices are L (7%),
+M (15%, default), Q (25%), and H (30%).
+.RE
+
+.PP
\fB\ data\fR
.RS 4
The data from which the QR code will be generated.
diff --git a/qrcode.egg-info/PKG-INFO b/qrcode.egg-info/PKG-INFO
index 279b81c..53ea657 100644
--- a/qrcode.egg-info/PKG-INFO
+++ b/qrcode.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: qrcode
-Version: 5.0.1
+Version: 5.3
Summary: QR Code image generator
Home-page: https://github.com/lincolnloop/python-qrcode
Author: Lincoln Loop
@@ -148,15 +148,244 @@ Description: =============================
from qrcode.image.pure import PymagingImage
img = qrcode.make('Some data here', image_factory=PymagingImage)
+
+ ==========
+ Change log
+ ==========
+
+ Version 5.3
+ ===========
+
+ * Fix incomplete block table for QR version 15. Thanks Rodrigo Queiro for the
+ report and Jacob Welsh for the investigation and fix.
+
+ * Avoid unnecessary dependency for non MS platforms, thanks to Noah Vesely.
+
+ * Make ``BaseImage.get_image()`` actually work.
+
+
+ Version 5.2
+ ===========
+
+ * Add ``--error-correction`` option to qr script.
+
+ * Fix script piping to stdout in Python 3 and reading non-UTF-8 characters in
+ Python 3.
+
+ * Fix script piping in Windows.
+
+ * Add some useful behind-the-curtain methods for tinkerers.
+
+ * Fix terminal output when using Python 2.6
+
+ * Fix terminal output to display correctly on MS command line.
+
+ Version 5.2.1
+ -------------
+
+ * Small fix to terminal output in Python 3 (and fix tests)
+
+ Version 5.2.2
+ -------------
+
+ * Revert some terminal changes from 5.2 that broke Python 3's real life tty
+ code generation and introduce a better way from Jacob Welsh.
+
+
+ Version 5.1
+ ===========
+
+ * Make ``qr`` script work in Windows. Thanks Ionel Cristian Mărieș
+
+ * Fixed print_ascii function in Python 3.
+
+ * Out-of-bounds code version numbers are handled more consistently with a
+ ValueError.
+
+ * Much better test coverage (now only officially supporting Python 2.6+)
+
+
+ Version 5.0
+ ===========
+
+ * Speed optimizations.
+
+ * Change the output when using the ``qr`` script to use ASCII rather than
+ just colors, better using the terminal real estate.
+
+ * Fix a bug in passing bytecode data directly when in Python 3.
+
+ * Substation speed optimizations to best-fit algorithm (thanks Jacob Welsh!).
+
+ * Introduce a ``print_ascii`` method and use it as the default for the ``qr``
+ script rather than ``print_tty``.
+
+ Version 5.0.1
+ -------------
+
+ * Update version numbers correctly.
+
+
+ Version 4.0
+ ===========
+
+ * Made qrcode work on Python 2.4 - Thanks tcely.
+ Note: officially, qrcode only supports 2.5+.
+
+ * Support pure-python PNG generation (via pymaging) for Python 2.6+ -- thanks
+ Adam Wisniewski!
+
+ * SVG image generation now supports alternate sizing (the default box size of
+ 10 == 1mm per rectangle).
+
+ * SVG path image generation allows cleaner SVG output by combining all QR rects
+ into a single path. Thank you, Viktor Stískala.
+
+ * Added some extra simple SVG factories that fill the background white.
+
+ Version 4.0.1
+ -------------
+
+ * Fix the pymaging backend not able to save the image to a buffer. Thanks ilj!
+
+ Version 4.0.2
+ -------------
+
+ * Fix incorrect regex causing a comma to be considered part of the alphanumeric
+ set.
+
+ * Switch to using setuptools for setup.py.
+
+ Version 4.0.3
+ -------------
+
+ * Fix bad QR code generation due to the regex comma fix in version 4.0.2.
+
+ Version 4.0.4
+ -------------
+
+ * Bad version number for previous hotfix release.
+
+
+ Version 3.1
+ ===========
+
+ * Important fixes for incorrect matches of the alpha-numeric encoding mode.
+ Previously, the pattern would match if a single line was alpha-numeric only
+ (even if others wern't). Also, the two characters ``{`` and ``}`` had snuck
+ in as valid characters. Thanks to Eran Tromer for the report and fix.
+
+ * Optimized chunking -- if the parts of the data stream can be encoded more
+ efficiently, the data will be split into chunks of the most efficient modes.
+
+ Version 3.1.1
+ -------------
+
+ * Update change log to contain version 3.1 changes. :P
+
+ * Give the ``qr`` script an ``--optimize`` argument to control the chunk
+ optimization setting.
+
+
+ Version 3.0
+ ===========
+
+ * Python 3 support.
+
+ * Add QRCode.get_matrix, an easy way to get the matrix array of a QR code
+ including the border. Thanks Hugh Rawlinson.
+
+ * Add in a workaround so that Python 2.6 users can use SVG generation (they
+ must install ``lxml``).
+
+ * Some initial tests! And tox support (``pip install tox``) for testing across
+ Python platforms.
+
+
+ Version 2.7
+ ===========
+
+ * Fix incorrect termination padding.
+
+
+ Version 2.6
+ ===========
+
+ * Fix the first four columns incorrectly shifted by one. Thanks to Josep
+ Gómez-Suay for the report and fix.
+
+ * Fix strings within 4 bits of the QR version limit being incorrectly
+ terminated. Thanks to zhjie231 for the report.
+
+
+ Version 2.5
+ ===========
+
+ * The PilImage wrapper is more transparent - you can use any methods or
+ attributes available to the underlying PIL Image instance.
+
+ * Fixed the first column of the QR Code coming up empty! Thanks to BecoKo.
+
+ Version 2.5.1
+ -------------
+
+ * Fix installation error on Windows.
+
+
+ Version 2.4
+ ===========
+
+ * Use a pluggable backend system for generating images, thanks to Branko Čibej!
+ Comes with PIL and SVG backends built in.
+
+ Version 2.4.1
+ -------------
+
+ * Fix a packaging issue
+
+ Version 2.4.2
+ -------------
+
+ * Added a ``show`` method to the PIL image wrapper so the ``run_example``
+ function actually works.
+
+
+ Version 2.3
+ ===========
+
+ * When adding data, auto-select the more efficient encoding methods for numbers
+ and alphanumeric data (KANJI still not supported).
+
+ Version 2.3.1
+ -------------
+
+ * Encode unicode to utf-8 bytestrings when adding data to a QRCode.
+
+
+ Version 2.2
+ ===========
+
+ * Fixed tty output to work on both white and black backgrounds.
+
+ * Added `border` parameter to allow customizing of the number of boxes used to
+ create the border of the QR code
+
+
+ Version 2.1
+ ===========
+
+ * Added a ``qr`` script which can be used to output a qr code to the tty using
+ background colors, or to a file via a pipe.
+
Platform: any
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/qrcode.egg-info/SOURCES.txt b/qrcode.egg-info/SOURCES.txt
index 8683083..7ef26e4 100644
--- a/qrcode.egg-info/SOURCES.txt
+++ b/qrcode.egg-info/SOURCES.txt
@@ -1,22 +1,24 @@
CHANGES.rst
LICENSE
MANIFEST.in
+PACKAGING.rst
README.rst
TESTING.rst
+setup.cfg
setup.py
doc/qr.1
qrcode/__init__.py
qrcode/base.py
+qrcode/console_scripts.py
qrcode/constants.py
qrcode/exceptions.py
qrcode/main.py
-qrcode/mecard.py
-qrcode/speedy.py
-qrcode/tests.py
qrcode/util.py
qrcode.egg-info/PKG-INFO
qrcode.egg-info/SOURCES.txt
qrcode.egg-info/dependency_links.txt
+qrcode.egg-info/entry_points.txt
+qrcode.egg-info/pbr.json
qrcode.egg-info/requires.txt
qrcode.egg-info/top_level.txt
qrcode/image/__init__.py
@@ -24,4 +26,8 @@ qrcode/image/base.py
qrcode/image/pil.py
qrcode/image/pure.py
qrcode/image/svg.py
-scripts/qr
\ No newline at end of file
+qrcode/tests/__init__.py
+qrcode/tests/svg.py
+qrcode/tests/test_example.py
+qrcode/tests/test_qrcode.py
+qrcode/tests/test_script.py
\ No newline at end of file
diff --git a/qrcode.egg-info/entry_points.txt b/qrcode.egg-info/entry_points.txt
new file mode 100644
index 0000000..5029cb4
--- /dev/null
+++ b/qrcode.egg-info/entry_points.txt
@@ -0,0 +1,3 @@
+[console_scripts]
+qr = qrcode.console_scripts:main
+
diff --git a/qrcode.egg-info/pbr.json b/qrcode.egg-info/pbr.json
new file mode 100644
index 0000000..0e32915
--- /dev/null
+++ b/qrcode.egg-info/pbr.json
@@ -0,0 +1 @@
+{"git_version": "a2e3516", "is_release": false}
\ No newline at end of file
diff --git a/qrcode.egg-info/requires.txt b/qrcode.egg-info/requires.txt
index 64c56a3..ffe2fce 100644
--- a/qrcode.egg-info/requires.txt
+++ b/qrcode.egg-info/requires.txt
@@ -1 +1 @@
-six
\ No newline at end of file
+six
diff --git a/qrcode/__init__.py b/qrcode/__init__.py
index 718f8dc..f6aa53f 100644
--- a/qrcode/__init__.py
+++ b/qrcode/__init__.py
@@ -1,6 +1,10 @@
-from qrcode.main import QRCode, make
-from qrcode.constants import *
-from qrcode import image
+from qrcode.main import QRCode
+from qrcode.main import make # noqa
+from qrcode.constants import ( # noqa
+ ERROR_CORRECT_L, ERROR_CORRECT_M, ERROR_CORRECT_Q, ERROR_CORRECT_H)
+
+from qrcode import image # noqa
+
def run_example(data="http://www.lincolnloop.com", *args, **kwargs):
"""
@@ -16,6 +20,6 @@ def run_example(data="http://www.lincolnloop.com", *args, **kwargs):
im.show()
-if __name__ == '__main__':
+if __name__ == '__main__': # pragma: no cover
import sys
run_example(*sys.argv[1:])
diff --git a/qrcode/base.py b/qrcode/base.py
index 729f840..26c521f 100644
--- a/qrcode/base.py
+++ b/qrcode/base.py
@@ -8,7 +8,8 @@ for i in range(8):
EXP_TABLE[i] = 1 << i
for i in range(8, 256):
- EXP_TABLE[i] = (EXP_TABLE[i - 4] ^ EXP_TABLE[i - 5] ^ EXP_TABLE[i - 6] ^
+ EXP_TABLE[i] = (
+ EXP_TABLE[i - 4] ^ EXP_TABLE[i - 5] ^ EXP_TABLE[i - 6] ^
EXP_TABLE[i - 8])
for i in range(255):
@@ -116,7 +117,7 @@ RS_BLOCK_TABLE = [
[5, 109, 87, 1, 110, 88],
[5, 65, 41, 5, 66, 42],
[5, 54, 24, 7, 55, 25],
- [11, 36, 12],
+ [11, 36, 12, 7, 37, 13],
# 16
[5, 122, 98, 1, 123, 99],
@@ -272,7 +273,7 @@ RS_BLOCK_TABLE = [
def glog(n):
- if n < 1:
+ if n < 1: # pragma: no cover
raise ValueError("glog(%s)" % n)
return LOG_TABLE[n]
@@ -284,7 +285,7 @@ def gexp(n):
class Polynomial:
def __init__(self, num, shift):
- if not num:
+ if not num: # pragma: no cover
raise Exception("%s/%s" % (len(num), shift))
offset = 0
@@ -343,8 +344,9 @@ class RSBlock:
def rs_blocks(version, error_correction):
- if error_correction not in RS_BLOCK_OFFSET:
- raise Exception("bad rs block @ version: %s / error_correction: %s" %
+ if error_correction not in RS_BLOCK_OFFSET: # pragma: no cover
+ raise Exception(
+ "bad rs block @ version: %s / error_correction: %s" %
(version, error_correction))
offset = RS_BLOCK_OFFSET[error_correction]
rs_block = RS_BLOCK_TABLE[(version - 1) * 4 + offset]
diff --git a/scripts/qr b/qrcode/console_scripts.py
similarity index 55%
rename from scripts/qr
rename to qrcode/console_scripts.py
index c9269b5..5d1a904 100755
--- a/scripts/qr
+++ b/qrcode/console_scripts.py
@@ -7,7 +7,12 @@ a pipe to a file an image is written. The default image format is PNG.
"""
import sys
import optparse
+import os
import qrcode
+# The next block is added to get the terminal to display properly on MS platforms
+if sys.platform.startswith(('win', 'cygwin')):
+ import colorama
+ colorama.init()
default_factories = {
'pil': 'qrcode.image.pil.PilImage',
@@ -17,10 +22,15 @@ default_factories = {
'svg-path': 'qrcode.image.svg.SvgPathImage',
}
+error_correction = {
+ 'L': qrcode.ERROR_CORRECT_L,
+ 'M': qrcode.ERROR_CORRECT_M,
+ 'Q': qrcode.ERROR_CORRECT_Q,
+ 'H': qrcode.ERROR_CORRECT_H,
+}
-def main(*args):
- qr = qrcode.QRCode()
+def main(args=sys.argv[1:]):
parser = optparse.OptionParser(usage=__doc__.strip())
parser.add_option(
"--factory", help="Full python path to the image factory class to "
@@ -31,7 +41,15 @@ def main(*args):
"--optimize", type=int, help="Optimize the data by looking for chunks "
"of at least this many characters that could use a more efficient "
"encoding method. Use 0 to turn off chunk optimization.")
- opts, args = parser.parse_args(list(args))
+ parser.add_option(
+ "--error-correction", type='choice',
+ choices=sorted(error_correction.keys()), default='M',
+ help="The error correction level to use. Choices are L (7%), "
+ "M (15%, default), Q (25%), and H (30%).")
+ opts, args = parser.parse_args(args)
+
+ qr = qrcode.QRCode(
+ error_correction=error_correction[opts.error_correction])
if opts.factory:
module = default_factories.get(opts.factory, opts.factory)
@@ -46,19 +64,33 @@ def main(*args):
if args:
data = args[0]
else:
- data = sys.stdin.read()
+ # Use sys.stdin.buffer if available (Python 3) avoiding
+ # UnicodeDecodeErrors.
+ stdin_buffer = getattr(sys.stdin, 'buffer', sys.stdin)
+ data = stdin_buffer.read()
if opts.optimize is None:
qr.add_data(data)
else:
qr.add_data(data, optimize=opts.optimize)
- if image_factory is None and sys.stdout.isatty():
+ if image_factory is None and os.isatty(sys.stdout.fileno()):
qr.print_ascii(tty=True)
return
img = qr.make_image(image_factory=image_factory)
- img.save(sys.stdout)
+
+ sys.stdout.flush()
+ # Use sys.stdout.buffer if available (Python 3), avoiding
+ # UnicodeDecodeErrors.
+ stdout_buffer = getattr(sys.stdout, 'buffer', None)
+ if not stdout_buffer:
+ if sys.platform == 'win32': # pragma: no cover
+ import msvcrt
+ msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
+ stdout_buffer = sys.stdout
+
+ img.save(stdout_buffer)
if __name__ == "__main__":
- main(*sys.argv[1:])
+ main()
diff --git a/qrcode/image/base.py b/qrcode/image/base.py
index 8cee539..d0bfd8f 100644
--- a/qrcode/image/base.py
+++ b/qrcode/image/base.py
@@ -33,12 +33,18 @@ class BaseImage(object):
y = (row + self.border) * self.box_size
return [(x, y), (x + self.box_size - 1, y + self.box_size - 1)]
- def new_image(self, **kwargs):
+ def new_image(self, **kwargs): # pragma: no cover
"""
Build the image class. Subclasses should return the class created.
"""
return None
+ def get_image(self, **kwargs):
+ """
+ Return the image class for further processing.
+ """
+ return self._img
+
def check_kind(self, kind, transform=None):
"""
Get the image type.
diff --git a/qrcode/image/pil.py b/qrcode/image/pil.py
index e13e5a9..a56d2f9 100644
--- a/qrcode/image/pil.py
+++ b/qrcode/image/pil.py
@@ -4,7 +4,7 @@ from __future__ import absolute_import
# Try to import PIL in either of the two ways it can be installed.
try:
from PIL import Image, ImageDraw
-except ImportError:
+except ImportError: # pragma: no cover
import Image
import ImageDraw
@@ -18,18 +18,33 @@ class PilImage(qrcode.image.base.BaseImage):
kind = "PNG"
def new_image(self, **kwargs):
- img = Image.new("1", (self.pixel_size, self.pixel_size), "white")
+ back_color = kwargs.get("fill_color", "white")
+ fill_color = kwargs.get("back_color", "black")
+
+ if fill_color.lower() != "black" or back_color.lower() != "white":
+ if back_color.lower() == "transparent":
+ mode = "RGBA"
+ back_color = None
+ else:
+ mode = "RGB"
+ else:
+ mode = "1"
+
+ img = Image.new(mode, (self.pixel_size, self.pixel_size), back_color)
+ self.fill_color = fill_color
self._idr = ImageDraw.Draw(img)
return img
def drawrect(self, row, col):
box = self.pixel_box(row, col)
- self._idr.rectangle(box, fill="black")
-
- def save(self, stream, kind=None):
- if kind is None:
- kind = self.kind
- self._img.save(stream, kind)
+ self._idr.rectangle(box, fill=self.fill_color)
+
+ def save(self, stream, format=None, **kwargs):
+ if format is None:
+ format = kwargs.get("kind", self.kind)
+ if "kind" in kwargs:
+ del kwargs["kind"]
+ self._img.save(stream, format=format, **kwargs)
... 845 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-qrcode.git
More information about the Python-modules-commits
mailing list