Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
343349f6
Commit
343349f6
authored
Mar 25, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #22364: Improved some re error messages using regex for hints.
parent
acf37945
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
300 additions
and
196 deletions
+300
-196
Lib/re.py
Lib/re.py
+1
-1
Lib/sre_compile.py
Lib/sre_compile.py
+3
-3
Lib/sre_parse.py
Lib/sre_parse.py
+112
-115
Lib/test/test_re.py
Lib/test/test_re.py
+179
-74
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_sre.c
Modules/_sre.c
+3
-3
No files found.
Lib/re.py
View file @
343349f6
...
...
@@ -286,7 +286,7 @@ def _compile(pattern, flags):
if
isinstance
(
pattern
,
_pattern_type
):
if
flags
:
raise
ValueError
(
"
C
annot process flags argument with a compiled pattern"
)
"
c
annot process flags argument with a compiled pattern"
)
return
pattern
if
not
sre_compile
.
isstring
(
pattern
):
raise
TypeError
(
"first argument must be string or compiled pattern"
)
...
...
Lib/sre_compile.py
View file @
343349f6
...
...
@@ -113,7 +113,7 @@ def _compile(code, pattern, flags):
emit
(
ANY
)
elif
op
in
REPEATING_CODES
:
if
flags
&
SRE_FLAG_TEMPLATE
:
raise
error
(
"internal: unsupported template operator
"
)
raise
error
(
"internal: unsupported template operator
%r"
%
(
op
,)
)
elif
_simple
(
av
)
and
op
is
not
REPEAT
:
if
op
is
MAX_REPEAT
:
emit
(
REPEAT_ONE
)
...
...
@@ -216,7 +216,7 @@ def _compile(code, pattern, flags):
else
:
code
[
skipyes
]
=
_len
(
code
)
-
skipyes
+
1
else
:
raise
ValueError
(
"unsupported operand type"
,
op
)
raise
error
(
"internal: unsupported operand type %r"
%
(
op
,)
)
def
_compile_charset
(
charset
,
flags
,
code
,
fixup
=
None
,
fixes
=
None
):
# compile charset subprogram
...
...
@@ -242,7 +242,7 @@ def _compile_charset(charset, flags, code, fixup=None, fixes=None):
else
:
emit
(
av
)
else
:
raise
error
(
"internal: unsupported set operator
"
)
raise
error
(
"internal: unsupported set operator
%r"
%
(
op
,)
)
emit
(
FAILURE
)
def
_optimize_charset
(
charset
,
fixup
,
fixes
):
...
...
Lib/sre_parse.py
View file @
343349f6
This diff is collapsed.
Click to expand it.
Lib/test/test_re.py
View file @
343349f6
This diff is collapsed.
Click to expand it.
Misc/NEWS
View file @
343349f6
...
...
@@ -30,6 +30,8 @@ Core and Builtins
Library
-------
-
Issue
#
22364
:
Improved
some
re
error
messages
using
regex
for
hints
.
-
Issue
#
23742
:
ntpath
.
expandvars
()
no
longer
loses
unbalanced
single
quotes
.
-
Issue
#
21717
:
The
zipfile
.
ZipFile
.
open
function
now
supports
'x'
(
exclusive
...
...
Modules/_sre.c
View file @
343349f6
...
...
@@ -315,7 +315,7 @@ getstring(PyObject* string, Py_ssize_t* p_length,
/* get pointer to byte string buffer */
if
(
PyObject_GetBuffer
(
string
,
view
,
PyBUF_SIMPLE
)
!=
0
)
{
PyErr_SetString
(
PyExc_TypeError
,
"expected string or b
uffer
"
);
PyErr_SetString
(
PyExc_TypeError
,
"expected string or b
ytes-like object
"
);
return
NULL
;
}
...
...
@@ -359,12 +359,12 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string,
if
(
isbytes
&&
pattern
->
isbytes
==
0
)
{
PyErr_SetString
(
PyExc_TypeError
,
"can
'
t use a string pattern on a bytes-like object"
);
"can
no
t use a string pattern on a bytes-like object"
);
goto
err
;
}
if
(
!
isbytes
&&
pattern
->
isbytes
>
0
)
{
PyErr_SetString
(
PyExc_TypeError
,
"can
'
t use a bytes pattern on a string-like object"
);
"can
no
t use a bytes pattern on a string-like object"
);
goto
err
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment