2 # QR Code generator test worker (Python)
4 # This program reads data and encoding parameters from standard input and writes
5 # QR Code bitmaps to standard output. The I/O format is one integer per line.
6 # Run with no command line arguments. The program is intended for automated
7 # batch testing of end-to-end functionality of this QR Code generator library.
9 # Copyright (c) Project Nayuki. (MIT License)
10 # https://www.nayuki.io/page/qr-code-generator-library
12 # Permission is hereby granted, free of charge, to any person obtaining a copy of
13 # this software and associated documentation files (the "Software"), to deal in
14 # the Software without restriction, including without limitation the rights to
15 # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
16 # the Software, and to permit persons to whom the Software is furnished to do so,
17 # subject to the following conditions:
18 # - The above copyright notice and this permission notice shall be included in
19 # all copies or substantial portions of the Software.
20 # - The Software is provided "as is", without warranty of any kind, express or
21 # implied, including but not limited to the warranties of merchantability,
22 # fitness for a particular purpose and noninfringement. In no event shall the
23 # authors or copyright holders be liable for any claim, damages or other
24 # liability, whether in an action of contract, tort or otherwise, arising from,
25 # out of or in connection with the Software or the use or other dealings in the
33 def read_int() -> int:
44 data = bytearray(read_int() for _ in range(length))
46 # Read encoding parameters
47 errcorlvl = read_int()
48 minversion = read_int()
49 maxversion = read_int()
53 # Make segments for encoding
54 if all((b < 128) for b in data): # Is ASCII
55 segs = qrcodegen.QrSegment.make_segments(data.decode("ASCII"))
57 segs = [qrcodegen.QrSegment.make_bytes(data)]
59 try: # Try to make QR Code symbol
60 qr = qrcodegen.QrCode.encode_segments(segs, ECC_LEVELS[errcorlvl], minversion, maxversion, mask, boostecl != 0)
61 # Print grid of modules
62 print(qr.get_version())
63 for y in range(qr.get_size()):
64 for x in range(qr.get_size()):
65 print(1 if qr.get_module(x, y) else 0)
67 except qrcodegen.DataTooLongError:
73 qrcodegen.QrCode.Ecc.LOW,
74 qrcodegen.QrCode.Ecc.MEDIUM,
75 qrcodegen.QrCode.Ecc.QUARTILE,
76 qrcodegen.QrCode.Ecc.HIGH,
80 if __name__ == "__main__":