當前位置: 首頁>>代碼示例>>Python>>正文


Python base64.b85encode方法代碼示例

本文整理匯總了Python中base64.b85encode方法的典型用法代碼示例。如果您正苦於以下問題:Python base64.b85encode方法的具體用法?Python base64.b85encode怎麽用?Python base64.b85encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在base64的用法示例。


在下文中一共展示了base64.b85encode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: crypter

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def crypter(ack='',iv='2769514380123456',base='b64'):
    ahk = hmac.new(b'vilame',ack.encode(),'md5').hexdigest()
    c = CrypterAES(ahk, iv)
    if base == 'b16': _encode,_decode = base64.b16encode,base64.b16decode
    if base == 'b32': _encode,_decode = base64.b32encode,base64.b32decode
    if base == 'b64': _encode,_decode = base64.b64encode,base64.b64decode
    if base == 'b85': _encode,_decode = base64.b85encode,base64.b85decode
    if base == 'urlsafe_b64': _encode,_decode = base64.urlsafe_b64encode,base64.urlsafe_b64decode
    def zbase_enc(data):
        return _encode(zlib.compress(data.encode())[2:-4]).decode()
    def zbase_dec(basedata):
        return zlib.decompress(_decode(basedata),-15).decode()
    def zencrypt(data): return c.encrypt_base(zlib.compress(data.encode())[2:-4],_encode)
    def zdecrypt(data): return zlib.decompress(c.decrypt_base(data,_decode),-15).decode()
    c.zencrypt = zencrypt
    c.zdecrypt = zdecrypt
    c.zbase_enc = zbase_enc
    c.zbase_dec = zbase_dec
    c.encrypt = lambda data:c.encrypt_base(data,_encode)
    c.decrypt = lambda data:c.decrypt_base(data,_decode).decode()
    return c 
開發者ID:cilame,項目名稱:vrequest,代碼行數:23,代碼來源:pyzlibaes.py

示例2: send_decoding_error

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def send_decoding_error(self, envelope: Envelope) -> None:
        """
        Handle a decoding error.

        :param envelope: the envelope
        :return: None
        """
        self.context.logger.warning(
            "Decoding error for envelope: {}. Protocol_id='{}' and message='{!r}' are inconsistent.".format(
                envelope, envelope.protocol_id, envelope.message
            )
        )
        encoded_envelope = base64.b85encode(envelope.encode())
        reply = DefaultMessage(
            dialogue_reference=("", ""),
            message_id=1,
            target=0,
            performative=DefaultMessage.Performative.ERROR,
            error_code=DefaultMessage.ErrorCode.DECODING_ERROR,
            error_msg="Decoding error.",
            error_data={"envelope": encoded_envelope},
        )
        reply.counterparty = envelope.sender
        self.context.outbox.put_message(message=reply) 
開發者ID:fetchai,項目名稱:agents-aea,代碼行數:26,代碼來源:handlers.py

示例3: test_encode_base85

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def test_encode_base85(self):
        if sys.version_info.major != 3 or \
                sys.version_info.minor < 4:
            self.fail('Base85 support not available for the current Python version!')
        data_bytes = self._random_bytes()
        encoded_bytes = base64.b85encode(data_bytes)
        plugin = self._plugins.get_plugin_instance('base85')
        result = plugin.process(data_bytes)
        self.assertIsNone(plugin.error), 'An error occurred during Base85 encoding'
        self.assertIsInstance(result, bytes,
            'Base85 encoding result should be bytes or bytearray, '
            'got %s instead' % type(result))
        self.assertEqual(encoded_bytes, result)
        data_str = self._random_str()
        self.assertRaises(TypeError, functools.partial(
            plugin.process, data_str), 'Unexpected exception raised') 
開發者ID:takeshixx,項目名稱:deen,代碼行數:18,代碼來源:test_plugins.py

示例4: test_decode_base85

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def test_decode_base85(self):
        if sys.version_info.major != 3 or \
                sys.version_info.minor < 4:
            self.fail('Base85 support not available for the current Python version!')
        data_bytes = self._random_bytes()
        encoded_bytes = base64.b85encode(data_bytes)
        plugin = self._plugins.get_plugin_instance('base85')
        result = plugin.unprocess(encoded_bytes)
        self.assertIsNone(plugin.error), 'An error occurred during Base85 decoding'
        self.assertIsInstance(result, bytes,
            'Base85 decoding result should be bytes or bytearray, '
            'got %s instead' % type(result))
        self.assertEqual(data_bytes, result)
        data_str = self._random_str()
        self.assertRaises(TypeError, functools.partial(
            plugin.unprocess, data_str), 'Unexpected exception raised') 
