本文整理汇总了Python中bitstring.BitArray.find方法的典型用法代码示例。如果您正苦于以下问题:Python BitArray.find方法的具体用法?Python BitArray.find怎么用?Python BitArray.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitstring.BitArray
的用法示例。
在下文中一共展示了BitArray.find方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testByteAligned
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import find [as 别名]
def testByteAligned(self):
bitstring.settings.bytealigned = True
a = BitArray('0x00 ff 0f f')
l = list(a.findall('0xff'))
self.assertEqual(l, [8])
p = a.find('0x0f')[0]
self.assertEqual(p, 16)
p = a.rfind('0xff')[0]
self.assertEqual(p, 8)
s = list(a.split('0xff'))
self.assertEqual(s, ['0x00', '0xff0ff'])
a.replace('0xff', '')
self.assertEqual(a, '0x000ff')
示例2: testByteAligned
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import find [as 别名]
def testByteAligned(self):
bitstring.bytealigned = True
a = BitArray("0x00 ff 0f f")
l = list(a.findall("0xff"))
self.assertEqual(l, [8])
p = a.find("0x0f")[0]
self.assertEqual(p, 16)
p = a.rfind("0xff")[0]
self.assertEqual(p, 8)
s = list(a.split("0xff"))
self.assertEqual(s, ["0x00", "0xff0ff"])
a.replace("0xff", "")
self.assertEqual(a, "0x000ff")
示例3: testNotByteAligned
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import find [as 别名]
def testNotByteAligned(self):
bitstring.bytealigned = False
a = BitArray('0x00 ff 0f f')
l = list(a.findall('0xff'))
self.assertEqual(l, [8, 20])
p = a.find('0x0f')[0]
self.assertEqual(p, 4)
p = a.rfind('0xff')[0]
self.assertEqual(p, 20)
s = list(a.split('0xff'))
self.assertEqual(s, ['0x00', '0xff0', '0xff'])
a.replace('0xff', '')
self.assertEqual(a, '0x000')
示例4: ESXVlans
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import find [as 别名]
class ESXVlans(object):
"""The vlan object"""
def __init__(self, esx_session):
self._vlan_id_bits = BitArray(MAX_VLAN_ID + 1)
self._init_vlans(esx_session)
#end __init__()
def _init_vlans(self, esx_session):
session = esx_session
host_mor = vm_util.get_host_ref(session)
port_grps_on_host_ret = session._call_method(vim_util,
"get_dynamic_property",
host_mor,
"HostSystem",
"config.network.portgroup")
if not port_grps_on_host_ret:
return
port_grps_on_host = port_grps_on_host_ret.HostPortGroup
for p_gp in port_grps_on_host:
if p_gp.spec.vlanId >= 0:
self._vlan_id_bits[p_gp.spec.vlanId] = 1
#end _init_vlans()
def alloc_vlan(self):
vid = self._vlan_id_bits.find('0b0')
if vid:
self._vlan_id_bits[vid[0]] = 1
return vid[0]
return INVALID_VLAN_ID
#end alloc_vlan()
def free_vlan(self, vlan_id):
if vlan_id < 0 or vlan_id > MAX_VLAN_ID:
return
self._vlan_id_bits[vlan_id] = 0
示例5: open
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import find [as 别名]
f = open(sys.argv[1],'r+b')
f.seek(0,2)
size = f.tell()
print "[*] file size: %d" % size
f.seek(0,0)
print "[*] ReeeeeWWWWWWiiiiiNNNNNNND"
fb = BitArray(f)
index = fb.find('0xa1dcab8c47a9cf118ee400c00c205365',bytealigned=True)
print "[*] found file properties GUID"
print "[*] File properties GUID: %s" % fb[index[0]:(index[0]+128)]
# index of minumum packet size in File Proprties header
i_min_data_pkt_size = index[0] + 736
print "[*] Original Minimum Data Packet Size: %s" % fb[i_min_data_pkt_size:i_min_data_pkt_size+32].hex
print "[*] Original Maximum Data Packet Size: %s" % fb[i_min_data_pkt_size+32:i_min_data_pkt_size+64].hex
# Accroding to ASF standarad the minimum data size and the maximum data size should be equal
print "[*] Changing Miniumum and Maximum Data packet size to 0"
# changing the data packets in bit array
示例6: VirtualMachineInterfaceKM
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import find [as 别名]
#.........这里部分代码省略.........
self.update_multiple_refs('floating_ip', obj)
self.update_single_ref('virtual_network', obj)
self.update_single_ref('virtual_machine', obj)
self.update_multiple_refs('security_group', obj)
self.update_multiple_refs('virtual_machine_interface', obj)
# Update VMI properties.
vlan_id = None
if obj.get('virtual_machine_interface_properties', None):
props = obj['virtual_machine_interface_properties']
# Property: Vlan ID.
vlan_id = props.get('sub_interface_vlan_tag', None)
# If vlan is configured on this interface, cache the appropriate
# info.
#
# In nested mode, if the interface is a sub-interface, the vlan id
# space is allocated and managed in the parent interface. So check to
# see if the interface has a parent. If it does, invoke the appropriate
# method on the parent interface for vlan-id management.
if (vlan_id is not None or self.vlan_id is not None) and\
vlan_id is not self.vlan_id:
# Vlan is configured on this interface.
if DBBaseKM.is_nested():
# We are in nested mode.
# Check if this interface has a parent. If yes, this is
# is a sub-interface and the vlan-id should be managed on the
# vlan-id space of the parent interface.
parent_vmis = self.virtual_machine_interfaces
for parent_vmi_id in parent_vmis:
parent_vmi = VirtualMachineInterfaceKM.locate(
parent_vmi_id)
if not parent_vmi:
continue
if self.vlan_id is not None:
parent_vmi.reset_vlan(self.vlan_id)
if vlan_id is not None:
parent_vmi.set_vlan(vlan_id)
# Cache the Vlan-id.
self.vlan_id = vlan_id
else:
# Nested mode is not configured.
# Vlan-id is NOT managed on the parent interface.
# Just cache and proceed.
self.vlan_id = vlan_id
return obj
@classmethod
def delete(cls, uuid):
if uuid not in cls._dict:
return
obj = cls._dict[uuid]
# If vlan-id is configured and if we are in nested mode,
# free up the vlan-id which was claimed from the parent
# interface.
if obj.vlan_id and DBBaseKM.is_nested():
parent_vmi_ids = obj.virtual_machine_interfaces
for parent_vmi_id in parent_vmi_ids:
parent_vmi = VirtualMachineInterfaceKM.get(parent_vmi_id)
if parent_vmi:
parent_vmi.reset_vlan(obj.vlan_id)
obj.update_multiple_refs('instance_ip', {})
obj.update_multiple_refs('floating_ip', {})
obj.update_single_ref('virtual_network', {})
obj.update_single_ref('virtual_machine', {})
obj.update_multiple_refs('security_group', {})
obj.update_multiple_refs('virtual_machine_interface', {})
obj.remove_from_parent()
del cls._dict[uuid]
def set_vlan (self, vlan):
if vlan < MIN_VLAN_ID or vlan > MAX_VLAN_ID:
return
if not self.vlan_bit_map:
self.vlan_bit_map = BitArray(MAX_VLAN_ID + 1)
self.vlan_bit_map[vlan] = 1
def reset_vlan (self, vlan):
if vlan < MIN_VLAN_ID or vlan > MAX_VLAN_ID:
return
if not self.vlan_bit_map:
return
self.vlan_bit_map[vlan] = 0
def alloc_vlan (self):
if not self.vlan_bit_map:
self.vlan_bit_map = BitArray(MAX_VLAN_ID + 1)
vid = self.vlan_bit_map.find('0b0', MIN_VLAN_ID)
if vid:
self.set_vlan(vid[0])
return vid[0]
return INVALID_VLAN_ID
def get_vlan (self):
return vlan_id
示例7: element_calulator
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import find [as 别名]
def element_calulator(Pulses):
ch1 = [-1]
ch2 = [-1]
ch3 = [-1]
ch4 = [-1]
for arg in Pulses:
if (arg.channel == 'ch1'):
ch1.append(arg.start)
ch1.append(arg.end)
elif (arg.channel == 'ch2'):
ch2.append(arg.start)
ch2.append(arg.end)
elif (arg.channel == 'ch3'):
ch3.append(arg.start)
ch3.append(arg.end)
elif (arg.channel == 'ch4'):
ch4.append(arg.start)
ch4.append(arg.end)
tot_length = max(max(ch1),max(ch2),max(ch3),max(ch4))
del ch1[0]
del ch2[0]
del ch3[0]
del ch4[0]
channel1 = BitArray(int=0, length=tot_length)
channel2 = BitArray(int=0, length=tot_length)
channel3 = BitArray(int=0, length=tot_length)
channel4 = BitArray(int=0, length=tot_length)
for x in range(len(ch1)):
if (x%2 == 0):
channel1.invert(range(ch1[x],ch1[x+1]))
else:
pass
for x in range(len(ch2)):
if (x%2 == 0):
channel2.invert(range(ch2[x],ch2[x+1]))
else:
pass
for x in range(len(ch3)):
if (x%2 == 0):
channel3.invert(range(ch3[x],ch3[x+1]))
else:
pass
for x in range(len(ch4)):
if (x%2 == 0):
channel4.invert(range(ch4[x],ch4[x+1]))
else:
pass
channel1 |= channel2
channel3 |= channel4
channel1 |= channel3
channel1.append('0b0')
result = []
count = 0
test = BitArray(int = 0, length = 1)
empty = test.find('0b1')
while (channel1.len != 0):
test = channel1.find('0b1')
if (test == empty):
break
else:
result.append(channel1.find('0b1'))
result[count] = result[count][0]
del channel1[0:result[count]]
count = count + 1
test = channel1.find('0b0')
if (test == empty):
break
else:
result.append(channel1.find('0b0'))
result[count] = result[count][0]
del channel1[0:result[count]]
count = count + 1
return result