1+ """A module to make an rMQR Code.
2+
3+ Example:
4+ Use the rMQR.fit method to make an rMQR automatically with some options.
5+
6+ qr = rMQR.fit(
7+ "https://oudon.xyz",
8+ ecc=ErrorCorrectionLevel.M,
9+ fit_strategy=FitStrategy.MINIMIZE_WIDTH
10+ )
11+
12+ The following example shows how to select the size of an rMQR Code.
13+
14+ qr = rMQR("R11x139", ErrorCorrectionLevel.H)
15+ qr.make("https://oudon.xyz")
16+
17+ """
18+
119import logging
220
321from .encoder .byte_encoder import ByteEncoder
1432
1533
1634class rMQR :
35+ """A class to make an rMQR Code.
36+
37+ Attributes:
38+ QUIET_ZONE_MODULES (int): The width of the quiet zone.
39+
40+ """
41+
1742 QUIET_ZONE_MODULES = 2
1843
1944 @staticmethod
2045 def _init_logger ():
46+ """Initializes a logger and returns it.
47+
48+ Returns:
49+ logging.RootLogger: Logger
50+
51+ """
2152 logger = logging .getLogger (__name__ )
2253 logger .addHandler (logging .NullHandler ())
2354 logger .setLevel (logging .DEBUG )
@@ -26,6 +57,20 @@ def _init_logger():
2657
2758 @staticmethod
2859 def fit (data , ecc = ErrorCorrectionLevel .M , fit_strategy = FitStrategy .BALANCED ):
60+ """Attempts to make an rMQR have optimized version for given data.
61+
62+ Args:
63+ data (str): Data string to encode.
64+ ecc (rmqrcode.ErrorCorrectionLevel): Error correction level.
65+ fit_strategy (rmqrcode.FitStrategy): Strategy how determine rMQR Code version.
66+
67+ Returns:
68+ rmqrcode.rMQR: Optimized rMQR Code.
69+
70+ Raises:
71+ rmqrcode.DataTooLongError: If the data is too long to encode.
72+
73+ """
2974 logger = rMQR ._init_logger ()
3075
3176 data_length = ByteEncoder .length (data )
@@ -88,6 +133,14 @@ def __init__(self, version, ecc, with_quiet_zone=True, logger=None):
88133 self ._qr = [[Color .UNDEFINED for x in range (self ._width )] for y in range (self ._height )]
89134
90135 def make (self , data ):
136+ """Makes an rMQR Code for given data
137+
138+ Args:
139+ data (str): Data string.
140+
141+ Returns:
142+ void
143+ """
91144 self ._put_finder_pattern ()
92145 self ._put_corner_finder_pattern ()
93146 self ._put_alignment_pattern ()
@@ -97,21 +150,84 @@ def make(self, data):
97150 self ._apply_mask (mask_area )
98151
99152 def version_name (self ):
153+ """Returns the version name.
154+
155+ Returns:
156+ str: The version name.
157+
158+ Examples:
159+ >>> qr.version_name()
160+ "R13x77"
161+
162+ """
100163 return f"R{ self ._height } x{ self ._width } "
101164
102165 def size (self ):
166+ """Returns the size.
167+
168+ Returns:
169+ tuple: The rMQR Code size.
170+
171+ Examples:
172+ >>> qr.size()
173+ (77, 13)
174+
175+ Note:
176+ This not includes the quiet zone.
177+
178+ """
103179 return (self .width (), self .height ())
104180
105181 def height (self ):
182+ """Returns the height.
183+
184+ Returns:
185+ int: The height.
186+
187+ Note:
188+ This not includes the quiet zone.
189+
190+ """
106191 return self ._height
107192
108193 def width (self ):
194+ """Returns the width.
195+
196+ Returns:
197+ int: The width.
198+
199+ Note:
200+ This not includes the quiet zone.
201+
202+ """
109203 return self ._width
110204
111205 def value_at (self , x , y ):
206+ """DEPRECATED: Returns the color at the point of (x, y).
207+
208+ Returns:
209+ rmqrcode.Color: The color of rMQRCode at the point of (x, y).
210+
211+ Note:
212+ This method is deprecated. Use to_list() alternatively.
213+ This not includes the quiet zone.
214+
215+ """
112216 return self ._qr [y ][x ]
113217
114218 def to_list (self , with_quiet_zone = True ):
219+ """Converts to two-dimensional list and returns it.
220+
221+ The value is 1 for the dark module and 0 for the light module.
222+
223+ Args:
224+ with_quiet_zone (bool): Flag to select whether include the quiet zone.
225+
226+ Returns:
227+ list: Converted list.
228+
229+ """
230+
115231 res = []
116232 if with_quiet_zone :
117233 for y in range (self .QUIET_ZONE_MODULES ):
@@ -125,6 +241,19 @@ def to_list(self, with_quiet_zone=True):
125241 return res
126242
127243 def _to_binary_list (self ):
244+ """Converts to two-dimensional list and returns it.
245+
246+ The value is 1 for the dark module and 0 for the light module.
247+
248+ Args:
249+ with_quiet_zone (bool): Flag to select whether include the quiet zone.
250+
251+ Returns:
252+ list: Converted list.
253+
254+ Note:
255+ This not includes the quiet zone.
256+ """
128257 return [list (map (lambda x : 1 if x == Color .BLACK else 0 , column )) for column in self ._qr ]
129258
130259 def __str__ (self , with_quiet_zone = True ):
@@ -283,6 +412,21 @@ def _compute_version_info(self):
283412 return version_information_data
284413
285414 def _put_data (self , data ):
415+ """Symbol character placement.
416+
417+ This method puts data into the encoding region of the rMQR Code. Also this
418+ method computes a two-dimensional list shows where encoding region at the
419+ same time. And returns the list.
420+
421+ See: "7.7.3 Symbol character placement" in the ISO/IEC 23941.
422+
423+ Args:
424+ data (str): Data string.
425+
426+ Returns:
427+ list: A two-dimensional list shows where encoding region.
428+
429+ """
286430 qr_version = rMQRVersions [self .version_name ()]
287431
288432 character_count_length = qr_version ["character_count_length" ]
@@ -403,6 +547,18 @@ def _convert_to_bites_data(self, data, character_count_length, codewords_total):
403547 return encoded_data
404548
405549 def _apply_mask (self , mask_area ):
550+ """Data masking.
551+
552+ This method applies the data mask.
553+
554+ Args:
555+ mask_area (list): A two-dimensional list shows where encoding region.
556+ This is computed by self._put_data().
557+
558+ Returns:
559+ void
560+
561+ """
406562 for y in range (self ._height ):
407563 for x in range (self ._width ):
408564 if not mask_area [y ][x ]:
@@ -415,12 +571,33 @@ def _apply_mask(self, mask_area):
415571
416572 @staticmethod
417573 def validate_version (version_name ):
574+ """Check if the given version_name is valid
575+
576+ Args:
577+ version_name (str): Version name.
578+
579+ Returns:
580+ bool: Validation result.
581+
582+ Example:
583+ >>> rMQR.validate_version("R13x77")
584+ True
585+
586+ >>> rMQR.validate_version("R14x55")
587+ False
588+
589+ >>> rMQR.validate_version("13, 77")
590+ False
591+
592+ """
418593 return version_name in rMQRVersions
419594
420595
421596class DataTooLongError (ValueError ):
597+ "A class represents an error raised when the given data is too long."
422598 pass
423599
424600
425601class IllegalVersionError (ValueError ):
602+ "A class represents an error raised when the given version name is illegal."
426603 pass
0 commit comments