def check_rsplit(value, sub, *args, **kwargs): result = kwargs['res'] assert rsplit(value, sub, *args) == result list_result = [list(i) for i in result] assert rsplit(list(value), sub, *args) == list_result assert rsplit(buffer(value), sub, *args) == result
def fn(): res = True res = res and split('a//b//c//d', '//') == ['a', 'b', 'c', 'd'] res = res and split('a//b//c//d', '//', 2) == ['a', 'b', 'c//d'] res = res and split(u'a//b//c//d', u'//') == [u'a', u'b', u'c', u'd'] res = res and split(u'endcase test', u'test') == [u'endcase ', u''] res = res and rsplit('a|b|c|d', '|', 2) == ['a|b', 'c', 'd'] res = res and rsplit('a//b//c//d', '//') == ['a', 'b', 'c', 'd'] res = res and rsplit(u'a|b|c|d', u'|') == [u'a', u'b', u'c', u'd'] res = res and rsplit(u'a|b|c|d', u'|', 2) == [u'a|b', u'c', u'd'] res = res and rsplit(u'a//b//c//d', u'//') == [u'a', u'b', u'c', u'd'] return res
def descr_rsplit(self, space, w_sep=None, maxsplit=-1): res = [] value = self._val(space) if space.is_none(w_sep): res = rsplit(value, maxsplit=maxsplit) return self._newlist_unwrapped(space, res) by = self._op_val(space, w_sep) if len(by) == 0: raise oefmt(space.w_ValueError, "empty separator") res = rsplit(value, by, maxsplit) return self._newlist_unwrapped(space, res)
def fn(): res = True res = res and split('a//b//c//d', '//') == ['a', 'b', 'c', 'd'] res = res and split(' a\ta\na b') == ['a', 'a', 'a', 'b'] res = res and split('a//b//c//d', '//', 2) == ['a', 'b', 'c//d'] res = res and split('abcd,efghi', ',') == ['abcd', 'efghi'] res = res and split(u'a//b//c//d', u'//') == [u'a', u'b', u'c', u'd'] res = res and split(u'endcase test', u'test') == [u'endcase ', u''] res = res and rsplit('a|b|c|d', '|', 2) == ['a|b', 'c', 'd'] res = res and rsplit('a//b//c//d', '//') == ['a', 'b', 'c', 'd'] res = res and rsplit(u'a|b|c|d', u'|') == [u'a', u'b', u'c', u'd'] res = res and rsplit(u'a|b|c|d', u'|', 2) == [u'a|b', u'c', u'd'] res = res and rsplit(u'a//b//c//d', u'//') == [u'a', u'b', u'c', u'd'] return res
def fn(): res = True res = res and split("a//b//c//d", "//") == ["a", "b", "c", "d"] res = res and split(" a\ta\na b") == ["a", "a", "a", "b"] res = res and split("a//b//c//d", "//", 2) == ["a", "b", "c//d"] res = res and split("abcd,efghi", ",") == ["abcd", "efghi"] res = res and split(u"a//b//c//d", u"//") == [u"a", u"b", u"c", u"d"] res = res and split(u"endcase test", u"test") == [u"endcase ", u""] res = res and rsplit("a|b|c|d", "|", 2) == ["a|b", "c", "d"] res = res and rsplit("a//b//c//d", "//") == ["a", "b", "c", "d"] res = res and rsplit(u"a|b|c|d", u"|") == [u"a", u"b", u"c", u"d"] res = res and rsplit(u"a|b|c|d", u"|", 2) == [u"a|b", u"c", u"d"] res = res and rsplit(u"a//b//c//d", u"//") == [u"a", u"b", u"c", u"d"] return res
def str_rsplit__String_String_ANY(space, w_self, w_by, w_maxsplit=-1): maxsplit = space.int_w(w_maxsplit) value = w_self._value by = w_by._value if not by: raise OperationError(space.w_ValueError, space.wrap("empty separator")) return space.newlist_str(rsplit(value, by, maxsplit))
def test_rsplit_unicode(): assert rsplit(u"a", u"a", 1) == [u'', u''] assert rsplit(u" ", u" ", 1) == [u'', u''] assert rsplit(u"aa", u"a", 2) == [u'', u'', u''] assert rsplit(u'a|b|c|d', u'|') == [u'a', u'b', u'c', u'd'] assert rsplit(u'a|b|c|d', u'|', 2) == [u'a|b', u'c', u'd'] assert rsplit(u'a//b//c//d', u'//') == [u'a', u'b', u'c', u'd'] assert rsplit(u'endcase test', u'test') == [u'endcase ', u''] py.test.raises(ValueError, rsplit, u"abc", u'')
def test_rsplit_unicode(): assert rsplit(u"a", u"a", 1) == [u"", u""] assert rsplit(u" ", u" ", 1) == [u"", u""] assert rsplit(u"aa", u"a", 2) == [u"", u"", u""] assert rsplit(u"a|b|c|d", u"|") == [u"a", u"b", u"c", u"d"] assert rsplit(u"a|b|c|d", u"|", 2) == [u"a|b", u"c", u"d"] assert rsplit(u"a//b//c//d", u"//") == [u"a", u"b", u"c", u"d"] assert rsplit(u"endcase test", u"test") == [u"endcase ", u""] py.test.raises(ValueError, rsplit, u"abc", u"")
def test_rsplit(): assert rsplit("a", "a", 1) == ['', ''] assert rsplit(" ", " ", 1) == ['', ''] assert rsplit("aa", "a", 2) == ['', '', ''] assert rsplit('a|b|c|d', '|') == ['a', 'b', 'c', 'd'] assert rsplit('a|b|c|d', '|', 2) == ['a|b', 'c', 'd'] assert rsplit('a//b//c//d', '//') == ['a', 'b', 'c', 'd'] assert rsplit('endcase test', 'test') == ['endcase ', ''] py.test.raises(ValueError, rsplit, "abc", '')
def __init__(self, space, pto): bases_w = space.fixedview(from_ref(space, pto.c_tp_bases)) dict_w = {} add_operators(space, dict_w, pto) convert_method_defs(space, dict_w, pto.c_tp_methods, self) convert_getset_defs(space, dict_w, pto.c_tp_getset, self) convert_member_defs(space, dict_w, pto.c_tp_members, self) full_name = rffi.charp2str(pto.c_tp_name) if '.' in full_name: module_name, extension_name = rsplit(full_name, ".", 1) dict_w["__module__"] = space.wrap(module_name) else: extension_name = full_name W_TypeObject.__init__(self, space, extension_name, bases_w or [space.w_object], dict_w) if not space.is_true(space.issubtype(self, space.w_type)): self.flag_cpytype = True self.flag_heaptype = False if pto.c_tp_doc: self.w_doc = space.wrap(rffi.charp2str(pto.c_tp_doc))
def String_rsplit(self, sep, maxsplit): out = [] m = maxsplit.value if maxsplit else -1 for s in rsplit(self.string, sep.string, m): out.append(String(s)) return space.List(out)
def test_rsplit_None(): assert rsplit("") == [] assert rsplit(' a\ta\na b') == ['a', 'a', 'a', 'b'] assert rsplit(" a a ", maxsplit=1) == [' a', 'a']
def test_rsplit_None(): assert rsplit("") == [] assert rsplit(" a\ta\na b") == ["a", "a", "a", "b"] assert rsplit(" a a ", maxsplit=1) == [" a", "a"]
def str_rsplit__String_None_ANY(space, w_self, w_none, w_maxsplit=-1): maxsplit = space.int_w(w_maxsplit) value = w_self._value res = rsplit(value, maxsplit=maxsplit) return space.newlist_str(res)
def test_rsplit_utf8(): assert rsplit('', 'a', isutf8=1) == [''] assert rsplit('baba', 'a', isutf8=1) == ['b', 'b', ''] assert rsplit('b b', isutf8=1) == ['b', 'b'] assert rsplit('b\xe1\x9a\x80b', isutf8=1) == ['b', 'b'] assert rsplit('b\xe1\x9a\x80', isutf8=1) == ['b']
def tokenize(s): "Convert a string into a list of tokens." return rsplit(replace(replace(s, '(', ' ( '), ')', ' ) '))