55
55
"""
56
56
57
57
# imports
58
+ import math
58
59
59
60
__version__ = "0.0.0-auto.0"
60
61
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_miniQR.git"
@@ -270,24 +271,24 @@ def create_data(qr_type, ecc, data_list):
270
271
for block in rs_blocks :
271
272
total_data_count += block ['data' ]
272
273
273
- if buffer .getLengthInBits () > total_data_count * 8 :
274
+ if buffer .get_length_bits () > total_data_count * 8 :
274
275
raise RuntimeError ("Code length overflow: %d > %d" %
275
- (buffer .getLengthInBits (), total_data_count * 8 ))
276
+ (buffer .get_length_bits (), total_data_count * 8 ))
276
277
277
278
#// end code
278
- if buffer .getLengthInBits () + 4 <= total_data_count * 8 :
279
+ if buffer .get_length_bits () + 4 <= total_data_count * 8 :
279
280
buffer .put (0 , 4 )
280
281
281
282
#// padding
282
- while buffer .getLengthInBits () % 8 != 0 :
283
- buffer .putBit (False )
283
+ while buffer .get_length_bits () % 8 != 0 :
284
+ buffer .put_bit (False )
284
285
285
286
#// padding
286
287
while True :
287
- if buffer .getLengthInBits () >= total_data_count * 8 :
288
+ if buffer .get_length_bits () >= total_data_count * 8 :
288
289
break
289
290
buffer .put (_PAD0 , 8 )
290
- if buffer .getLengthInBits () >= total_data_count * 8 :
291
+ if buffer .get_length_bits () >= total_data_count * 8 :
291
292
break
292
293
buffer .put (_PAD1 , 8 )
293
294
@@ -371,7 +372,7 @@ class QRUtil(object):
371
372
G15 = 0b10100110111
372
373
G18 = 0b1111100100101
373
374
G15_MASK = 0b101010000010010
374
-
375
+ #pylint: disable=invalid-name
375
376
@staticmethod
376
377
def get_BCH_type_info (data ):
377
378
d = data << 10
@@ -385,6 +386,7 @@ def get_BCH_type_number(data):
385
386
while QRUtil .get_BCH_digit (d ) - QRUtil .get_BCH_digit (QRUtil .G18 ) >= 0 :
386
387
d ^= QRUtil .G18 << (QRUtil .get_BCH_digit (d ) - QRUtil .get_BCH_digit (QRUtil .G18 ))
387
388
return (data << 12 ) | d
389
+ #pylint: enable=invalid-name
388
390
@staticmethod
389
391
def get_BCH_digit (data ):
390
392
digit = 0
@@ -397,6 +399,7 @@ def get_pattern_position(type):
397
399
return QRUtil .PATTERN_POSITION_TABLE [type - 1 ]
398
400
@staticmethod
399
401
def get_mask (mask , i , j ):
402
+ #pylint: disable=multiple-statements
400
403
if mask == 0 : return (i + j ) % 2 == 0
401
404
if mask == 1 : return i % 2 == 0
402
405
if mask == 2 : return j % 3 == 0
@@ -406,6 +409,7 @@ def get_mask(mask, i, j):
406
409
if mask == 6 : return ((i * j ) % 2 + (i * j ) % 3 ) % 2 == 0
407
410
if mask == 7 : return ((i * j ) % 3 + (i + j ) % 2 ) % 2 == 0
408
411
raise ValueError ("Bad mask pattern:" + mask )
412
+ #pylint: enable=multiple-statements
409
413
@staticmethod
410
414
def get_error_correct_polynomial (ecc_length ):
411
415
a = QRPolynomial ([1 ], 0 )
@@ -440,20 +444,21 @@ def multiply(self, e):
440
444
_QRRS_BLOCK_TABLE = (b'\x01 \x1a \x10 ' , b'\x01 \x1a \x13 ' , b'\x01 \x1a \t ' , b'\x01 \x1a \r ' , b'\x01 ,\x1c ' , b'\x01 ,"' , b'\x01 ,\x10 ' , b'\x01 ,\x16 ' , b'\x01 F,' , b'\x01 F7' , b'\x02 #\r ' , b'\x02 #\x11 ' , b'\x02 2 ' , b'\x01 dP' , b'\x04 \x19 \t ' , b'\x02 2\x18 ' , b'\x02 C+' , b'\x01 \x86 l' , b'\x02 !\x0b \x02 "\x0c ' , b'\x02 !\x0f \x02 "\x10 ' , b'\x04 +\x1b ' , b'\x02 VD' , b'\x04 +\x0f ' , b'\x04 +\x13 ' , b'\x04 1\x1f ' , b'\x02 bN' , b"\x04 '\r \x01 (\x0e " , b'\x02 \x0e \x04 !\x0f ' , b"\x02 <&\x02 ='" , b'\x02 ya' , b'\x04 (\x0e \x02 )\x0f ' , b'\x04 (\x12 \x02 )\x13 ' , b'\x03 :$\x02 ;%' , b'\x02 \x92 t' , b'\x04 $\x0c \x04 %\r ' , b'\x04 $\x10 \x04 %\x11 ' ) #pylint: disable=line-too-long
441
445
442
446
def _getRSBlocks (qr_type , ECC ):
443
- rsBlock = _QRRS_BLOCK_TABLE [(qr_type - 1 ) * 4 + ECC ]
447
+ rs_block = _QRRS_BLOCK_TABLE [(qr_type - 1 ) * 4 + ECC ]
444
448
445
- length = len (rsBlock ) // 3
446
- list = []
449
+ length = len (rs_block ) // 3
450
+ blocks = []
447
451
for i in range (length ):
448
- count = rsBlock [i * 3 + 0 ]
449
- totalCount = rsBlock [i * 3 + 1 ]
450
- dataCount = rsBlock [i * 3 + 2 ]
451
- block = {'total' : totalCount , 'data' : dataCount }
452
- for j in range (count ):
453
- list .append (block )
454
- return list
452
+ count = rs_block [i * 3 + 0 ]
453
+ total = rs_block [i * 3 + 1 ]
454
+ data = rs_block [i * 3 + 2 ]
455
+ block = {'total' : total , 'data' : data }
456
+ for _ in range (count ):
457
+ blocks .append (block )
458
+ return blocks
455
459
456
460
class QRBitMatrix :
461
+ """A bit-packed storage class for matrices"""
457
462
def __init__ (self , width , height ):
458
463
self .width = width
459
464
self .height = height
@@ -463,19 +468,20 @@ def __init__(self, width, height):
463
468
self .used = [0 ] * self .height * 2
464
469
465
470
def __repr__ (self ):
466
- s = ""
471
+ b = ""
467
472
for y in range (self .height ):
468
473
for x in range (self .width ):
469
474
if self [x , y ]:
470
- s += 'X'
475
+ b += 'X'
471
476
else :
472
- s += '.'
473
- s += '\n '
474
- return s
477
+ b += '.'
478
+ b += '\n '
479
+ return b
475
480
476
481
def __getitem__ (self , key ):
477
482
x , y = key
478
- if y > self .width : raise ValueError ()
483
+ if y > self .width :
484
+ raise ValueError ()
479
485
i = 2 * x + (y // 30 )
480
486
j = y % 30
481
487
if not self .used [i ] & (1 << j ):
@@ -484,7 +490,8 @@ def __getitem__(self, key):
484
490
485
491
def __setitem__ (self , key , value ):
486
492
x , y = key
487
- if y > self .width : raise ValueError ()
493
+ if y > self .width :
494
+ raise ValueError ()
488
495
i = 2 * x + (y // 30 )
489
496
j = y % 30
490
497
if value :
@@ -494,6 +501,7 @@ def __setitem__(self, key, value):
494
501
self .used [i ] |= 1 << j # buffer item was set
495
502
496
503
class QRBitBuffer :
504
+ """Storage class for a length of individual bits"""
497
505
def __init__ (self ):
498
506
self .buffer = []
499
507
self .length = 0
@@ -502,17 +510,21 @@ def __repr__(self):
502
510
return "." .join ([str (n ) for n in self .buffer ])
503
511
504
512
def get (self , index ):
513
+ """The bit value at a location"""
505
514
i = index // 8
506
515
return self .buffer [i ] & (1 << (7 - index % 8 ))
507
516
508
517
def put (self , num , length ):
518
+ """Add a number of bits from a single integer value"""
509
519
for i in range (length ):
510
- self .putBit (num & (1 << (length - i - 1 )))
520
+ self .put_bit (num & (1 << (length - i - 1 )))
511
521
512
- def getLengthInBits (self ):
522
+ def get_length_bits (self ):
523
+ """Size of bit buffer"""
513
524
return self .length
514
525
515
- def putBit (self , bit ):
526
+ def put_bit (self , bit ):
527
+ """Insert one bit at the end of the bit buffer"""
516
528
i = self .length // 8
517
529
if len (self .buffer ) <= i :
518
530
self .buffer .append (0 )
0 commit comments