Python operator 模块,__getitem__() 实例源码

我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用operator.__getitem__()

项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def decompile(cls, ea):
        '''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
        source = idaapi.decompile(ea)

        res = map(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: pretty damn unstable
        try:
            for fmt in formatted:
                res.append( fmt.print1(source.__deref__()) )
        except TypeError: pass
        return '\n'.join(map(idaapi.tag_remove,res))

# function frame attributes
# FIXME: put these in their own object and replace them with aliases
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def decompile(cls, ea):
        '''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
        source = idaapi.decompile(ea)

        res = map(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 is pretty damn unstable in my tests.
        try:
            for fmt in formatted:
                res.append( fmt.print1(source.__deref__()) )
        except TypeError: pass
        return '\n'.join(map(idaapi.tag_remove,res))

# function frame attributes
# FIXME: put these in their own object and replace them with aliases
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def decompile(cls, ea):
        '''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
        source = idaapi.decompile(ea)

        res = map(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: pretty damn unstable
        try:
            for fmt in formatted:
                res.append( fmt.print1(source.__deref__()) )
        except TypeError: pass
        return '\n'.join(map(idaapi.tag_remove,res))

# function frame attributes
# FIXME: put these in their own object and replace them with aliases
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def decompile(cls, ea):
        '''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
        source = idaapi.decompile(ea)

        res = map(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: pretty damn unstable
        try:
            for fmt in formatted:
                res.append( fmt.print1(source.__deref__()) )
        except TypeError: pass
        return '\n'.join(map(idaapi.tag_remove,res))

# function frame attributes
# FIXME: put these in their own object and replace them with aliases
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def decompile(cls, ea):
        '''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
        source = idaapi.decompile(ea)

        res = map(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 is pretty damn unstable in my tests.
        try:
            for fmt in formatted:
                res.append( fmt.print1(source.__deref__()) )
        except TypeError: pass
        return '\n'.join(map(idaapi.tag_remove,res))

# function frame attributes
# FIXME: put these in their own object and replace them with aliases
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def decompile(cls, ea):
        '''(UNSTABLE) Returns the decompiled code of the basic-block at the address ``ea``.'''
        source = idaapi.decompile(ea)

        res = map(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: pretty damn unstable
        try:
            for fmt in formatted:
                res.append( fmt.print1(source.__deref__()) )
        except TypeError: pass
        return '\n'.join(map(idaapi.tag_remove,res))

# function frame attributes
# FIXME: put these in their own object and replace them with aliases
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
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)
项目:AskTanmay-NLQA-System-    作者:tanmayb123    | 项目源码 | 文件源码
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)
项目:MacHeap    作者:blankwall    | 项目源码 | 文件源码
def _calculate_(self, offset):
        res = self.new(self._object_).a
        res = reduce(operator.__getitem__, self._path_, res)
        return offset - res.getoffset()
项目:MacHeap    作者:blankwall    | 项目源码 | 文件源码
def next(self):
        '''Follow the next pointer to the next header entry.'''
        if self['next'].int():
            return reduce(operator.__getitem__, self._path_, self['next'].d.l)
        raise ValueError("{:s} : Unable to navigate to next pointer : 0x{:x}".format(self['next'].int()))
项目:MacHeap    作者:blankwall    | 项目源码 | 文件源码
def previous(self):
        '''Follow the previous pointer to the previous header entry.'''
        if self['previous'].int():
            return reduce(operator.__getitem__, self._path_, self['previous'].d.l)
        raise ValueError("{:s} : Unable to navigate to previous pointer : 0x{:x}".format(self['previous'].int()))
项目:MacHeap    作者:blankwall    | 项目源码 | 文件源码
def _walk(self, direction):
        '''Yield all the elements in the specified direction.'''
        yield self
        res = direction(self)
        while res.int():
            res = res.d
            res = reduce(operator.__getitem__, self._path_, res.l)
            yield res
            res = direction(res)
        return

    # FIXME: make sure that these return each and every header
项目:MacHeap    作者:blankwall    | 项目源码 | 文件源码
def summary(self):
            mapper = ['.', 'X']
            return str().join(map(mapper.__getitem__, self.iterate()))
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
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)
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def fromStr(cls, string):
        '''Convert string representation of SynchDomain enum e.g.
        'SynchDomain.Time' to SynchDomain objects. It also works with just
        domain strings like 'Time'. The following expressions are True:

        SynchDomain.fromStr(str(SynchDomain.Time)) == SynchDomain.Time
        SynchDomain.fromStr('Time') == SynchDomain.Time
        '''
        domain = string.split('.')
        if len(domain) == 1:
            return __getitem__(cls, domain[0])
        elif len(domain) == 2:
            return __getitem__(cls, domain[1])
        else:
            raise ValueError('Can not convert %s to SynchDomain' % string)