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
2b881d16
Commit
2b881d16
authored
May 20, 2016
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add __rmod__ to str object
parent
2b1b8705
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
src/runtime/str.cpp
src/runtime/str.cpp
+8
-0
test/tests/str_functions.py
test/tests/str_functions.py
+6
-0
No files found.
src/runtime/str.cpp
View file @
2b881d16
...
...
@@ -1164,6 +1164,13 @@ extern "C" Box* strMod(BoxedString* lhs, Box* rhs) {
return
rtn
;
}
Box
*
strRMod
(
BoxedString
*
lhs
,
Box
*
rhs
)
{
Box
*
rtn
=
PyString_Format
(
rhs
,
lhs
);
if
(
!
rtn
)
throwCAPIException
();
return
rtn
;
}
extern
"C"
Box
*
strMul
(
BoxedString
*
lhs
,
Box
*
rhs
)
{
assert
(
PyString_Check
(
lhs
));
...
...
@@ -2926,6 +2933,7 @@ void setupStr() {
str_cls
->
giveAttr
(
"__add__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
strAdd
,
UNKNOWN
,
2
)));
str_cls
->
giveAttr
(
"__mod__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
strMod
,
UNKNOWN
,
2
)));
str_cls
->
giveAttr
(
"__rmod__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
strRMod
,
UNKNOWN
,
2
)));
str_cls
->
giveAttr
(
"__mul__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
strMul
,
UNKNOWN
,
2
)));
// TODO not sure if this is right in all cases:
str_cls
->
giveAttr
(
"__rmul__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
strMul
,
UNKNOWN
,
2
)));
...
...
test/tests/str_functions.py
View file @
2b881d16
...
...
@@ -215,3 +215,9 @@ for i in xrange(-8, 8):
print
i
,
j
,
repr
(
s
[
i
:
j
])
for
k
in
(
-
2
,
1
,
1
,
2
):
print
i
,
j
,
k
,
repr
(
s
[
i
:
j
:
k
]),
repr
(
s
[
slice
(
i
,
j
,
k
)])
class
D
(
str
):
pass
print
(
D
(
'abc'
).
__rmod__
(
'%s'
))
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