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


Python ConstBitStream.peeklist方法代码示例

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


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

示例1: extractXMP

# 需要导入模块: from bitstring import ConstBitStream [as 别名]
# 或者: from bitstring.ConstBitStream import peeklist [as 别名]
 def extractXMP(self, filename):
     xmpStr = ""        
     # Can initialise from files, bytes, etc.
     try:
         s = ConstBitStream(filename = filename)
         # Search for ":xmpmeta" string in file
         keepSearching = True
         while keepSearching:
             keepSearching = False
             colonXmpmetaInHexStr = '0x3a786d706d657461'
             foundSt = s.find(colonXmpmetaInHexStr, bytealigned=True)
             if foundSt:
                 byteStart = (int(foundSt[0])//8)
                 # The start of data can be "<xmp:xmpmeta" or "<x:xmpmeta"
                 s.bytepos = byteStart - 4
                 prevals = s.peeklist("4*uint:8")
                 prestr = ''.join(chr(i) for i in prevals)
     #            print (prestr, prestr[2:])
                 if prestr == "<xmp":
                     byteStart = byteStart - 4
                     prefix = "0x3c2f786d70"  # "<\xmp" in hex
                 elif prestr[2:] == "<x":
                     byteStart = byteStart - 2
                     prefix = "0x3c2f78"  # "<\x" in hex
                 else:
     #                print ("Cont")
                     keepSearching = True
                     continue
     #            print("Found start code at byte offset %d." % byteStart)
                 foundEnd = s.find(prefix + colonXmpmetaInHexStr, bytealigned=True)
                 if foundEnd:
                     byteEnd = (int(foundEnd[0])//8)
                     s.bytepos = byteStart
     #                print("Found end code at byte offset %d." % byteEnd)
                     xmpBytes = s.readlist(str(byteEnd-byteStart+len(prefix)//2+9) +"*uint:8")
                     xmpStr = ''.join(chr(i) for i in xmpBytes)
                     #if "Rating" in xmpStr:
     #                print (xmpStr)
     except:
         xmpStr = ""
     return xmpStr
开发者ID:,项目名称:,代码行数:43,代码来源:


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