• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.b_函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.b_函数的典型用法代码示例。如果您正苦于以下问题:Python b_函数的具体用法?Python b_怎么用?Python b_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: writeToStream

 def writeToStream(self, stream, encryption_key):
     bytearr = self
     if encryption_key:
         bytearr = RC4_encrypt(encryption_key, bytearr)
     stream.write(b_("<"))
     stream.write(utils.hexencode(bytearr))
     stream.write(b_(">"))
开发者ID:USGM,项目名称:PyPDF2,代码行数:7,代码来源:generic.py


示例2: _decrypt

 def _decrypt(self, password):
     encrypt = self.trailer['/Encrypt'].getObject()
     if encrypt['/Filter'] != '/Standard':
         raise NotImplementedError(
             "only Standard PDF encryption handler is available")
     if not (encrypt['/V'] in (1, 2)):
         raise NotImplementedError(
             "only algorithm code 1 and 2 are supported")
     user_password, key = self._authenticateUserPassword(password)
     if user_password:
         self._decryption_key = key
         return 1
     else:
         rev = encrypt['/R'].getObject()
         if rev == 2:
             keylen = 5
         else:
             keylen = encrypt['/Length'].getObject() // 8
         key = _alg33_1(password, rev, keylen)
         real_O = encrypt["/O"].getObject()
         if rev == 2:
             userpass = utils.RC4_encrypt(key, real_O)
         else:
             val = real_O
             for i in range(19, -1, -1):
                 new_key = b_('')
                 for l in range(len(key)):
                     new_key += b_(chr(utils.ord_(key[l]) ^ i))
                 val = utils.RC4_encrypt(new_key, val)
             userpass = val
         owner_password, key = self._authenticateUserPassword(userpass)
         if owner_password:
             self._decryption_key = key
             return 2
     return 0
开发者ID:jeansch,项目名称:PyPDF2,代码行数:35,代码来源:reader.py


示例3: readFromStream

 def readFromStream(stream, pdf):
     idnum = b_("")
     while True:
         tok = stream.read(1)
         if not tok:
             # stream has truncated prematurely
             raise PdfStreamError("Stream has ended unexpectedly")
         if tok.isspace():
             break
         idnum += tok
     generation = b_("")
     while True:
         tok = stream.read(1)
         if not tok:
             # stream has truncated prematurely
             raise PdfStreamError("Stream has ended unexpectedly")
         if tok.isspace():
             if not generation:
                 continue
             break
         generation += tok
     r = readNonWhitespace(stream)
     if r != b_("R"):
         raise utils.PdfReadError("Error reading indirect object reference at byte %s" % utils.hexStr(stream.tell()))
     return IndirectObject(int(idnum), int(generation), pdf)
开发者ID:arshpreetsingh,项目名称:pdf2audio,代码行数:25,代码来源:generic.py


示例4: readFromStream

 def readFromStream(stream):
     word = stream.read(4)
     if word == b_("true"):
         return BooleanObject(True)
     elif word == b_("fals"):
         stream.read(1)
         return BooleanObject(False)
     assert False
开发者ID:ccurvey,项目名称:PyPDF2,代码行数:8,代码来源:generic.py


示例5: encode_pdfdocencoding

def encode_pdfdocencoding(unicode_string):
    retval = b_('')
    for c in unicode_string:
        try:
            retval += b_(chr(_pdfDocEncoding_rev[c]))
        except KeyError:
            raise UnicodeEncodeError("pdfdocencoding", c, -1, -1,
                    "does not exist in translation table")
    return retval
开发者ID:USGM,项目名称:PyPDF2,代码行数:9,代码来源:generic.py


示例6: readFromStream

 def readFromStream(stream):
     word = stream.read(4)
     if word == b_("true"):
         return BooleanObject(True)
     elif word == b_("fals"):
         stream.read(1)
         return BooleanObject(False)
     else:
         raise utils.PdfReadError('Could not read Boolean object')
开发者ID:USGM,项目名称:PyPDF2,代码行数:9,代码来源:generic.py


示例7: readHexStringFromStream

def readHexStringFromStream(stream):
    stream.read(1)
    txt = ""
    x = b_("")
    while True:
        tok = readNonWhitespace(stream)
        if tok == b_(">"):
            break
        x += tok
        if len(x) == 2:
            txt += chr(int(x, base=16))
            x = b_("")
    if len(x) == 1:
        x += b_("0")
    if len(x) == 2:
        txt += chr(int(x, base=16))
    return createStringObject(b_(txt))
