diff options
author | Guido van Rossum <guido@python.org> | 1997-07-15 18:11:42 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-07-15 18:11:42 (GMT) |
commit | 9f845ec64b47d32afe44bdba4a9a6b7b51d1b00c (patch) | |
tree | 11ca46ca39b4616a14290747af4cf354448a4729 /Lib | |
parent | 23b8d4c15e4338689c3ac0695fe981eaf62b0c3f (diff) | |
download | cpython-9f845ec64b47d32afe44bdba4a9a6b7b51d1b00c.zip cpython-9f845ec64b47d32afe44bdba4a9a6b7b51d1b00c.tar.gz cpython-9f845ec64b47d32afe44bdba4a9a6b7b51d1b00c.tar.bz2 |
More changes by Jeffrey.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/re.py | 74 |
1 files changed, 51 insertions, 23 deletions
@@ -688,34 +688,62 @@ def expand_escape(pattern, index, context=NORMAL): return CHAR, 'D', index + 1 elif pattern[index] in '0123456789': - end = index - while (end < len(pattern)) and (pattern[end] in string.digits): - end = end + 1 - value = pattern[index:end] - if (len(value) == 3) or ((len(value) == 2) and (value[0] == '0')): - # octal character value - value = string.atoi(value, 8) - if value > 255: - raise error, 'octal char out of range' - return CHAR, chr(value), end + if pattern[index] == '0': + if (index + 1 < len(pattern)) and \ + (pattern[index + 1] in string.octdigits): + if (index + 2 < len(pattern)) and \ + (pattern[index + 2] in string.octdigits): + value = string.atoi(pattern[index:index + 3], 8) + index = index + 3 + + else: + value = string.atoi(pattern[index:index + 2], 8) + index = index + 2 - elif value == '0': - return CHAR, chr(0), end + else: + value = 0 + index = index + 1 - elif len(value) > 3: - raise error, ('\\' + value + ' has too many digits') + if value > 255: + raise error, 'octal value out of range' + return CHAR, chr(value), index + else: - # \1-\99 - reference a register - if context == CHARCLASS: - raise error, ('cannot reference a register from ' - 'inside a character class') - value = string.atoi(value) - if value == 0: - raise error, ('register 0 cannot be used ' - 'during match') - return MEMORY_REFERENCE, value, end + if (index + 1 < len(pattern)) and \ + (pattern[index + 1] in string.digits): + if (index + 2 < len(pattern)) and \ + (pattern[index + 2] in string.octdigits) and \ + (pattern[index + 1] in string.octdigits) and \ + (pattern[index] in string.octdigits): + value = string.atoi(pattern[index:index + 3], 8) + if value > 255: + raise error, 'octal value out of range' + + return CHAR, chr(value), index + 3 + + else: + value = string.atoi(pattern[index:index + 2]) + if (value < 1) or (value > 99): + raise error, 'memory reference out of range' + + if context == CHARCLASS: + raise error, ('cannot reference a register from ' + 'inside a character class') + return MEMORY_REFERENCE, value, index + 2 + + else: + if context == CHARCLASS: + raise error, ('cannot reference a register from ' + 'inside a character class') + + value = string.atoi(pattern[index]) + return MEMORY_REFERENCE, value, index + 1 + + while (end < len(pattern)) and (pattern[end] in string.digits): + end = end + 1 + value = pattern[index:end] else: return CHAR, pattern[index], index + 1 |