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
768921cf
Commit
768921cf
authored
Feb 25, 2016
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite parsestr() so it's comprehensible; remove dead code
parent
202803a0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
24 deletions
+12
-24
Python/ast.c
Python/ast.c
+12
-24
No files found.
Python/ast.c
View file @
768921cf
...
...
@@ -3995,7 +3995,7 @@ decode_utf8(struct compiling *c, const char **sPtr, const char *end)
}
static
PyObject
*
decode_unicode
(
struct
compiling
*
c
,
const
char
*
s
,
size_t
len
,
const
char
*
encoding
)
decode_unicode
_with_escapes
(
struct
compiling
*
c
,
const
char
*
s
,
size_t
len
)
{
PyObject
*
v
,
*
u
;
char
*
buf
;
...
...
@@ -4921,7 +4921,6 @@ parsestr(struct compiling *c, const node *n, int *bytesmode, int *fmode)
const
char
*
s
=
STR
(
n
);
int
quote
=
Py_CHARMASK
(
*
s
);
int
rawmode
=
0
;
int
need_encoding
;
if
(
Py_ISALPHA
(
quote
))
{
while
(
!*
bytesmode
||
!
rawmode
)
{
if
(
quote
==
'b'
||
quote
==
'B'
)
{
...
...
@@ -4977,11 +4976,10 @@ parsestr(struct compiling *c, const node *n, int *bytesmode, int *fmode)
return
NULL
;
}
}
if
(
!*
bytesmode
&&
!
rawmode
)
{
return
decode_unicode
(
c
,
s
,
len
,
c
->
c_encoding
);
}
/* Avoid invoking escape decoding routines if possible. */
rawmode
=
rawmode
||
strchr
(
s
,
'\\'
)
==
NULL
;
if
(
*
bytesmode
)
{
/* Disallow non-
ascii characters (but not escapes)
*/
/* Disallow non-
ASCII characters.
*/
const
char
*
ch
;
for
(
ch
=
s
;
*
ch
;
ch
++
)
{
if
(
Py_CHARMASK
(
*
ch
)
>=
0x80
)
{
...
...
@@ -4990,26 +4988,16 @@ parsestr(struct compiling *c, const node *n, int *bytesmode, int *fmode)
return
NULL
;
}
}
}
need_encoding
=
!*
bytesmode
&&
strcmp
(
c
->
c_encoding
,
"utf-8"
)
!=
0
;
if
(
rawmode
||
strchr
(
s
,
'\\'
)
==
NULL
)
{
if
(
need_encoding
)
{
PyObject
*
v
,
*
u
=
PyUnicode_DecodeUTF8
(
s
,
len
,
NULL
);
if
(
u
==
NULL
||
!*
bytesmode
)
return
u
;
v
=
PyUnicode_AsEncodedString
(
u
,
c
->
c_encoding
,
NULL
);
Py_DECREF
(
u
);
return
v
;
}
else
if
(
*
bytesmode
)
{
if
(
rawmode
)
return
PyBytes_FromStringAndSize
(
s
,
len
);
}
else
if
(
strcmp
(
c
->
c_encoding
,
"utf-8"
)
==
0
)
{
return
PyUnicode_FromStringAndSize
(
s
,
len
);
}
else
{
return
PyUnicode_DecodeLatin1
(
s
,
len
,
NULL
);
}
else
return
PyBytes_DecodeEscape
(
s
,
len
,
NULL
,
/* ignored */
0
,
NULL
);
}
else
{
if
(
rawmode
)
return
PyUnicode_DecodeUTF8Stateful
(
s
,
len
,
NULL
,
NULL
);
else
return
decode_unicode_with_escapes
(
c
,
s
,
len
);
}
return
PyBytes_DecodeEscape
(
s
,
len
,
NULL
,
1
,
need_encoding
?
c
->
c_encoding
:
NULL
);
}
/* Accepts a STRING+ atom, and produces an expr_ty node. Run through
...
...
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