開發者ID:takeshixx,項目名稱:deen,代碼行數:18,代碼來源:test_plugins.py

示例5: encode

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def encode(self, text):
		return base64.b85encode(text).replace("=","") 
開發者ID:earthquake,項目名稱:XFLTReaT,代碼行數:4,代碼來源:encoding.py

示例6: _pickle_object

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def _pickle_object(x: typing.Any) -> str:
    pck: str = base64.b85encode(gzip.compress(pickle.dumps(x, protocol=4))).decode().strip()
    segment_gen = map(''.join, itertools.zip_longest(*([iter(pck)] * 100), fillvalue=''))
    return '\n'.join(repr(x) for x in segment_gen) 
開發者ID:UAVCAN,項目名稱:pyuavcan,代碼行數:6,代碼來源:_compiler.py

示例7: packTree

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def packTree(src):
    if not os.path.isdir(src):
        raise BuildError("Cannot import '{}': not a directory!".format(src))

    try:
        f = io.BytesIO()
        with tarfile.open(fileobj=f, mode="w:xz") as tar:
            tar.add(src, arcname=".")
    except OSError as e:
        raise BuildError("Error gathering files: {}".format(str(e)))
    return base64.b85encode(f.getvalue()).decode('ascii') 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:13,代碼來源:imp.py

示例8: random_string

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def random_string(length=TRACKER_PASSWORD_LENGTH_MIN):
    salt = b85encode(urandom(length))
    return salt.decode() 
開發者ID:archlinux,項目名稱:arch-security-tracker,代碼行數:5,代碼來源:user.py

示例9: hash_password

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def hash_password(password, salt):
    hashed = b85encode(shash(password, salt[:User.SALT_LENGTH]))
    return hashed.decode()[:User.PASSWORD_LENGTH] 
開發者ID:archlinux,項目名稱:arch-security-tracker,代碼行數:5,代碼來源:user.py

示例10: main

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def main():
    with open(INPUT_FILE, 'rb') as fd:
        contents = fd.read()

    encoded_contents = base64.b85encode(gzip.compress(contents)).decode()

    print("ENCODED_LIB_CONTENTS = (")
    for line in textwrap.wrap(encoded_contents, 128):
        print("    '%s'" % line)
    print(")") 
開發者ID:dimaryaz,項目名稱:dropbox_ext4,代碼行數:12,代碼來源:encode_lib.py

示例11: test_b85encode

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def test_b85encode(self):
        eq = self.assertEqual

        tests = {
            b'': b'',
            b'www.python.org': b'cXxL#aCvlSZ*DGca%T',
            bytes(range(255)): b"""009C61O)~M2nh-c3=Iws5D^j+6crX17#SKH9337X"""
                b"""AR!_nBqb&%C@Cr{EG;fCFflSSG&MFiI5|2yJUu=?KtV!7L`6nNNJ&ad"""
                b"""OifNtP*GA-R8>}2SXo+ITwPvYU}0ioWMyV&XlZI|Y;A6DaB*^Tbai%j"""
                b"""czJqze0_d@fPsR8goTEOh>41ejE#<ukdcy;l$Dm3n3<ZJoSmMZprN9p"""
                b"""q@|{(sHv)}tgWuEu(7hUw6(UkxVgH!yuH4^z`?@9#Kp$P$jQpf%+1cv"""
                b"""(9zP<)YaD4*xB0K+}+;a;Njxq<mKk)=;`X~?CtLF@bU8V^!4`l`1$(#"""
                b"""{Qdp""",
            b"""abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"""
                b"""0123456789!@#0^&*();:<>,. []{}""":
                b"""VPa!sWoBn+X=-b1ZEkOHadLBXb#`}nd3r%YLqtVJM@UIZOH55pPf$@("""
                b"""Q&d$}S6EqEFflSSG&MFiI5{CeBQRbjDkv#CIy^osE+AW7dwl""",
            b'no padding..': b'Zf_uPVPs@!Zf7no',
            b'zero compression\x00\x00\x00\x00': b'dS!BNAY*TBaB^jHb7^mG00000',
            b'zero compression\x00\x00\x00': b'dS!BNAY*TBaB^jHb7^mG0000',
            b"""Boundary:\x00\x00\x00\x00""": b"""LT`0$WMOi7IsgCw00""",
            b'Space compr:    ': b'Q*dEpWgug3ZE$irARr(h',
            b'\xff': b'{{',
            b'\xff'*2: b'|Nj',
            b'\xff'*3: b'|Ns9',
            b'\xff'*4: b'|NsC0',
        }

        for data, res in tests.items():
            eq(base64.b85encode(data), res)

        self.check_other_types(base64.b85encode, b"www.python.org",
                               b'cXxL#aCvlSZ*DGca%T') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:35,代碼來源:test_base64.py

