Python operator.setslice() Examples
The following are 20
code examples of operator.setslice().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
operator
, or try the search function
.
Example #1
Source File: test_slicing.py From oss-ftp with MIT License | 5 votes |
def test_wchar_ptr(self): s = u"abcdefghijklmnopqrstuvwxyz\0" dll = CDLL(_ctypes_test.__file__) dll.my_wcsdup.restype = POINTER(c_wchar) dll.my_wcsdup.argtypes = POINTER(c_wchar), dll.my_free.restype = None res = dll.my_wcsdup(s) self.assertEqual(res[:len(s)], s) self.assertEqual(res[:len(s):], s) self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) import operator self.assertRaises(TypeError, operator.setslice, res, 0, 5, u"abcde") self.assertRaises(TypeError, operator.setitem, res, slice(0, 5), u"abcde") dll.my_free(res) if sizeof(c_wchar) == sizeof(c_short): dll.my_wcsdup.restype = POINTER(c_short) elif sizeof(c_wchar) == sizeof(c_int): dll.my_wcsdup.restype = POINTER(c_int) elif sizeof(c_wchar) == sizeof(c_long): dll.my_wcsdup.restype = POINTER(c_long) else: self.skipTest('Pointers to c_wchar are not supported') res = dll.my_wcsdup(s) tmpl = range(ord("a"), ord("z")+1) self.assertEqual(res[:len(s)-1], tmpl) self.assertEqual(res[:len(s)-1:], tmpl) self.assertEqual(res[len(s)-2:-1:-1], tmpl[::-1]) self.assertEqual(res[len(s)-2:5:-7], tmpl[:5:-7]) dll.my_free(res) ################################################################
Example #2
Source File: test_operator.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_setslice(self): a = range(4) self.failUnlessRaises(TypeError, operator.setslice, a) self.failUnlessRaises(TypeError, operator.setslice, a, None, None, None) self.failUnless(operator.setslice(a, 1, 3, [2, 1]) is None) self.assert_(a == [0, 2, 1, 3]) operator.setslice(a, 0, test_support.MAX_Py_ssize_t, []) self.assert_(a == [])
Example #3
Source File: test_operator.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_setslice(self): a = range(4) self.failUnlessRaises(TypeError, operator.setslice, a) self.failUnlessRaises(TypeError, operator.setslice, a, None, None, None) self.failUnless(operator.setslice(a, 1, 3, [2, 1]) is None) self.assert_(a == [0, 2, 1, 3]) operator.setslice(a, 0, test_support.MAX_Py_ssize_t, []) self.assert_(a == [])
Example #4
Source File: test_operator.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_setslice(self): a = range(4) self.failUnlessRaises(TypeError, operator.setslice, a) self.failUnlessRaises(TypeError, operator.setslice, a, None, None, None) self.failUnless(operator.setslice(a, 1, 3, [2, 1]) is None) self.assert_(a == [0, 2, 1, 3]) operator.setslice(a, 0, test_support.MAX_Py_ssize_t, []) self.assert_(a == [])
Example #5
Source File: expr.py From owasp-pysec with Apache License 2.0 | 5 votes |
def __setslice__(self, key, value): return Expression((self, key, value), operator.setslice)
Example #6
Source File: test_slicing.py From datafari with Apache License 2.0 | 5 votes |
def test_wchar_ptr(self): s = u"abcdefghijklmnopqrstuvwxyz\0" dll = CDLL(_ctypes_test.__file__) dll.my_wcsdup.restype = POINTER(c_wchar) dll.my_wcsdup.argtypes = POINTER(c_wchar), dll.my_free.restype = None res = dll.my_wcsdup(s) self.assertEqual(res[:len(s)], s) self.assertEqual(res[:len(s):], s) self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) import operator self.assertRaises(TypeError, operator.setslice, res, 0, 5, u"abcde") self.assertRaises(TypeError, operator.setitem, res, slice(0, 5), u"abcde") dll.my_free(res) if sizeof(c_wchar) == sizeof(c_short): dll.my_wcsdup.restype = POINTER(c_short) elif sizeof(c_wchar) == sizeof(c_int): dll.my_wcsdup.restype = POINTER(c_int) elif sizeof(c_wchar) == sizeof(c_long): dll.my_wcsdup.restype = POINTER(c_long) else: self.skipTest('Pointers to c_wchar are not supported') res = dll.my_wcsdup(s) tmpl = range(ord("a"), ord("z")+1) self.assertEqual(res[:len(s)-1], tmpl) self.assertEqual(res[:len(s)-1:], tmpl) self.assertEqual(res[len(s)-2:-1:-1], tmpl[::-1]) self.assertEqual(res[len(s)-2:5:-7], tmpl[:5:-7]) dll.my_free(res) ################################################################
Example #7
Source File: test_slicing.py From datafari with Apache License 2.0 | 5 votes |
def test_char_ptr(self): s = "abcdefghijklmnopqrstuvwxyz" dll = CDLL(_ctypes_test.__file__) dll.my_strdup.restype = POINTER(c_char) dll.my_free.restype = None res = dll.my_strdup(s) self.assertEqual(res[:len(s)], s) self.assertEqual(res[:3], s[:3]) self.assertEqual(res[:len(s):], s) self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) self.assertEqual(res[0:-1:-1], s[0::-1]) import operator self.assertRaises(ValueError, operator.getitem, res, slice(None, None, None)) self.assertRaises(ValueError, operator.getitem, res, slice(0, None, None)) self.assertRaises(ValueError, operator.getitem, res, slice(None, 5, -1)) self.assertRaises(ValueError, operator.getitem, res, slice(-5, None, None)) self.assertRaises(TypeError, operator.setslice, res, 0, 5, u"abcde") self.assertRaises(TypeError, operator.setitem, res, slice(0, 5), u"abcde") dll.my_free(res) dll.my_strdup.restype = POINTER(c_byte) res = dll.my_strdup(s) self.assertEqual(res[:len(s)], range(ord("a"), ord("z")+1)) self.assertEqual(res[:len(s):], range(ord("a"), ord("z")+1)) dll.my_free(res)
Example #8
Source File: test_slicing.py From datafari with Apache License 2.0 | 5 votes |
def test_setslice_cint(self): a = (c_int * 100)(*xrange(1100, 1200)) b = range(1100, 1200) a[32:47] = range(32, 47) self.assertEqual(a[32:47], range(32, 47)) a[32:47] = range(132, 147) self.assertEqual(a[32:47:], range(132, 147)) a[46:31:-1] = range(232, 247) self.assertEqual(a[32:47:1], range(246, 231, -1)) a[32:47] = range(1132, 1147) self.assertEqual(a[:], b) a[32:47:7] = range(3) b[32:47:7] = range(3) self.assertEqual(a[:], b) a[33::-3] = range(12) b[33::-3] = range(12) self.assertEqual(a[:], b) from operator import setslice, setitem # TypeError: int expected instead of str instance self.assertRaises(TypeError, setslice, a, 0, 5, "abcde") self.assertRaises(TypeError, setitem, a, slice(0, 5), "abcde") # TypeError: int expected instead of str instance self.assertRaises(TypeError, setslice, a, 0, 5, ["a", "b", "c", "d", "e"]) self.assertRaises(TypeError, setitem, a, slice(0, 5), ["a", "b", "c", "d", "e"]) # TypeError: int expected instead of float instance self.assertRaises(TypeError, setslice, a, 0, 5, [1, 2, 3, 4, 3.14]) self.assertRaises(TypeError, setitem, a, slice(0, 5), [1, 2, 3, 4, 3.14]) # ValueError: Can only assign sequence of same size self.assertRaises(ValueError, setslice, a, 0, 5, range(32)) self.assertRaises(ValueError, setitem, a, slice(0, 5), range(32))
Example #9
Source File: test_operator.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_setslice(self): a = range(4) self.assertRaises(TypeError, operator.setslice, a) self.assertRaises(TypeError, operator.setslice, a, None, None, None) self.assertTrue(operator.setslice(a, 1, 3, [2, 1]) is None) self.assertTrue(a == [0, 2, 1, 3]) operator.setslice(a, 0, test_support.MAX_Py_ssize_t, []) self.assertTrue(a == [])
Example #10
Source File: test_operator.py From oss-ftp with MIT License | 5 votes |
def test_setslice(self): a = range(4) self.assertRaises(TypeError, operator.setslice, a) self.assertRaises(TypeError, operator.setslice, a, None, None, None) self.assertTrue(operator.setslice(a, 1, 3, [2, 1]) is None) self.assertTrue(a == [0, 2, 1, 3]) operator.setslice(a, 0, test_support.MAX_Py_ssize_t, []) self.assertTrue(a == [])
Example #11
Source File: test_slicing.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_setslice_cint(self): a = (c_int * 100)(*xrange(1100, 1200)) b = range(1100, 1200) a[32:47] = range(32, 47) self.assertEqual(a[32:47], range(32, 47)) a[32:47] = range(132, 147) self.assertEqual(a[32:47:], range(132, 147)) a[46:31:-1] = range(232, 247) self.assertEqual(a[32:47:1], range(246, 231, -1)) a[32:47] = range(1132, 1147) self.assertEqual(a[:], b) a[32:47:7] = range(3) b[32:47:7] = range(3) self.assertEqual(a[:], b) a[33::-3] = range(12) b[33::-3] = range(12) self.assertEqual(a[:], b) from operator import setslice, setitem # TypeError: int expected instead of str instance self.assertRaises(TypeError, setslice, a, 0, 5, "abcde") self.assertRaises(TypeError, setitem, a, slice(0, 5), "abcde") # TypeError: int expected instead of str instance self.assertRaises(TypeError, setslice, a, 0, 5, ["a", "b", "c", "d", "e"]) self.assertRaises(TypeError, setitem, a, slice(0, 5), ["a", "b", "c", "d", "e"]) # TypeError: int expected instead of float instance self.assertRaises(TypeError, setslice, a, 0, 5, [1, 2, 3, 4, 3.14]) self.assertRaises(TypeError, setitem, a, slice(0, 5), [1, 2, 3, 4, 3.14]) # ValueError: Can only assign sequence of same size self.assertRaises(ValueError, setslice, a, 0, 5, range(32)) self.assertRaises(ValueError, setitem, a, slice(0, 5), range(32))
Example #12
Source File: test_slicing.py From oss-ftp with MIT License | 5 votes |
def test_char_ptr(self): s = "abcdefghijklmnopqrstuvwxyz" dll = CDLL(_ctypes_test.__file__) dll.my_strdup.restype = POINTER(c_char) dll.my_free.restype = None res = dll.my_strdup(s) self.assertEqual(res[:len(s)], s) self.assertEqual(res[:3], s[:3]) self.assertEqual(res[:len(s):], s) self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) self.assertEqual(res[0:-1:-1], s[0::-1]) import operator self.assertRaises(ValueError, operator.getitem, res, slice(None, None, None)) self.assertRaises(ValueError, operator.getitem, res, slice(0, None, None)) self.assertRaises(ValueError, operator.getitem, res, slice(None, 5, -1)) self.assertRaises(ValueError, operator.getitem, res, slice(-5, None, None)) self.assertRaises(TypeError, operator.setslice, res, 0, 5, u"abcde") self.assertRaises(TypeError, operator.setitem, res, slice(0, 5), u"abcde") dll.my_free(res) dll.my_strdup.restype = POINTER(c_byte) res = dll.my_strdup(s) self.assertEqual(res[:len(s)], range(ord("a"), ord("z")+1)) self.assertEqual(res[:len(s):], range(ord("a"), ord("z")+1)) dll.my_free(res)
Example #13
Source File: test_slicing.py From oss-ftp with MIT License | 5 votes |
def test_setslice_cint(self): a = (c_int * 100)(*xrange(1100, 1200)) b = range(1100, 1200) a[32:47] = range(32, 47) self.assertEqual(a[32:47], range(32, 47)) a[32:47] = range(132, 147) self.assertEqual(a[32:47:], range(132, 147)) a[46:31:-1] = range(232, 247) self.assertEqual(a[32:47:1], range(246, 231, -1)) a[32:47] = range(1132, 1147) self.assertEqual(a[:], b) a[32:47:7] = range(3) b[32:47:7] = range(3) self.assertEqual(a[:], b) a[33::-3] = range(12) b[33::-3] = range(12) self.assertEqual(a[:], b) from operator import setslice, setitem # TypeError: int expected instead of str instance self.assertRaises(TypeError, setslice, a, 0, 5, "abcde") self.assertRaises(TypeError, setitem, a, slice(0, 5), "abcde") # TypeError: int expected instead of str instance self.assertRaises(TypeError, setslice, a, 0, 5, ["a", "b", "c", "d", "e"]) self.assertRaises(TypeError, setitem, a, slice(0, 5), ["a", "b", "c", "d", "e"]) # TypeError: int expected instead of float instance self.assertRaises(TypeError, setslice, a, 0, 5, [1, 2, 3, 4, 3.14]) self.assertRaises(TypeError, setitem, a, slice(0, 5), [1, 2, 3, 4, 3.14]) # ValueError: Can only assign sequence of same size self.assertRaises(ValueError, setslice, a, 0, 5, range(32)) self.assertRaises(ValueError, setitem, a, slice(0, 5), range(32))
Example #14
Source File: test_operator.py From BinderFilter with MIT License | 5 votes |
def test_setslice(self): a = range(4) self.assertRaises(TypeError, operator.setslice, a) self.assertRaises(TypeError, operator.setslice, a, None, None, None) self.assertTrue(operator.setslice(a, 1, 3, [2, 1]) is None) self.assertTrue(a == [0, 2, 1, 3]) operator.setslice(a, 0, test_support.MAX_Py_ssize_t, []) self.assertTrue(a == [])
Example #15
Source File: test_slicing.py From BinderFilter with MIT License | 5 votes |
def test_wchar_ptr(self): s = u"abcdefghijklmnopqrstuvwxyz\0" dll = CDLL(_ctypes_test.__file__) dll.my_wcsdup.restype = POINTER(c_wchar) dll.my_wcsdup.argtypes = POINTER(c_wchar), dll.my_free.restype = None res = dll.my_wcsdup(s) self.assertEqual(res[:len(s)], s) self.assertEqual(res[:len(s):], s) self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) import operator self.assertRaises(TypeError, operator.setslice, res, 0, 5, u"abcde") self.assertRaises(TypeError, operator.setitem, res, slice(0, 5), u"abcde") dll.my_free(res) if sizeof(c_wchar) == sizeof(c_short): dll.my_wcsdup.restype = POINTER(c_short) elif sizeof(c_wchar) == sizeof(c_int): dll.my_wcsdup.restype = POINTER(c_int) elif sizeof(c_wchar) == sizeof(c_long): dll.my_wcsdup.restype = POINTER(c_long) else: return res = dll.my_wcsdup(s) tmpl = range(ord("a"), ord("z")+1) self.assertEqual(res[:len(s)-1], tmpl) self.assertEqual(res[:len(s)-1:], tmpl) self.assertEqual(res[len(s)-2:-1:-1], tmpl[::-1]) self.assertEqual(res[len(s)-2:5:-7], tmpl[:5:-7]) dll.my_free(res) ################################################################
Example #16
Source File: test_slicing.py From BinderFilter with MIT License | 5 votes |
def test_char_ptr(self): s = "abcdefghijklmnopqrstuvwxyz" dll = CDLL(_ctypes_test.__file__) dll.my_strdup.restype = POINTER(c_char) dll.my_free.restype = None res = dll.my_strdup(s) self.assertEqual(res[:len(s)], s) self.assertEqual(res[:3], s[:3]) self.assertEqual(res[:len(s):], s) self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) self.assertEqual(res[0:-1:-1], s[0::-1]) import operator self.assertRaises(ValueError, operator.getitem, res, slice(None, None, None)) self.assertRaises(ValueError, operator.getitem, res, slice(0, None, None)) self.assertRaises(ValueError, operator.getitem, res, slice(None, 5, -1)) self.assertRaises(ValueError, operator.getitem, res, slice(-5, None, None)) self.assertRaises(TypeError, operator.setslice, res, 0, 5, u"abcde") self.assertRaises(TypeError, operator.setitem, res, slice(0, 5), u"abcde") dll.my_free(res) dll.my_strdup.restype = POINTER(c_byte) res = dll.my_strdup(s) self.assertEqual(res[:len(s)], range(ord("a"), ord("z")+1)) self.assertEqual(res[:len(s):], range(ord("a"), ord("z")+1)) dll.my_free(res)
Example #17
Source File: test_slicing.py From BinderFilter with MIT License | 5 votes |
def test_setslice_cint(self): a = (c_int * 100)(*xrange(1100, 1200)) b = range(1100, 1200) a[32:47] = range(32, 47) self.assertEqual(a[32:47], range(32, 47)) a[32:47] = range(132, 147) self.assertEqual(a[32:47:], range(132, 147)) a[46:31:-1] = range(232, 247) self.assertEqual(a[32:47:1], range(246, 231, -1)) a[32:47] = range(1132, 1147) self.assertEqual(a[:], b) a[32:47:7] = range(3) b[32:47:7] = range(3) self.assertEqual(a[:], b) a[33::-3] = range(12) b[33::-3] = range(12) self.assertEqual(a[:], b) from operator import setslice, setitem # TypeError: int expected instead of str instance self.assertRaises(TypeError, setslice, a, 0, 5, "abcde") self.assertRaises(TypeError, setitem, a, slice(0, 5), "abcde") # TypeError: int expected instead of str instance self.assertRaises(TypeError, setslice, a, 0, 5, ["a", "b", "c", "d", "e"]) self.assertRaises(TypeError, setitem, a, slice(0, 5), ["a", "b", "c", "d", "e"]) # TypeError: int expected instead of float instance self.assertRaises(TypeError, setslice, a, 0, 5, [1, 2, 3, 4, 3.14]) self.assertRaises(TypeError, setitem, a, slice(0, 5), [1, 2, 3, 4, 3.14]) # ValueError: Can only assign sequence of same size self.assertRaises(ValueError, setslice, a, 0, 5, range(32)) self.assertRaises(ValueError, setitem, a, slice(0, 5), range(32))
Example #18
Source File: test_operator.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_setslice(self): a = range(4) self.assertRaises(TypeError, operator.setslice, a) self.assertRaises(TypeError, operator.setslice, a, None, None, None) self.assertTrue(operator.setslice(a, 1, 3, [2, 1]) is None) self.assertTrue(a == [0, 2, 1, 3]) operator.setslice(a, 0, test_support.MAX_Py_ssize_t, []) self.assertTrue(a == [])
Example #19
Source File: test_slicing.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_wchar_ptr(self): s = u"abcdefghijklmnopqrstuvwxyz\0" dll = CDLL(_ctypes_test.__file__) dll.my_wcsdup.restype = POINTER(c_wchar) dll.my_wcsdup.argtypes = POINTER(c_wchar), dll.my_free.restype = None res = dll.my_wcsdup(s) self.assertEqual(res[:len(s)], s) self.assertEqual(res[:len(s):], s) self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) import operator self.assertRaises(TypeError, operator.setslice, res, 0, 5, u"abcde") self.assertRaises(TypeError, operator.setitem, res, slice(0, 5), u"abcde") dll.my_free(res) if sizeof(c_wchar) == sizeof(c_short): dll.my_wcsdup.restype = POINTER(c_short) elif sizeof(c_wchar) == sizeof(c_int): dll.my_wcsdup.restype = POINTER(c_int) elif sizeof(c_wchar) == sizeof(c_long): dll.my_wcsdup.restype = POINTER(c_long) else: self.skipTest('Pointers to c_wchar are not supported') res = dll.my_wcsdup(s) tmpl = range(ord("a"), ord("z")+1) self.assertEqual(res[:len(s)-1], tmpl) self.assertEqual(res[:len(s)-1:], tmpl) self.assertEqual(res[len(s)-2:-1:-1], tmpl[::-1]) self.assertEqual(res[len(s)-2:5:-7], tmpl[:5:-7]) dll.my_free(res) ################################################################
Example #20
Source File: test_slicing.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_char_ptr(self): s = "abcdefghijklmnopqrstuvwxyz" dll = CDLL(_ctypes_test.__file__) dll.my_strdup.restype = POINTER(c_char) dll.my_free.restype = None res = dll.my_strdup(s) self.assertEqual(res[:len(s)], s) self.assertEqual(res[:3], s[:3]) self.assertEqual(res[:len(s):], s) self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) self.assertEqual(res[0:-1:-1], s[0::-1]) import operator self.assertRaises(ValueError, operator.getitem, res, slice(None, None, None)) self.assertRaises(ValueError, operator.getitem, res, slice(0, None, None)) self.assertRaises(ValueError, operator.getitem, res, slice(None, 5, -1)) self.assertRaises(ValueError, operator.getitem, res, slice(-5, None, None)) self.assertRaises(TypeError, operator.setslice, res, 0, 5, u"abcde") self.assertRaises(TypeError, operator.setitem, res, slice(0, 5), u"abcde") dll.my_free(res) dll.my_strdup.restype = POINTER(c_byte) res = dll.my_strdup(s) self.assertEqual(res[:len(s)], range(ord("a"), ord("z")+1)) self.assertEqual(res[:len(s):], range(ord("a"), ord("z")+1)) dll.my_free(res)