Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
e1d01bec
Commit
e1d01bec
authored
Apr 09, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bytes.decode() without arguments
parent
827fff94
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
12 deletions
+30
-12
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+17
-12
tests/run/charptr_decode.pyx
tests/run/charptr_decode.pyx
+13
-0
No files found.
Cython/Compiler/Optimize.py
View file @
e1d01bec
...
...
@@ -1944,20 +1944,25 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
return
None
def
_unpack_encoding_and_error_mode
(
self
,
pos
,
args
):
encoding_node
=
args
[
1
]
if
isinstance
(
encoding_node
,
ExprNodes
.
CoerceToPyTypeNode
):
encoding_node
=
encoding_node
.
arg
if
isinstance
(
encoding_node
,
(
ExprNodes
.
UnicodeNode
,
ExprNodes
.
StringNode
,
ExprNodes
.
BytesNode
)):
encoding
=
encoding_node
.
value
encoding_node
=
ExprNodes
.
BytesNode
(
encoding_node
.
pos
,
value
=
encoding
,
type
=
PyrexTypes
.
c_char_ptr_type
)
elif
encoding_node
.
type
.
is_string
:
encoding
=
None
null_node
=
ExprNodes
.
NullNode
(
pos
)
if
len
(
args
)
>=
2
:
encoding_node
=
args
[
1
]
if
isinstance
(
encoding_node
,
ExprNodes
.
CoerceToPyTypeNode
):
encoding_node
=
encoding_node
.
arg
if
isinstance
(
encoding_node
,
(
ExprNodes
.
UnicodeNode
,
ExprNodes
.
StringNode
,
ExprNodes
.
BytesNode
)):
encoding
=
encoding_node
.
value
encoding_node
=
ExprNodes
.
BytesNode
(
encoding_node
.
pos
,
value
=
encoding
,
type
=
PyrexTypes
.
c_char_ptr_type
)
elif
encoding_node
.
type
.
is_string
:
encoding
=
None
else
:
return
None
else
:
return
None
encoding
=
None
encoding_node
=
null_node
null_node
=
ExprNodes
.
NullNode
(
pos
)
if
len
(
args
)
==
3
:
error_handling_node
=
args
[
2
]
if
isinstance
(
error_handling_node
,
ExprNodes
.
CoerceToPyTypeNode
):
...
...
tests/run/charptr_decode.pyx
View file @
e1d01bec
...
...
@@ -17,6 +17,19 @@ def slice_charptr_decode():
cstring
[:
3
].
decode
(
'UTF-8'
),
cstring
[:
9
].
decode
(
'UTF-8'
))
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
)
@
cython
.
test_fail_if_path_exists
(
"//AttributeNode"
)
def
slice_charptr_decode_platform_encoding
():
"""
>>> print(str(slice_charptr_decode()).replace("u'", "'"))
('a', 'abc', 'abcABCqtp')
"""
cdef
bytes
s
=
u'abcABCqtp'
.
encode
()
cdef
char
*
cstr
=
s
return
(
cstr
[:
1
].
decode
(),
cstr
[:
3
].
decode
(),
cstr
[:
9
].
decode
())
@
cython
.
test_assert_path_exists
(
"//PythonCapiCallNode"
)
@
cython
.
test_fail_if_path_exists
(
"//AttributeNode"
)
def
slice_charptr_decode_unknown_encoding
():
...
...
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