示例12: test_b85_padding

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def test_b85_padding(self):
        eq = self.assertEqual

        eq(base64.b85encode(b"x", pad=True), b'cmMzZ')
        eq(base64.b85encode(b"xx", pad=True), b'cz6H+')
        eq(base64.b85encode(b"xxx", pad=True), b'czAdK')
        eq(base64.b85encode(b"xxxx", pad=True), b'czAet')
        eq(base64.b85encode(b"xxxxx", pad=True), b'czAetcmMzZ')

        eq(base64.b85decode(b'cmMzZ'), b"x\x00\x00\x00")
        eq(base64.b85decode(b'cz6H+'), b"xx\x00\x00")
        eq(base64.b85decode(b'czAdK'), b"xxx\x00")
        eq(base64.b85decode(b'czAet'), b"xxxx")
        eq(base64.b85decode(b'czAetcmMzZ'), b"xxxxx\x00\x00\x00") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:16,代碼來源:test_base64.py

示例13: dump_observation

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def dump_observation(observation, f):
    if 'cache' in observation:
        observation['cache'] = \
            str(base64.b85encode(pickle.dumps(observation['cache'])), 'ascii')

    json.dump(observation, f)
    f.write("\n") 
開發者ID:wikimedia,項目名稱:revscoring,代碼行數:9,代碼來源:util.py

示例14: send_unsupported_protocol

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def send_unsupported_protocol(self, envelope: Envelope) -> None:
        """
        Handle the received envelope in case the protocol is not supported.

        :param envelope: the envelope
        :return: None
        """
        self.context.logger.warning(
            "Unsupported protocol: {}. You might want to add a handler for this protocol.".format(
                envelope.protocol_id
            )
        )
        encoded_protocol_id = base64.b85encode(str.encode(str(envelope.protocol_id)))
        encoded_envelope = base64.b85encode(envelope.encode())
        reply = DefaultMessage(
            dialogue_reference=("", ""),
            message_id=1,
            target=0,
            performative=DefaultMessage.Performative.ERROR,
            error_code=DefaultMessage.ErrorCode.UNSUPPORTED_PROTOCOL,
            error_msg="Unsupported protocol.",
            error_data={
                "protocol_id": encoded_protocol_id,
                "envelope": encoded_envelope,
            },
        )
        reply.counterparty = envelope.sender
        self.context.outbox.put_message(message=reply) 
開發者ID:fetchai,項目名稱:agents-aea,代碼行數:30,代碼來源:handlers.py

示例15: send_unsupported_skill

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b85encode [as 別名]
def send_unsupported_skill(self, envelope: Envelope) -> None:
        """
        Handle the received envelope in case the skill is not supported.

        :param envelope: the envelope
        :return: None
        """
        if envelope.skill_id is None:
            self.context.logger.warning(
                "Cannot handle envelope: no active handler registered for the protocol_id='{}'.".format(
                    envelope.protocol_id
                )
            )
        else:
            self.context.logger.warning(
                "Cannot handle envelope: no active handler registered for the protocol_id='{}' and skill_id='{}'.".format(
                    envelope.protocol_id, envelope.skill_id
                )
            )
        encoded_envelope = base64.b85encode(envelope.encode())
        reply = DefaultMessage(
            dialogue_reference=("", ""),
            message_id=1,
            target=0,
            performative=DefaultMessage.Performative.ERROR,
            error_code=DefaultMessage.ErrorCode.UNSUPPORTED_SKILL,
            error_msg="Unsupported skill.",
            error_data={"envelope": encoded_envelope},
        )
        reply.counterparty = envelope.sender
        self.context.outbox.put_message(message=reply) 
開發者ID:fetchai,項目名稱:agents-aea,代碼行數:33,代碼來源:handlers.py


注:本文中的base64.b85encode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。