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


Python System.Byte方法代码示例

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


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

示例1: test_byte

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def test_byte(self):
        a = Byte()
        self.assertEqual(type(a), Byte)
        self.assertEqual(a, 0)

        b = a + Byte(1)
        self.assertEqual(b, 1)
        self.assertEqual(type(b), Byte)

        bprime = b * Byte(10)
        self.assertEqual(type(bprime), Byte)

        d = a + Byte(255)
        self.assertEqual(type(d), Byte)

        c = b + Byte(255)
        self.assertEqual(c, 256)
        self.assertEqual(type(c), Int16) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_math.py

示例2: parse_eventargs

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def parse_eventargs(event_args):
        bdaddr = _format_bdaddr(event_args.BluetoothAddress)
        uuids = []
        for u in event_args.Advertisement.ServiceUuids:
            uuids.append(u.ToString())
        data = {}
        for m in event_args.Advertisement.ManufacturerData:
            md = IBuffer(m.Data)
            b = Array.CreateInstance(Byte, md.Length)
            reader = DataReader.FromBuffer(md)
            reader.ReadBytes(b)
            data[m.CompanyId] = bytes(b)
        local_name = event_args.Advertisement.LocalName
        return BLEDevice(
            bdaddr, local_name, event_args, uuids=uuids, manufacturer_data=data
        ) 
开发者ID:hbldh,项目名称:bleak,代码行数:18,代码来源:scanner.py