开发者ID:ccurvey,项目名称:PyPDF2,代码行数:17,代码来源:generic.py


示例8: readObject

def readObject(stream, pdf):
    tok = stream.read(1)
    stream.seek(-1, 1) # reset to start
    idx = ObjectPrefix.find(tok)
    if idx == 0:
        # name object
        return NameObject.readFromStream(stream, pdf)
    elif idx == 1:
        # hexadecimal string OR dictionary
        peek = stream.read(2)
        stream.seek(-2, 1) # reset to start
        if peek == b_('<<'):
            return DictionaryObject.readFromStream(stream, pdf)
        else:
            return readHexStringFromStream(stream)
    elif idx == 2:
        # array object
        return ArrayObject.readFromStream(stream, pdf)
    elif idx == 3 or idx == 4:
        # boolean object
        return BooleanObject.readFromStream(stream)
    elif idx == 5:
        # string object
        return readStringFromStream(stream)
    elif idx == 6:
        # null object
        return NullObject.readFromStream(stream)
    elif idx == 7:
        # comment
        while tok not in (b_('\r'), b_('\n')):
            tok = stream.read(1)
        tok = readNonWhitespace(stream)
        stream.seek(-1, 1)
        return readObject(stream, pdf)
    else:
        # number object OR indirect reference
        if tok in NumberSigns:
            # number
            return NumberObject.readFromStream(stream)
        peek = stream.read(20)
        stream.seek(-len(peek), 1) # reset to start
        if IndirectPattern.match(peek) != None:
            return IndirectObject.readFromStream(stream, pdf)
        else:
            return NumberObject.readFromStream(stream)
开发者ID:arshpreetsingh,项目名称:pdf2audio,代码行数:45,代码来源:generic.py


示例9: readHexStringFromStream

def readHexStringFromStream(stream):
    stream.read(1)
    txt = ""
    x = b_("")
    while True:
        tok = readNonWhitespace(stream)
        if not tok:
            # stream has truncated prematurely
            raise PdfStreamError("Stream has ended unexpectedly")
        if tok == b_(">"):
            break
        x += tok
        if len(x) == 2:
            txt += chr(int(x, base=16))
            x = b_("")
    if len(x) == 1:
        x += b_("0")
    if len(x) == 2:
        txt += chr(int(x, base=16))
    return createStringObject(b_(txt))
开发者ID:USGM,项目名称:PyPDF2,代码行数:20,代码来源:generic.py


示例10: readFromStream

 def readFromStream(stream):
     name = stream.read(1)
     if name != b_("/"):
         raise utils.PdfReadError, "name read error"
     while True:
         tok = stream.read(1)
         if tok.isspace() or tok in NameObject.delimiterCharacters:
             stream.seek(-1, 1)
             break
         name += tok
     return NameObject(name.decode('utf-8'))
开发者ID:jeansch,项目名称:PyPDF2,代码行数:11,代码来源:generic.py


示例11: _alg35

def _alg35(password, rev, keylen,
           owner_entry, p_entry, id1_entry, metadata_encrypt):
    # 1. Create an encryption key based on the user password string, as
    # described in Algorithm 3.2.
    key = _alg32(password, rev, keylen, owner_entry, p_entry, id1_entry)
    # 2. Initialize the MD5 hash function and pass the 32-byte padding string
    # shown in step 1 of Algorithm 3.2 as input to this function.
    m = md5()
    m.update(_encryption_padding)
    # 3. Pass the first element of the file's file identifier array (the value
    # of the ID entry in the document's trailer dictionary; see Table 3.13 on
    # page 73) to the hash function and finish the hash.  (See implementation
    # note 25 in Appendix H.)
    m.update(id1_entry.original_bytes)
    md5_hash = m.digest()
    # 4. Encrypt the 16-byte result of the hash, using an RC4 encryption
    # function with the encryption key from step 1.
    val = utils.RC4_encrypt(key, md5_hash)
    # 5. Do the following 19 times: Take the output from the previous
    # invocation of the RC4 function and pass it as input to a new invocation
    # of the function; use an encryption key generated by taking each byte of
    # the original encryption key (obtained in step 2) and performing an XOR
    # operation between that byte and the single-byte value of the iteration
    # counter (from 1 to 19).
    for i in range(1, 20):
        new_key = b_('')
        for l in range(len(key)):
            new_key += b_(chr(utils.ord_(key[l]) ^ i))
        val = utils.RC4_encrypt(new_key, val)
    # 6. Append 16 bytes of arbitrary padding to the output from the final
    # invocation of the RC4 function and store the 32-byte result as the value
    # of the U entry in the encryption dictionary.
    # (implementator note: I don't know what "arbitrary padding" is supposed to
    # mean, so I have used null bytes.  This seems to match a few other
    # people's implementations)
    return val + (b_('\x00') * 16), key
