Fixed regex usage in Python code (due to commit 9ed47110a5).

pull/88/head
Project Nayuki 5 years ago
parent 9ed47110a5
commit 6951a7e49e

@ -731,7 +731,7 @@ class QrSegment:
@staticmethod @staticmethod
def make_numeric(digits: str) -> QrSegment: def make_numeric(digits: str) -> QrSegment:
"""Returns a segment representing the given string of decimal digits encoded in numeric mode.""" """Returns a segment representing the given string of decimal digits encoded in numeric mode."""
if QrSegment.NUMERIC_REGEX.match(digits) is None: if QrSegment.NUMERIC_REGEX.fullmatch(digits) is None:
raise ValueError("String contains non-numeric characters") raise ValueError("String contains non-numeric characters")
bb = _BitBuffer() bb = _BitBuffer()
i = 0 i = 0
@ -747,7 +747,7 @@ class QrSegment:
"""Returns a segment representing the given text string encoded in alphanumeric mode. """Returns a segment representing the given text string encoded in alphanumeric mode.
The characters allowed are: 0 to 9, A to Z (uppercase only), space, The characters allowed are: 0 to 9, A to Z (uppercase only), space,
dollar, percent, asterisk, plus, hyphen, period, slash, colon.""" dollar, percent, asterisk, plus, hyphen, period, slash, colon."""
if QrSegment.ALPHANUMERIC_REGEX.match(text) is None: if QrSegment.ALPHANUMERIC_REGEX.fullmatch(text) is None:
raise ValueError("String contains unencodable characters in alphanumeric mode") raise ValueError("String contains unencodable characters in alphanumeric mode")
bb = _BitBuffer() bb = _BitBuffer()
for i in range(0, len(text) - 1, 2): # Process groups of 2 for i in range(0, len(text) - 1, 2): # Process groups of 2
@ -769,9 +769,9 @@ class QrSegment:
# Select the most efficient segment encoding automatically # Select the most efficient segment encoding automatically
if text == "": if text == "":
return [] return []
elif QrSegment.NUMERIC_REGEX.match(text) is not None: elif QrSegment.NUMERIC_REGEX.fullmatch(text) is not None:
return [QrSegment.make_numeric(text)] return [QrSegment.make_numeric(text)]
elif QrSegment.ALPHANUMERIC_REGEX.match(text) is not None: elif QrSegment.ALPHANUMERIC_REGEX.fullmatch(text) is not None:
return [QrSegment.make_alphanumeric(text)] return [QrSegment.make_alphanumeric(text)]
else: else:
return [QrSegment.make_bytes(text.encode("UTF-8"))] return [QrSegment.make_bytes(text.encode("UTF-8"))]

Loading…
Cancel
Save