示例3: test_io_memorystream

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def test_io_memorystream(self):
        import System
        s = System.IO.MemoryStream()
        a = System.Array.CreateInstance(System.Byte, 10)
        b = System.Array.CreateInstance(System.Byte, a.Length)
        for i in range(a.Length):
            a[i] = a.Length - i
        s.Write(a, 0, a.Length)
        result = s.Seek(0, System.IO.SeekOrigin.Begin)
        r = s.Read(b, 0, b.Length)
        self.assertTrue(r == b.Length)
        for i in range(a.Length):
            self.assertEqual(a[i], b[i]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_methoddispatch.py

示例4: test_array_error_message

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def test_array_error_message(self):
        import System
        from IronPythonTest import BinderTest
        
        x = BinderTest.CNoOverloads()
        self.assertRaisesMessage(TypeError, 'expected Array[int], got Array[Byte]', x.M500, System.Array[System.Byte]([1,2,3])) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_methoddispatch.py

示例5: test_bool_asked

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def test_bool_asked(self):
        """check the bool conversion result"""
        import System
        from IronPythonTest.BinderTest import Flag

        for arg in ['a', 3, object(), True]:
            self.target.M204(arg)
            self.assertTrue(Flag.BValue, "argument is %s" % arg)
            Flag.BValue = False
            
        for arg in [0, System.Byte.Parse('0'), System.UInt64.Parse('0'), 0.0, 0L, False, None, tuple(), list()]:
            self.target.M204(arg)
            self.assertTrue(not Flag.BValue, "argument is %s" % (arg,))
            Flag.BValue = True 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_methodbinder1.py

示例6: test_out_int

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def test_out_int(self):
        self._helper(self.target.M701, [], 701, [1, 10L, None, System.Byte.Parse('3')], TypeError)    # not allow to pass in anything 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_methodbinder1.py

示例7: test_ref_bytearr

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def test_ref_bytearr(self):
        from IronPythonTest.BinderTest import COtherConcern, Flag
        import clr
        self.target = COtherConcern()
        
        arr = System.Array[System.Byte]((2,3,4))
        
        res = self.target.M702(arr)
        self.assertEqual(Flag.Value, 702)
        self.assertEqual(type(res), System.Array[System.Byte])
        self.assertEqual(len(res), 0)
        
        i, res = self.target.M703(arr)
        self.assertEqual(Flag.Value, 703)
        self.assertEqual(i, 42)
        self.assertEqual(type(res), System.Array[System.Byte])
        self.assertEqual(len(res), 0)
        
        i, res = self.target.M704(arr, arr)
        self.assertEqual(Flag.Value, 704)
        self.assertEqual(i, 42)
        self.assertEqual(arr, res)
        
        sarr = clr.StrongBox[System.Array[System.Byte]](arr)
        res = self.target.M702(sarr)
        self.assertEqual(Flag.Value, 702)
        self.assertEqual(res, None)
        res = sarr.Value
        self.assertEqual(type(res), System.Array[System.Byte])
        self.assertEqual(len(res), 0)
        
        sarr.Value = arr
        i = self.target.M703(sarr)
        self.assertEqual(Flag.Value, 703)
        self.assertEqual(i, 42)
        self.assertEqual(len(sarr.Value), 0)
        
        i = self.target.M704(arr, sarr)
        self.assertEqual(Flag.Value, 704)
        self.assertEqual(i, 42)
        self.assertEqual(sarr.Value, arr) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:43,代码来源:test_methodbinder1.py

示例8: test_cp13401

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def test_cp13401(self):
        import System
        import copy
        
        #A few special cases
        self.assertEqual(System.Char.MinValue, copy.copy(System.Char.MinValue))
        self.assertTrue(System.Char.MinValue != copy.copy(System.Char.MaxValue))
        self.assertEqual(System.StringSplitOptions.None, copy.copy(System.StringSplitOptions.None))
        self.assertEqual(System.StringSplitOptions.RemoveEmptyEntries, copy.copy(System.StringSplitOptions.RemoveEmptyEntries))
        self.assertTrue(System.StringSplitOptions.None != copy.copy(System.StringSplitOptions.RemoveEmptyEntries))
        
        #Normal cases
        test_dict = {   System.Byte : [System.Byte.MinValue, System.Byte.MinValue+1, System.Byte.MaxValue, System.Byte.MaxValue-1],
                        System.Char : [],
                        System.Boolean : [True, False],
                        System.SByte   : [System.SByte.MinValue, System.SByte.MinValue+1, System.SByte.MaxValue, System.SByte.MaxValue-1],
                        System.UInt32  : [System.UInt32.MinValue, System.UInt32.MinValue+1, System.UInt32.MaxValue, System.UInt32.MaxValue-1],
                        System.Int64   : [System.Int64.MinValue, System.Int64.MinValue+1, System.Int64.MaxValue, System.Int64.MaxValue-1],
                        System.Double  : [0.00, 3.14],
                        }
        
        for key in test_dict.keys():
            temp_type = key
            self.assertTrue(hasattr(temp_type, "__reduce_ex__"), 
                "%s has no attribute '%s'" % (str(temp_type), "__reduce_ex__"))
        
            for temp_value in test_dict[key]:
                x = temp_type(temp_value)
                x_copy = copy.copy(x)
                self.assertEqual(x, x_copy)
                self.assertEqual(x, temp_value) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:test_stdmodules.py

示例9: transform

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def transform(x):
        x = _common_transform(x)
        if isinstance(x, type) and (x == Byte or x == Int64):
            return int
        return x 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:common.py

示例10: get_values

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def get_values(values, itypes, ftypes):
    """
    This will return structure of values converted to variety of types as a list of tuples:
    [ ...
    ( python_value, [ all_values ] ),
    ... ]

    all_values: Byte, UInt16, UInt32, UInt64, SByte, Int16, Int32, Int64, Single, Double, myint, mylong, myfloat
    """
    all = []
    for v in values:
        sv  = str(v)
        py  = int(v)
        clr = get_clr_values(sv, itypes)
        clr.append(long(py))
        clr.append(myint(py))
        clr.append(mylong(py))
        all.append( (py, clr) )

        py  = long(v)
        clr = get_clr_values(sv, itypes)
        clr.append(py)
        clr.append(myint(py))
        clr.append(mylong(py))
        all.append( (py, clr) )

        py  = float(v)
        clr = get_clr_values(sv, ftypes)
        clr.append(myfloat(py))
        all.append( (py, clr) )

        for imag in [0j, 1j, -1j]:
            py = complex(v + imag)
            all.append( (py, [ py, mycomplex(py) ] ) )

    all.append( (True, [ True ] ))
    all.append( (False, [ False ] ))

    return all 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:41,代码来源:test_numtypes.py

示例11: validate_constructors

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def validate_constructors(self, values):
        types = [Byte, UInt16, UInt32, UInt64, SByte, Int16, Int32, Int64]
        total = 0
        for value in values:
            for first in types:
                v1 = first(value)
                for second in types:
                    v2 = first(second((value)))
                total += 1
        return total 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_numtypes.py

示例12: _test_delete_by_descriptor

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def _test_delete_by_descriptor(self, current_type):
        for x in [
            'Byte',
            'SByte',
            'UInt16',
            'Int16',
            'UInt32',
            'Int32',
            'UInt64',
            'Int64',
            'Double',
            'Single',
            'Decimal',
            'Char',
            'Boolean',
            'String',
            'Object',
            'Enum',
            'DateTime',
            'SimpleStruct',
            'SimpleGenericStruct',
            'NullableStructNotNull',
            'NullableStructNull',
            'SimpleClass',
            'SimpleGenericClass',
            'SimpleInterface',
        ]:
            for o in [None, current_type, current_type()]:
                self.assertRaisesRegexp(AttributeError, "cannot delete attribute", lambda: current_type.__dict__['Instance%sField' % x].__delete__(o)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:31,代码来源:test_instance_fields.py

示例13: test_nested

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def test_nested(self):
        import System
        from Merlin.Testing.FieldTest import Class2, GenericClass2
        for ct in [ Class2, GenericClass2[System.Byte], GenericClass2[object] ]:
            c = ct()
            self.assertEqual(c.InstanceNextField, None)
            c.InstanceNextField = ct()
            
            self.assertEqual(c.InstanceNextField.InstanceNextField, None)
            c.InstanceNextField.InstanceField = 20
            self.assertEqual(c.InstanceNextField.InstanceField, 20) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_instance_fields.py

示例14: _test_delete_by_descriptor

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def _test_delete_by_descriptor(self, current_type):
        for x in [
            'Byte',
            'SByte',
            'UInt16',
            'Int16',
            'UInt32',
            'Int32',
            'UInt64',
            'Int64',
            'Double',
            'Single',
            'Decimal',
            'Char',
            'Boolean',
            'String',
            'Object',
            'Enum',
            'DateTime',
            'SimpleStruct',
            'SimpleGenericStruct',
            'NullableStructNotNull',
            'NullableStructNull',
            'SimpleClass',
            'SimpleGenericClass',
            'SimpleInterface',
        ]:
            for o in [None, current_type, current_type()]:
                self.assertRaises(AttributeError, lambda: current_type.__dict__['Static%sField' % x].__delete__(o)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:31,代码来源:test_static_fields.py

示例15: test_big_1

# 需要导入模块: import System [as 别名]
# 或者: from System import Byte [as 别名]
def test_big_1(self):
        from System import SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64
        from System.Numerics import BigInteger
        for (a, m, t,x) in [
                            (7, "ToSByte",  SByte,2),
                            (8, "ToByte",   Byte, 0),
                            (15, "ToInt16", Int16,2),
                            (16, "ToUInt16", UInt16,0),
                            (31, "ToInt32", Int32,2),
                            (32, "ToUInt32", UInt32,0),
                            (63, "ToInt64", Int64,2),
                            (64, "ToUInt64", UInt64,0)
                        ]:

            b = BigInteger(-x ** a )
            left = getattr(b, m)(self.p)
            right = t.MinValue
            self.assertEqual(left, right)

            b = BigInteger(2 ** a -1)
            left = getattr(b, m)(self.p)
            right = t.MaxValue
            self.assertEqual(left, right)

            b = BigInteger(long(0))
            left = getattr(b, m)(self.p)
            right = t.MaxValue - t.MaxValue
            self.assertEqual(left, 0)

            self.assertRaises(OverflowError,getattr(BigInteger(2 ** a ), m),self.p)
            self.assertRaises(OverflowError,getattr(BigInteger(-1 - x ** a ), m),self.p) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:test_ironmath.py


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