开发者ID:jeansch,项目名称:PyPDF2,代码行数:36,代码来源:algorithms.py


示例12: __init__

 def __init__(self):
     self._header = b_("%PDF-1.3")
     self._objects = []  # array of indirect objects
     # The root of our page tree node.
     pages = DictionaryObject()
     pages.update({NameObject("/Type"): NameObject("/Pages"),
                   NameObject("/Count"): NumberObject(0),
                   NameObject("/Kids"): ArrayObject()})
     self._pages = self._addObject(pages)
     # info object
     info = DictionaryObject()
     info.update({NameObject("/Producer"): createStringObject(
         u"Python PDF Library - http://pybrary.net/pyPdf/")})
     self._info = self._addObject(info)
     # root object
     root = DictionaryObject()
     root.update({NameObject("/Type"): NameObject("/Catalog"),
                  NameObject("/Pages"): self._pages})
     self._root = self._addObject(root)
开发者ID:jeansch,项目名称:PyPDF2,代码行数:19,代码来源:writer.py


示例13: readNextEndLine

 def readNextEndLine(self, stream):
     line = b_("")
     while True:
         x = stream.read(1)
         stream.seek(-2, 1)
         if x == b_('\n') or x == b_('\r'):  # \n = LF; \r = CR
             crlf = False
             while x == b_('\n') or x == b_('\r'):
                 x = stream.read(1)
                 if x == b_('\n') or x == b_('\r'):  # account for CR+LF
                     stream.seek(-1, 1)
                     crlf = True
                 stream.seek(-2, 1)
             # if using CR+LF, go back 2 bytes, else 1
             stream.seek(2 if crlf else 1, 1)
             break
         else:
             line = x + line
     return line
开发者ID:jeansch,项目名称:PyPDF2,代码行数:19,代码来源:reader.py


示例14: _alg32

def _alg32(password, rev, keylen,
           owner_entry, p_entry, id1_entry, metadata_encrypt=True):
    # 1. Pad or truncate the password string to exactly 32 bytes.  If the
    # password string is more than 32 bytes long, use only its first 32 bytes;
    # if it is less than 32 bytes long, pad it by appending the required number
    # of additional bytes from the beginning of the padding string
    # (_encryption_padding).
    password = (password + _encryption_padding)[:32]
    # 2. Initialize the MD5 hash function and pass the result of step 1 as
    # input to this function.
    m = md5(password)
    # 3. Pass the value of the encryption dictionary's /O entry to the MD5 hash
    # function.
    m.update(owner_entry.original_bytes)
    # 4. Treat the value of the /P entry as an unsigned 4-byte integer and pass
    # these bytes to the MD5 hash function, low-order byte first.
    p_entry = struct.pack('<i', p_entry)
    m.update(p_entry)
    # 5. Pass the first element of the file's file identifier array to the MD5
    # hash function.
    m.update(id1_entry.original_bytes)
    # 6. (Revision 3 or greater) If document metadata is not being encrypted,
    # pass 4 bytes with the value 0xFFFFFFFF to the MD5 hash function.
    if rev >= 3 and not metadata_encrypt:
        m.update(b_("\xff\xff\xff\xff"))
    # 7. Finish the hash.
    md5_hash = m.digest()
    # 8. (Revision 3 or greater) Do the following 50 times: Take the output
    # from the previous MD5 hash and pass the first n bytes of the output as
    # input into a new MD5 hash, where n is the number of bytes of the
    # encryption key as defined by the value of the encryption dictionary's
    # /Length entry.
    if rev >= 3:
        for i in range(50):
            md5_hash = md5(md5_hash[:keylen]).digest()
    # 9. Set the encryption key to the first n bytes of the output from the
    # final MD5 hash, where n is always 5 for revision 2 but, for revision 3 or
    # greater, depends on the value of the encryption dictionary's /Length
    # entry.
    return md5_hash[:keylen]
