Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(91039)

Side by Side Diff: Lib/sre_constants.py

Issue 22578: Add addition attributes to re.error
Patch Set: Created 5 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 1 #
2 # Secret Labs' Regular Expression Engine 2 # Secret Labs' Regular Expression Engine
3 # 3 #
4 # various symbols used by the regular expression engine. 4 # various symbols used by the regular expression engine.
5 # run this script to update the _sre include files! 5 # run this script to update the _sre include files!
6 # 6 #
7 # Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved. 7 # Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved.
8 # 8 #
9 # See the sre.py file for information on usage and redistribution. 9 # See the sre.py file for information on usage and redistribution.
10 # 10 #
11 11
12 """Internal support module for sre""" 12 """Internal support module for sre"""
13 13
14 # update when constants are added or removed 14 # update when constants are added or removed
15 15
16 MAGIC = 20031017 16 MAGIC = 20031017
17 17
18 from _sre import MAXREPEAT, MAXGROUPS 18 from _sre import MAXREPEAT, MAXGROUPS
19 19
20 # SRE standard exception (access as sre.error) 20 # SRE standard exception (access as sre.error)
21 # should this really be here? 21 # should this really be here?
22 22
23 class error(Exception): 23 class error(Exception):
24 pass 24 def __init__(self, msg, pattern=None, pos=None):
25 self.msg = msg
26 self.pattern = pattern
27 self.pos = pos
28 if pattern is not None and pos is not None:
29 msg = '%s at position %d' % (msg, pos)
30 if isinstance(pattern, str):
31 newline = '\n'
32 else:
33 newline = b'\n'
34 self.lineno = pattern.count(newline, 0, pos) + 1
35 if self.lineno == 1:
36 self.colno = pos + 1
37 else:
38 self.colno = pos - pattern.rindex(newline, 0, pos)
39 msg = '%s (line %d, column %d)' % (msg, self.lineno, self.colno)
40 else:
41 self.lineno = self.colno = None
42 super().__init__(msg)
25 43
44 def linecol(doc, pos):
45 if isinstance(pattern, str):
46 newline = '\n'
47 else:
48 newline = b'\n'
49 lineno = pattern.count(newline, 0, pos) + 1
50 if lineno == 1:
51 colno = pos + 1
52 else:
53 colno = pos - doc.rindex(newline, 0, pos)
54 return lineno, colno
26 # operators 55 # operators
27 56
28 FAILURE = "failure" 57 FAILURE = "failure"
29 SUCCESS = "success" 58 SUCCESS = "success"
30 59
31 ANY = "any" 60 ANY = "any"
32 ANY_ALL = "any_all" 61 ANY_ALL = "any_all"
33 ASSERT = "assert" 62 ASSERT = "assert"
34 ASSERT_NOT = "assert_not" 63 ASSERT_NOT = "assert_not"
35 AT = "at" 64 AT = "at"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 f.write("#define SRE_FLAG_VERBOSE %d\n" % SRE_FLAG_VERBOSE) 281 f.write("#define SRE_FLAG_VERBOSE %d\n" % SRE_FLAG_VERBOSE)
253 f.write("#define SRE_FLAG_DEBUG %d\n" % SRE_FLAG_DEBUG) 282 f.write("#define SRE_FLAG_DEBUG %d\n" % SRE_FLAG_DEBUG)
254 f.write("#define SRE_FLAG_ASCII %d\n" % SRE_FLAG_ASCII) 283 f.write("#define SRE_FLAG_ASCII %d\n" % SRE_FLAG_ASCII)
255 284
256 f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX) 285 f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX)
257 f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL) 286 f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL)
258 f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET) 287 f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET)
259 288
260 f.close() 289 f.close()
261 print("done") 290 print("done")
OLDNEW

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+