本文整理匯總了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)
示例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
)
示例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])
示例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]))
示例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
示例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
示例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)
示例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)
示例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
示例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
示例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
示例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))
示例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)
示例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))
示例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)