MCPcopy Index your code
hub / github.com/lincolnloop/python-qrcode / best_fit

Method best_fit

qrcode/main.py:208–236  ·  view source on GitHub ↗

Find the minimum size required to fit in the data.

(self, start=None)

Source from the content-addressed store, hash-verified

206 self.modules[row + r][col + c] = False
207
208 def best_fit(self, start=None):
209 """
210 Find the minimum size required to fit in the data.
211 """
212 if start is None:
213 start = 1
214 util.check_version(start)
215
216 # Corresponds to the code in util.create_data, except we don't yet know
217 # version, so optimistically assume start and check later
218 mode_sizes = util.mode_sizes_for_version(start)
219 buffer = util.BitBuffer()
220 for data in self.data_list:
221 buffer.put(data.mode, 4)
222 buffer.put(len(data), mode_sizes[data.mode])
223 data.write(buffer)
224
225 needed_bits = len(buffer)
226 self.version = bisect_left(
227 util.BIT_LIMIT_TABLE[self.error_correction], needed_bits, start
228 )
229 if self.version == 41:
230 raise exceptions.DataOverflowError()
231
232 # Now check whether we need more bits for the mode sizes, recursing if
233 # our guess was too low
234 if mode_sizes is not util.mode_sizes_for_version(self.version):
235 self.best_fit(start=self.version)
236 return self.version
237
238 def best_mask_pattern(self):
239 """

Callers 2

versionMethod · 0.95
makeMethod · 0.95

Calls 2

putMethod · 0.95
writeMethod · 0.80

Tested by

no test coverage detected