Python operator.__getitem__() Examples

The following are 5 code examples of operator.__getitem__(). 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_solve.py    From pyx with GNU General Public License v2.0 6 votes vote down vote up
def testAccess(self):
        A = matrix([2, 3])
        self.failUnlessEqual(str(A), "unnamed_matrix{=((unnamed_matrix[0, 0], unnamed_matrix[0, 1], unnamed_matrix[0, 2]), (unnamed_matrix[1, 0], unnamed_matrix[1, 1], unnamed_matrix[1, 2]))}")
        self.failUnlessEqual(A[0, 0].is_set(), 0)
        self.failUnlessEqual(A[1, 0].is_set(), 0)
        self.failUnlessRaises(IndexError, operator.__getitem__, A, (2, 0))
        self.failUnlessEqual(A[0, 1].is_set(), 0)
        self.failUnlessEqual(A[1, 1].is_set(), 0)
        self.failUnlessEqual(A[0, 2].is_set(), 0)
        self.failUnlessEqual(A[1, 2].is_set(), 0)
        self.failUnlessRaises(IndexError, operator.__getitem__, A, (0, 3))
        A[0, 0].set(1)
        self.failUnlessEqual(A[0, 0].is_set(), 1)
        self.failUnlessEqual(A[0, 1].is_set(), 0)
        self.failUnlessEqual(A[1, 0].is_set(), 0)
        self.failUnlessAlmostEqual(A[0, 0].get(), 1.0)
        self.failUnlessAlmostEqual(float(A[0, 0]), 1.0) 
Example #2
Source File: function.py    From ida-minsc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def decompile(cls, ea):
        '''(UNSTABLE) Returns the decompiled code of the basic block at the address `ea`.'''
        source = idaapi.decompile(ea)

        res = itertools.imap(functools.partial(operator.__getitem__, source.eamap), cls.iterate(ea))
        res = itertools.chain(*res)
        formatted = reduce(lambda t, c: t if t[-1].ea == c.ea else t+[c], res, [next(res)])

        res = []
        # FIXME: This has been pretty damn unstable in my tests.
        try:
            for fmt in formatted:
                res.append( fmt.print1(source.__deref__()) )
        except TypeError: pass
        res = itertools.imap(idaapi.tag_remove, res)
        return '\n'.join(map(utils.string.of, res)) 
Example #3
Source File: basemapping.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def testIReadMapping(self, inst, state, absent):
    for key in state:
        self.assertEqual(inst[key], state[key])
        self.assertEqual(inst.get(key, None), state[key])
        self.assertTrue(key in inst)

    for key in absent:
        self.assertEqual(inst.get(key, None), None)
        self.assertEqual(inst.get(key), None)
        self.assertEqual(inst.get(key, self), self)
        self.assertRaises(KeyError, __getitem__, inst, key) 
Example #4
Source File: basemapping.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def testIReadMapping(self, inst, state, absent):
    for key in state:
        self.assertEqual(inst[key], state[key])
        self.assertEqual(inst.get(key, None), state[key])
        self.assertTrue(key in inst)

    for key in absent:
        self.assertEqual(inst.get(key, None), None)
        self.assertEqual(inst.get(key), None)
        self.assertEqual(inst.get(key, self), self)
        self.assertRaises(KeyError, __getitem__, inst, key) 
Example #5
Source File: basemapping.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def testIReadMapping(self, inst, state, absent):
    for key in state:
        self.assertEqual(inst[key], state[key])
        self.assertEqual(inst.get(key, None), state[key])
        self.failUnless(key in inst)

    for key in absent:
        self.assertEqual(inst.get(key, None), None)
        self.assertEqual(inst.get(key), None)
        self.assertEqual(inst.get(key, self), self)
        self.assertRaises(KeyError, __getitem__, inst, key)