开发者ID:jeansch,项目名称:PyPDF2,代码行数:40,代码来源:algorithms.py


示例15: readObject

def readObject(stream, pdf):
    tok = stream.read(1)
    stream.seek(-1, 1) # reset to start
    if tok == b_('t') or tok == b_('f'):
        # boolean object
        return BooleanObject.readFromStream(stream)
    elif tok == b_('('):
        # string object
        return readStringFromStream(stream)
    elif tok == b_('/'):
        # name object
        return NameObject.readFromStream(stream)
    elif tok == b_('['):
        # array object
        return ArrayObject.readFromStream(stream, pdf)
    elif tok == b_('n'):
        # null object
        return NullObject.readFromStream(stream)
    elif tok == b_('<'):
        # hexadecimal string OR dictionary
        peek = stream.read(2)
        stream.seek(-2, 1) # reset to start
        if peek == b_('<<'):
            return DictionaryObject.readFromStream(stream, pdf)
        else:
            return readHexStringFromStream(stream)
    elif tok == b_('%'):
        # comment
        while tok not in (b_('\r'), b_('\n')):
            tok = stream.read(1)
        tok = readNonWhitespace(stream)
        stream.seek(-1, 1)
        return readObject(stream, pdf)
    else:
        # number object OR indirect reference
        if tok == b_('+') or tok == b_('-'):
            # number
            return NumberObject.readFromStream(stream)
        peek = stream.read(20)
        stream.seek(-len(peek), 1) # reset to start
        if re.match(b_(r"(\d+)\s(\d+)\sR[^a-zA-Z]"), peek) != None:
            return IndirectObject.readFromStream(stream, pdf)
        else:
            return NumberObject.readFromStream(stream)
开发者ID:USGM,项目名称:PyPDF2,代码行数:44,代码来源:generic.py


示例16: readStringFromStream

def readStringFromStream(stream):
    tok = stream.read(1)
    parens = 1
    txt = b_("")
    while True:
        tok = stream.read(1)
        if not tok:
            # stream has truncated prematurely
            raise PdfStreamError("Stream has ended unexpectedly")
        if tok == b_("("):
            parens += 1
        elif tok == b_(")"):
            parens -= 1
            if parens == 0:
                break
        elif tok == b_("\\"):
            tok = stream.read(1)
            if tok == b_("n"):
                tok = b_("\n")
            elif tok == b_("r"):
                tok = b_("\r")
            elif tok == b_("t"):
                tok = b_("\t")
            elif tok == b_("b"):
                tok = b_("\b")
            elif tok == b_("f"):
                tok = b_("\f")
            elif tok == b_("("):
                tok = b_("(")
            elif tok == b_(")"):
                tok = b_(")")
            elif tok == b_("\\"):
                tok = b_("\\")
            elif tok in (b_(" "), b_("/"), b_("%"), b_("<"), b_(">"), b_("["), b_("]")):
                # odd/unnessecary escape sequences we have encountered
                tok = b_(tok)
            elif tok.isdigit():
                # "The number ddd may consist of one, two, or three
                # octal digits; high-order overflow shall be ignored.
                # Three octal digits shall be used, with leading zeros
                # as needed, if the next character of the string is also
                # a digit." (PDF reference 7.3.4.2, p 16)
                for i in range(2):
                    ntok = stream.read(1)
                    if ntok.isdigit():
                        tok += ntok
                    else:
                        break
                tok = b_(chr(int(tok, base=8)))
            elif tok in b_("\n\r"):
                # This case is  hit when a backslash followed by a line
                # break occurs.  If it's a multi-char EOL, consume the
                # second character:
                tok = stream.read(1)
                if not tok in b_("\n\r"):
                    stream.seek(-1, 1)
                # Then don't add anything to the actual string, since this
                # line break was escaped:
                tok = b_('')
            else:
                raise utils.PdfReadError("Unexpected escaped string")
        txt += tok
    return createStringObject(txt)
开发者ID:USGM,项目名称:PyPDF2,代码行数:63,代码来源:generic.py


示例17: as_numeric

 def as_numeric(self):
     return int(b_(repr(self)))
开发者ID:USGM,项目名称:PyPDF2,代码行数:2,代码来源:generic.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.bbox2str函数代码示例发布时间:2022-05-26
下一篇:
Python utils.authenticate函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap