当前位置: 首页>>代码示例>>Python>>正文


Python ctypes.BigEndianStructure方法代码示例

本文整理汇总了Python中ctypes.BigEndianStructure方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.BigEndianStructure方法的具体用法?Python ctypes.BigEndianStructure怎么用?Python ctypes.BigEndianStructure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


在下文中一共展示了ctypes.BigEndianStructure方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_super_init_not_called_regression

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import BigEndianStructure [as 别名]
def test_super_init_not_called_regression(self):
        # This should not emit a super-init-not-called
        # warning. It previously did this, because
        # ``next(node.infer())`` was used in that checker's
        # logic and the first inferred node was an Uninferable object,
        # leading to this false positive.
        node = astroid.extract_node(
            """
        import ctypes

        class Foo(ctypes.BigEndianStructure):
            def __init__(self): #@
                ctypes.BigEndianStructure.__init__(self)
        """
        )
        with self.assertNoMessages():
            self.checker.visit_functiondef(node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:19,代码来源:unittest_checker_classes.py

示例2: __init__

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import BigEndianStructure [as 别名]
def __init__(self, ei_class, ei_data):
        if ei_class not in (ELFCLASS32, ELFCLASS64):
            raise ValueError("Unknown ei_class=%d" % ei_class)
        if ei_data not in (ELFDATA2LSB, ELFDATA2MSB):
            raise ValueError("Unknown ei_data=%d" % ei_data)

        self.ei_class = ei_class
        self.ei_data = ei_data

        if self.ei_class == ELFCLASS32:
            self.wordsize = 32
        elif self.ei_class == ELFCLASS64:
            self.wordsize = 64

        if self.ei_data == ELFDATA2LSB:
            self.structure = LittleEndianStructure
            self.endianess = "LSB"
        elif self.ei_data == ELFDATA2MSB:
            self.structure = BigEndianStructure
            self.endianess = "MSB" 
开发者ID:wapiflapi,项目名称:wsym,代码行数:22,代码来源:elf.py

示例3: get_base_class_and_magic_number

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import BigEndianStructure [as 别名]
def get_base_class_and_magic_number(lib_file, seek=None):
    if seek is None:
        seek = lib_file.tell()
    else:
        lib_file.seek(seek)
    magic_number = ctypes.c_uint32.from_buffer_copy(
        lib_file.read(ctypes.sizeof(ctypes.c_uint32))).value

    # Handle wrong byte order
    if magic_number in [FAT_CIGAM, FAT_CIGAM_64, MH_CIGAM, MH_CIGAM_64]:
        if sys.byteorder == "little":
            BaseClass = ctypes.BigEndianStructure
        else:
            BaseClass = ctypes.LittleEndianStructure

        magic_number = swap32(magic_number)
    else:
        BaseClass = ctypes.Structure

    lib_file.seek(seek)
    return BaseClass, magic_number 
开发者ID:ali5h,项目名称:rules_pip,代码行数:23,代码来源:macosx_libfile.py

示例4: test_big_endian_structure_packed

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import BigEndianStructure [as 别名]
def test_big_endian_structure_packed(self):
        class BigEndStruct(ctypes.BigEndianStructure):
            _fields_ = [
                ('one', ctypes.c_uint8),
                ('two', ctypes.c_uint32)
            ]
            _pack_ = 1
        expected = np.dtype([('one', 'u1'), ('two', '>u4')])
        self.check(BigEndStruct, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_dtype.py

示例5: test_big_endian_structure

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import BigEndianStructure [as 别名]
def test_big_endian_structure(self):
        class PaddedStruct(ctypes.BigEndianStructure):
            _fields_ = [
                ('a', ctypes.c_uint8),
                ('b', ctypes.c_uint16)
            ]
        expected = np.dtype([
            ('a', '>B'),
            ('b', '>H')
        ], align=True)
        self.check(PaddedStruct, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_dtype.py

示例6: test_memoryview_tobytes

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import BigEndianStructure [as 别名]
def test_memoryview_tobytes(self):
        # Many implicit tests are already in self.verify().

        t = (-529, 576, -625, 676, -729)

        nd = ndarray(t, shape=[5], format='@h')
        m = memoryview(nd)
        self.assertEqual(m, nd)
        self.assertEqual(m.tobytes(), nd.tobytes())

        nd = ndarray([t], shape=[1], format='>hQiLl')
        m = memoryview(nd)
        self.assertEqual(m, nd)
        self.assertEqual(m.tobytes(), nd.tobytes())

        nd = ndarray([t for _ in range(12)], shape=[2,2,3], format='=hQiLl')
        m = memoryview(nd)
        self.assertEqual(m, nd)
        self.assertEqual(m.tobytes(), nd.tobytes())

        nd = ndarray([t for _ in range(120)], shape=[5,2,2,3,2],
                     format='<hQiLl')
        m = memoryview(nd)
        self.assertEqual(m, nd)
        self.assertEqual(m.tobytes(), nd.tobytes())

        # Unknown formats are handled: tobytes() purely depends on itemsize.
        if ctypes:
            # format: "T{>l:x:>l:y:}"
            class BEPoint(ctypes.BigEndianStructure):
                _fields_ = [("x", ctypes.c_long), ("y", ctypes.c_long)]
            point = BEPoint(100, 200)
            a = memoryview(point)
            self.assertEqual(a.tobytes(), bytes(point)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:36,代码来源:test_buffer.py

示例7: test_memoryview_compare_special_cases

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import BigEndianStructure [as 别名]
def test_memoryview_compare_special_cases(self):

        a = array.array('L', [1, 2, 3])
        b = array.array('L', [1, 2, 7])

        # Ordering comparisons raise:
        v = memoryview(a)
        w = memoryview(b)
        for attr in ('__lt__', '__le__', '__gt__', '__ge__'):
            self.assertIs(getattr(v, attr)(w), NotImplemented)
            self.assertIs(getattr(a, attr)(v), NotImplemented)

        # Released views compare equal to themselves:
        v = memoryview(a)
        v.release()
        self.assertEqual(v, v)
        self.assertNotEqual(v, a)
        self.assertNotEqual(a, v)

        v = memoryview(a)
        w = memoryview(a)
        w.release()
        self.assertNotEqual(v, w)
        self.assertNotEqual(w, v)

        # Operand does not implement the buffer protocol:
        v = memoryview(a)
        self.assertNotEqual(v, [1, 2, 3])

        # NaNs
        nd = ndarray([(0, 0)], shape=[1], format='l x d x', flags=ND_WRITABLE)
        nd[0] = (-1, float('nan'))
        self.assertNotEqual(memoryview(nd), nd)

        # Depends on issue #15625: the struct module does not understand 'u'.
        a = array.array('u', 'xyz')
        v = memoryview(a)
        self.assertNotEqual(a, v)
        self.assertNotEqual(v, a)

        # Some ctypes format strings are unknown to the struct module.
        if ctypes:
            # format: "T{>l:x:>l:y:}"
            class BEPoint(ctypes.BigEndianStructure):
                _fields_ = [("x", ctypes.c_long), ("y", ctypes.c_long)]
            point = BEPoint(100, 200)
            a = memoryview(point)
            b = memoryview(point)
            self.assertNotEqual(a, b)
            self.assertNotEqual(a, point)
            self.assertNotEqual(point, a)
            self.assertRaises(NotImplementedError, a.tolist) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:54,代码来源:test_buffer.py


注:本文中的ctypes.BigEndianStructure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。