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
86f088e8
Commit
86f088e8
authored
Jul 22, 2011
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Plain Diff
merge 3.2
parents
db57e8d1
2193d2b7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
4 deletions
+55
-4
Lib/test/test_ast.py
Lib/test/test_ast.py
+14
-0
Misc/NEWS
Misc/NEWS
+3
-0
Parser/asdl_c.py
Parser/asdl_c.py
+19
-2
Python/Python-ast.c
Python/Python-ast.c
+19
-2
No files found.
Lib/test/test_ast.py
View file @
86f088e8
...
...
@@ -367,6 +367,20 @@ class AST_Tests(unittest.TestCase):
compile
(
m
,
"<test>"
,
"exec"
)
self
.
assertIn
(
"but got <_ast.expr"
,
str
(
cm
.
exception
))
def
test_invalid_identitifer
(
self
):
m
=
ast
.
Module
([
ast
.
Expr
(
ast
.
Name
(
42
,
ast
.
Load
()))])
ast
.
fix_missing_locations
(
m
)
with
self
.
assertRaises
(
TypeError
)
as
cm
:
compile
(
m
,
"<test>"
,
"exec"
)
self
.
assertIn
(
"identifier must be of type str"
,
str
(
cm
.
exception
))
def
test_invalid_string
(
self
):
m
=
ast
.
Module
([
ast
.
Expr
(
ast
.
Str
(
42
))])
ast
.
fix_missing_locations
(
m
)
with
self
.
assertRaises
(
TypeError
)
as
cm
:
compile
(
m
,
"<test>"
,
"exec"
)
self
.
assertIn
(
"string must be of type str"
,
str
(
cm
.
exception
))
class
ASTHelpers_Test
(
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
86f088e8
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
- Verify the types of AST strings and identifiers provided by the user before
compiling them.
- Issue #12579: str.format_map() now raises a ValueError if used on a
format string that contains positional fields. Initial patch by
Julian Berman.
...
...
Parser/asdl_c.py
View file @
86f088e8
...
...
@@ -795,8 +795,25 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
return 0;
}
#define obj2ast_identifier obj2ast_object
#define obj2ast_string obj2ast_object
static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena,
const char *name)
{
if (!PyUnicode_CheckExact(name)) {
PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name);
return 1;
}
return obj2ast_object(obj, out, arena);
}
static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
{
return obj2ast_stringlike(obj, out, arena, "identifier");
}
static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
{
return obj2ast_stringlike(obj, out, arena, "string");
}
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
{
...
...
Python/Python-ast.c
View file @
86f088e8
...
...
@@ -592,8 +592,25 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
return
0
;
}
#define obj2ast_identifier obj2ast_object
#define obj2ast_string obj2ast_object
static
int
obj2ast_stringlike
(
PyObject
*
obj
,
PyObject
**
out
,
PyArena
*
arena
,
const
char
*
name
)
{
if
(
!
PyUnicode_CheckExact
(
name
))
{
PyErr_Format
(
PyExc_TypeError
,
"AST %s must be of type str"
,
name
);
return
1
;
}
return
obj2ast_object
(
obj
,
out
,
arena
);
}
static
int
obj2ast_identifier
(
PyObject
*
obj
,
PyObject
**
out
,
PyArena
*
arena
)
{
return
obj2ast_stringlike
(
obj
,
out
,
arena
,
"identifier"
);
}
static
int
obj2ast_string
(
PyObject
*
obj
,
PyObject
**
out
,
PyArena
*
arena
)
{
return
obj2ast_stringlike
(
obj
,
out
,
arena
,
"string"
);
}
static
int
obj2ast_int
(
PyObject
*
obj
,
int
*
out
,
PyArena
*
arena
)
{
...
...
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