My favorites
▼
|
Sign in
pyqrnative
Native Python QR code generation library
Project Home
Wiki
Issues
Source
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
8
attachment: PyQRNative.py.patch
(1.2 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
--- trunk/pyqrnative/src/PyQRNative.py
+++ trunk/pyqrnative/src/PyQRNative.py
@@ -39,7 +39,7 @@
class QRCode:
def __init__(self, typeNumber, errorCorrectLevel):
self.typeNumber = typeNumber
- self.errorCorrectLevel = errorCorrectLevel
+ self.errorCorrectLevel = QRErrorCorrectLevel.parseLevel(errorCorrectLevel)
self.modules = None
self.moduleCount = 0
self.dataCache = None
@@ -374,6 +374,26 @@
M = 0
Q = 3
H = 2
+
+ @staticmethod
+ def parseLevel(level):
+ if isinstance(level, QRErrorCorrectLevel):
+ return level
+ if isinstance(level, float):
+ return QRErrorCorrectLevel.forRestoreableFraction(level)
+ if isinstance(level, int) and 0 <= level < 4:
+ return level
+ raise ValueError("Invalid QRErrorCorrectLevel", level)
+
+ @staticmethod
+ def forRestoreableFraction(restorable):
+ if restorable <= .07:
+ return QRErrorCorrectLevel.L
+ if restorable <= .15:
+ return QRErrorCorrectLevel.M
+ if restorable <= .25:
+ return QRErrorCorrectLevel.Q
+ return QRErrorCorrectLevel.H
class QRMaskPattern:
PATTERN000 = 0
Powered by
Google Project Hosting