本文整理汇总了Python中bitstring.ConstBitStream.pos方法的典型用法代码示例。如果您正苦于以下问题:Python ConstBitStream.pos方法的具体用法?Python ConstBitStream.pos怎么用?Python ConstBitStream.pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitstring.ConstBitStream
的用法示例。
在下文中一共展示了ConstBitStream.pos方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReadList
# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import pos [as 别名]
def testReadList(self):
s = CBS("0b10001111001")
t = s.readlist("pad:1, uint:3, pad:4, uint:3")
self.assertEqual(t, [0, 1])
s.pos = 0
t = s.readlist("pad:1, pad:5")
self.assertEqual(t, [])
self.assertEqual(s.pos, 6)
s.pos = 0
t = s.readlist("pad:1, bin, pad:4, uint:3")
self.assertEqual(t, ["000", 1])
s.pos = 0
t = s.readlist("pad, bin:3, pad:4, uint:3")
self.assertEqual(t, ["000", 1])
示例2: ConstBitStream
# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import pos [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bitstring import ConstBitStream
import sys
c = ConstBitStream(filename=sys.argv[1])
#Most log entry ends with 0A, this helps us to seek to the beginning of an entry
start = c.find('0x0A', bytealigned=True)[0]
#Seek 8 byte into the stream to skip EOL from previus log entry
start += 8
c.pos = start
while True:
#Read and print the binary log header
header = c.readlist('8*uintle:32')
print header
#Get the size in bits of the log message
msgSize = (header[0] * 8 - 256)
#Move pointer after message
c.pos += msgSize
#Check if EOL is present after message, if true, move pointer 8 byte
if c.peek(8).hex == '0a':
c.pos += 8
示例3: testNotAligned
# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import pos [as 别名]
def testNotAligned(self):
a = CBS('0b00111001001010011011')
a.pos = 1
self.assertEqual(a.readto('0b00'), '0b011100')
self.assertEqual(a.readto('0b110'), '0b10010100110')
self.assertRaises(ValueError, a.readto, '')
示例4: parse_font
# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import pos [as 别名]
def parse_font(font_num, spft_filename):
FONT_DATA[font_num] = {}
# spft_filename = ""
# if font_num == 1:
# spft_filename = os.path.join(FONT_FOLDER, FONT1_TABLE)
# elif font_num == 2:
# spft_filename = os.path.join(FONT_FOLDER, FONT2_TABLE)
if not font_num in [1, 2]:
print "Invalid font number. Valid values: 1, 2"
return None
# Header:
# 74467053 -- Magic
# 04000000 -- Magic
# XXXXXXXX -- Number of entries in font table
# XXXXXXXX -- Position of first entry in font table
#
# XXXXXXXX -- Number of chunks in the mappings table
# XXXXXXXX -- Start position of mappings table (little-endian, as always)
# ***0x20000000 in both fonts I've seen
# XXXXXXXX -- ????
# XXXXXXXX -- ????
#
# Character Mappings: from start pos (0x20) to (start pos + (# chunks * 2))
# * To avoid overcomplicating this, I'm just referring to the start pos as
# 0x20 since I've only ever seen that value used.
# * Two-byte chunks (XXXX)
# * The position of each chunk, minus 0x20, divided by two (because they're
# two-byte chunks), equals the UTF-16 representation of a character.
# (i.e. pos 0x00A8: (0x00A8 - 0x20) / 2 = 0x0044 -> "A")
# * The value of each chunk is the index of that character in the font table,
# little-endian.
# (i.e. if the character "A" is the 35th entry, zero-indexed = 0x2200)
# * A chunk value of 0xFFFF means that character is not present in the font.
spft = ConstBitStream(filename = spft_filename)
magic = spft.read(64)
if magic != SPFT_MAGIC:
print "Didn't find SPFT magic."
exit()
num_entries = spft.read('uintle:32')
table_start = spft.read('uintle:32')
if num_entries == 0:
print "No entries in SPFT table."
return None
if table_start * 8 > spft.len:
print "Invalid SPFT table position."
return None
#print "Characters in font:", num_entries
spft.pos = table_start * 8
# Table:
# * Entry:
# XXXX -- Character
# XXXX -- X Pos
# XXXX -- Y Pos
# XXXX -- Width
# XXXX -- Height
# 0000 -- Padding
# 0000 -- Padding
# FA08 -- Something to do with rendering offset. FA -> -6 -> renders six pixels down
#print " XXXX YYYY WWW HHH"
for i in range(0, num_entries):
char = spft.read(16)
char = char.bytes.decode('utf-16le')
xpos = spft.read('uintle:16')
ypos = spft.read('uintle:16')
width = spft.read('uintle:16')
height = spft.read('uintle:16')
dummy = spft.read('uintle:16')
dummy = spft.read('uintle:16')
yshift = spft.read('intle:8')
dummy = spft.read('uintle:8')
info = {'x': xpos, 'y': ypos, 'w': width, 'h': height}
FONT_DATA[font_num][char] = info
示例5: testNotAligned
# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import pos [as 别名]
def testNotAligned(self):
a = CBS("0b00111001001010011011")
a.pos = 1
self.assertEqual(a.readto("0b00"), "0b011100")
self.assertEqual(a.readto("0b110"), "0b10010100110")
self.assertRaises(ValueError, a.readto, "")