|
15 | 15 | MAXREPEAT = 65535 |
16 | 16 |
|
17 | 17 | SPECIAL_CHARS = ".\\[{()*+?^$|" |
18 | | -REPEAT_CHARS = "*+?{" |
| 18 | +REPEAT_CHARS = "*+?{" |
19 | 19 |
|
20 | 20 | DIGITS = tuple("0123456789") |
21 | 21 |
|
@@ -259,29 +259,29 @@ def _escape(source, escape, state): |
259 | 259 | # hexadecimal escape |
260 | 260 | while source.next in HEXDIGITS and len(escape) < 4: |
261 | 261 | escape = escape + source.get() |
262 | | - escape = escape[2:] |
263 | | - if len(escape) != 2: |
264 | | - raise error, "bogus escape: %s" % repr("\\" + escape) |
265 | | - return LITERAL, int(escape, 16) & 0xff |
| 262 | + if len(escape) != 4: |
| 263 | + raise ValueError |
| 264 | + return LITERAL, int(escape[2:], 16) & 0xff |
266 | 265 | elif escape[1:2] == "0": |
267 | 266 | # octal escape |
268 | | - while source.next in OCTDIGITS and len(escape) < 5: |
| 267 | + while source.next in OCTDIGITS and len(escape) < 4: |
269 | 268 | escape = escape + source.get() |
270 | 269 | return LITERAL, int(escape[1:], 8) & 0xff |
271 | 270 | elif escape[1:2] in DIGITS: |
272 | 271 | # octal escape *or* decimal group reference (sigh) |
273 | 272 | here = source.tell() |
274 | 273 | if source.next in DIGITS: |
275 | 274 | escape = escape + source.get() |
276 | | - if escape[2] in OCTDIGITS and source.next in OCTDIGITS: |
| 275 | + if (escape[1] in OCTDIGITS and escape[2] in OCTDIGITS and |
| 276 | + source.next in OCTDIGITS): |
277 | 277 | # got three octal digits; this is an octal escape |
278 | 278 | escape = escape + source.get() |
279 | 279 | return LITERAL, int(escape[1:], 8) & 0xff |
280 | 280 | # got at least one decimal digit; this is a group reference |
281 | 281 | group = _group(escape, state.groups) |
282 | 282 | if group: |
283 | 283 | return GROUPREF, group |
284 | | - raise error, "bogus escape: %s" % repr(escape) |
| 284 | + raise ValueError |
285 | 285 | if len(escape) == 2: |
286 | 286 | return LITERAL, ord(escape[1]) |
287 | 287 | except ValueError: |
|
0 commit comments