|
8 | 8 | _format_datestr, _parse_datestr, _str_to_bytes, binary, uri)
|
9 | 9 |
|
10 | 10 | _real_regex = re.compile(br"[-+]?(?:(\d+(\.\d*)?|\d*\.\d+)([eE][-+]?\d+)?)|[-+]?inf|[-+]?nan")
|
11 |
| -_true_regex = re.compile(br"TRUE|true|\b[Tt]\b") |
12 |
| -_false_regex = re.compile(br"FALSE|false|\b[Ff]\b") |
13 | 11 |
|
14 | 12 |
|
15 | 13 | class LLSDNotationParser(LLSDBaseParser):
|
@@ -346,10 +344,50 @@ def _parse_string_raw(self):
|
346 | 344 | raise LLSDParseError(exc)
|
347 | 345 |
|
348 | 346 | def _parse_true(self, cc):
|
349 |
| - return self._get_re(cc, "'true'", _true_regex, True) |
| 347 | + # match t, T, true, TRUE -- not mixed-case |
| 348 | + try: |
| 349 | + rest = {b't': b'rue', b'T': b'RUE'}[cc] |
| 350 | + except KeyError: |
| 351 | + self._error("Invalid 'true' token") |
| 352 | + |
| 353 | + cc = self._getc(full=False) |
| 354 | + # beware, rest is bytes, so bytes[0] is an int! |
| 355 | + if cc != rest[:1]: |
| 356 | + # just 't' or 'T' is legal, put back cc and carry on |
| 357 | + if cc: |
| 358 | + self._putback() |
| 359 | + return True |
| 360 | + |
| 361 | + # saw 'tr' or 'TR', cc is the 'r' |
| 362 | + tail = self._getc(len(rest)-1) |
| 363 | + # 'tr' MUST be followed by 'ue' |
| 364 | + if tail != rest[1:]: |
| 365 | + self._error("Invalid 'true' token") |
| 366 | + # good, it is |
| 367 | + return True |
350 | 368 |
|
351 | 369 | def _parse_false(self, cc):
|
352 |
| - return self._get_re(cc, "'false'", _false_regex, False) |
| 370 | + # match f, F, false, FALSE -- not mixed-case |
| 371 | + try: |
| 372 | + rest = {b'f': b'alse', b'F': b'ALSE'}[cc] |
| 373 | + except KeyError: |
| 374 | + self._error("Invalid 'false' token") |
| 375 | + |
| 376 | + cc = self._getc(full=False) |
| 377 | + # beware, rest is bytes, so bytes[0] is an int! |
| 378 | + if cc != rest[:1]: |
| 379 | + # just 'f' or 'F' is legal, put back cc and carry on |
| 380 | + if cc: |
| 381 | + self._putback() |
| 382 | + return False |
| 383 | + |
| 384 | + # saw 'fa' or 'FA', cc is the 'a' |
| 385 | + tail = self._getc(len(rest)-1) |
| 386 | + # 'fa' MUST be followed by 'lse' |
| 387 | + if tail != rest[1:]: |
| 388 | + self._error("Invalid 'false' token") |
| 389 | + # good, it is |
| 390 | + return False |
353 | 391 |
|
354 | 392 |
|
355 | 393 | class LLSDNotationFormatter(LLSDBaseFormatter):
|
|
0 commit comments