Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
1fa8e88f
Commit
1fa8e88f
authored
Apr 23, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow "".decode()
parent
b51c4bcf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
3 deletions
+69
-3
from_cpython/Objects/stringobject.c
from_cpython/Objects/stringobject.c
+62
-0
src/runtime/str.cpp
src/runtime/str.cpp
+3
-3
test/tests/str_encode_decode.py
test/tests/str_encode_decode.py
+4
-0
No files found.
from_cpython/Objects/stringobject.c
View file @
1fa8e88f
...
...
@@ -206,3 +206,65 @@ string_splitlines(PyStringObject *self, PyObject *args)
keepends
);
}
PyObject
*
PyString_AsDecodedObject
(
PyObject
*
str
,
const
char
*
encoding
,
const
char
*
errors
)
{
PyObject
*
v
;
if
(
!
PyString_Check
(
str
))
{
PyErr_BadArgument
();
goto
onError
;
}
if
(
encoding
==
NULL
)
{
#ifdef Py_USING_UNICODE
encoding
=
PyUnicode_GetDefaultEncoding
();
#else
PyErr_SetString
(
PyExc_ValueError
,
"no encoding specified"
);
goto
onError
;
#endif
}
/* Decode via the codec registry */
v
=
PyCodec_Decode
(
str
,
encoding
,
errors
);
if
(
v
==
NULL
)
goto
onError
;
return
v
;
onError:
return
NULL
;
}
PyObject
*
PyString_AsEncodedObject
(
PyObject
*
str
,
const
char
*
encoding
,
const
char
*
errors
)
{
PyObject
*
v
;
if
(
!
PyString_Check
(
str
))
{
PyErr_BadArgument
();
goto
onError
;
}
if
(
encoding
==
NULL
)
{
#ifdef Py_USING_UNICODE
encoding
=
PyUnicode_GetDefaultEncoding
();
#else
PyErr_SetString
(
PyExc_ValueError
,
"no encoding specified"
);
goto
onError
;
#endif
}
/* Encode via the codec registry */
v
=
PyCodec_Encode
(
str
,
encoding
,
errors
);
if
(
v
==
NULL
)
goto
onError
;
return
v
;
onError:
return
NULL
;
}
src/runtime/str.cpp
View file @
1fa8e88f
...
...
@@ -2194,8 +2194,8 @@ Box* strDecode(BoxedString* self, Box* encoding, Box* error) {
if
(
error_str
&&
!
isSubclass
(
error_str
->
cls
,
str_cls
))
raiseExcHelper
(
TypeError
,
"decode() argument 2 must be string, not '%s'"
,
getTypeName
(
error_str
));
Box
*
result
=
PyCodec_Decode
(
self
,
encoding_str
?
encoding_str
->
data
()
:
NULL
,
error_str
?
error_str
->
data
()
:
NULL
);
Box
*
result
=
PyString_AsDecodedObject
(
self
,
encoding_str
?
encoding_str
->
data
()
:
NULL
,
error_str
?
error_str
->
data
()
:
NULL
);
checkAndThrowCAPIException
();
return
result
;
}
...
...
@@ -2219,7 +2219,7 @@ Box* strEncode(BoxedString* self, Box* encoding, Box* error) {
if
(
error_str
&&
!
isSubclass
(
error_str
->
cls
,
str_cls
))
raiseExcHelper
(
TypeError
,
"encode() argument 2 must be string, not '%s'"
,
getTypeName
(
error_str
));
Box
*
result
=
Py
Codec_Encode
(
self
,
encoding_str
?
encoding_str
->
data
()
:
PyUnicode_GetDefaultEncoding
(),
Box
*
result
=
Py
String_AsEncodedObject
(
self
,
encoding_str
?
encoding_str
->
data
()
:
PyUnicode_GetDefaultEncoding
(),
error_str
?
error_str
->
data
()
:
NULL
);
checkAndThrowCAPIException
();
return
result
;
...
...
test/tests/str_encode_decode.py
View file @
1fa8e88f
...
...
@@ -7,3 +7,7 @@ test("hello world", "hex")
test
(
"hello world"
,
"base64"
)
test
(
"
\
r
\
n
\
\
"
,
"string-escape"
)
""
.
encode
()
""
.
decode
()
u""
.
encode
()
u""
.
decode
()
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