Commit 2b881d16 authored by Boxiang Sun's avatar Boxiang Sun

add __rmod__ to str object

parent 2b1b8705
......@@ -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)));
......
......@@ -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'))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment