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

Side by Side Diff: Lib/sre_constants.py

Issue 22578: Add addition attributes to re.error
Patch Set: Created 5 years 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
« no previous file with comments | « Doc/library/re.rst ('k') | Lib/sre_parse.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 self.colno = pos - pattern.rfind(newline, 0, pos)
36 if newline in pattern:
37 msg = '%s (line %d, column %d)' % (msg, self.lineno, self.colno)
38 else:
39 self.lineno = self.colno = None
40 super().__init__(msg)
25 41
42 def linecol(doc, pos):
43 if isinstance(pattern, str):
44 newline = '\n'
45 else:
46 newline = b'\n'
47 lineno = pattern.count(newline, 0, pos) + 1
48 if lineno == 1:
49 colno = pos + 1
50 else:
51 colno = pos - doc.rindex(newline, 0, pos)
52 return lineno, colno
26 # operators 53 # operators
27 54
28 FAILURE = "failure" 55 FAILURE = "failure"
29 SUCCESS = "success" 56 SUCCESS = "success"
30 57
31 ANY = "any" 58 ANY = "any"
32 ANY_ALL = "any_all" 59 ANY_ALL = "any_all"
33 ASSERT = "assert" 60 ASSERT = "assert"
34 ASSERT_NOT = "assert_not" 61 ASSERT_NOT = "assert_not"
35 AT = "at" 62 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) 279 f.write("#define SRE_FLAG_VERBOSE %d\n" % SRE_FLAG_VERBOSE)
253 f.write("#define SRE_FLAG_DEBUG %d\n" % SRE_FLAG_DEBUG) 280 f.write("#define SRE_FLAG_DEBUG %d\n" % SRE_FLAG_DEBUG)
254 f.write("#define SRE_FLAG_ASCII %d\n" % SRE_FLAG_ASCII) 281 f.write("#define SRE_FLAG_ASCII %d\n" % SRE_FLAG_ASCII)
255 282
256 f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX) 283 f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX)
257 f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL) 284 f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL)
258 f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET) 285 f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET)
259 286
260 f.close() 287 f.close()
261 print("done") 288 print("done")
OLDNEW
« no previous file with comments | « Doc/library/re.rst ('k') | Lib/sre_parse.py » ('j') | no next file with comments »

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