本文整理汇总了Python中base64.b85decode方法的典型用法代码示例。如果您正苦于以下问题:Python base64.b85decode方法的具体用法?Python base64.b85decode怎么用?Python base64.b85decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类base64
的用法示例。
在下文中一共展示了base64.b85decode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def main():
# Install the library.
os.makedirs(os.path.join(INSTALL_PATH, 'lib'), exist_ok=True)
with open(LIBRARY_PATH, 'wb') as fd:
fd.write(gzip.decompress(base64.b85decode(ENCODED_LIB_CONTENTS)))
os.fchmod(fd.fileno(), 0o755)
# Install the wrapper script.
os.makedirs(os.path.join(INSTALL_PATH, 'bin'), exist_ok=True)
with open(SCRIPT_PATH, 'w') as fd:
fd.write(DROPBOX_WRAPPER_CONTENTS)
os.fchmod(fd.fileno(), 0o755)
print("Installed the library and the wrapper script at:\n %s\n %s" % (LIBRARY_PATH, SCRIPT_PATH))
print("(To uninstall, simply delete them.)")
# Check that the correct 'dropbox' is in the $PATH.
result = subprocess.check_output(['which', 'dropbox']).decode().rstrip()
if result != SCRIPT_PATH:
print()
print("You will need to fix your $PATH! Currently, %r takes precedence." % result)
示例2: main
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def main():
tmpdir = None
try:
# Create a temporary working directory
tmpdir = tempfile.mkdtemp()
# Unpack the zipfile into the temporary directory
pip_zip = os.path.join(tmpdir, "pip.zip")
with open(pip_zip, "wb") as fp:
fp.write(b85decode(DATA.replace(b"\n", b"")))
# Add the zipfile to sys.path so that we can import it
sys.path.insert(0, pip_zip)
# Run the bootstrap
bootstrap(tmpdir=tmpdir)
finally:
# Clean up our temporary working directory
if tmpdir:
shutil.rmtree(tmpdir, ignore_errors=True)
示例3: decode
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def decode(self, text):
if len(text) % 4:
text += "="*(4-(len(text)%4))
return base64.b85decode(text)
示例4: _restore_constant_
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def _restore_constant_(encoded_string: str) -> object:
"""Recovers a pickled gzipped constant object from base85 string representation."""
out = pickle.loads(gzip.decompress(base64.b85decode(encoded_string)))
assert isinstance(out, object)
return out
# These typing hints are provided here for use in the generated classes. They are obviously not part of the API.
示例5: unpackTree
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def unpackTree(data, dest):
try:
f = io.BytesIO(base64.b85decode(data))
with tarfile.open(fileobj=f, mode="r:xz") as tar:
tar.extractall(dest)
except OSError as e:
raise BuildError("Error unpacking files: {}".format(str(e)))
示例6: test_b85decode
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def test_b85decode(self):
eq = self.assertEqual
tests = {
b'': b'',
b'cXxL#aCvlSZ*DGca%T': b'www.python.org',
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""": bytes(range(255)),
b"""VPa!sWoBn+X=-b1ZEkOHadLBXb#`}nd3r%YLqtVJM@UIZOH55pPf$@("""
b"""Q&d$}S6EqEFflSSG&MFiI5{CeBQRbjDkv#CIy^osE+AW7dwl""":
b"""abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"""
b"""0123456789!@#0^&*();:<>,. []{}""",
b'Zf_uPVPs@!Zf7no': b'no padding..',
b'dS!BNAY*TBaB^jHb7^mG00000': b'zero compression\x00\x00\x00\x00',
b'dS!BNAY*TBaB^jHb7^mG0000': b'zero compression\x00\x00\x00',
b"""LT`0$WMOi7IsgCw00""": b"""Boundary:\x00\x00\x00\x00""",
b'Q*dEpWgug3ZE$irARr(h': b'Space compr: ',
b'{{': b'\xff',
b'|Nj': b'\xff'*2,
b'|Ns9': b'\xff'*3,
b'|NsC0': b'\xff'*4,
}
for data, res in tests.items():
eq(base64.b85decode(data), res)
eq(base64.b85decode(data.decode("ascii")), res)
self.check_other_types(base64.b85decode, b'cXxL#aCvlSZ*DGca%T',
b"www.python.org")
示例7: test_b85_padding
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [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")
示例8: test_b85decode_errors
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def test_b85decode_errors(self):
illegal = list(range(33)) + \
list(b'"\',./:[\\]') + \
list(range(128, 256))
for c in illegal:
with self.assertRaises(ValueError, msg=bytes([c])):
base64.b85decode(b'0000' + bytes([c]))
self.assertRaises(ValueError, base64.b85decode, b'|')
self.assertRaises(ValueError, base64.b85decode, b'|N')
self.assertRaises(ValueError, base64.b85decode, b'|Ns')
self.assertRaises(ValueError, base64.b85decode, b'|NsC')
self.assertRaises(ValueError, base64.b85decode, b'|NsC1')
示例9: test_decode_nonascii_str
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def test_decode_nonascii_str(self):
decode_funcs = (base64.b64decode,
base64.standard_b64decode,
base64.urlsafe_b64decode,
base64.b32decode,
base64.b16decode,
base64.b85decode,
base64.a85decode)
for f in decode_funcs:
self.assertRaises(ValueError, f, 'with non-ascii \xcb')
示例10: read_observations
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def read_observations(f):
for line in f:
observation = json.loads(line)
if 'cache' in observation:
observation['cache'] = pickle.loads(
base64.b85decode(bytes(observation['cache'], 'ascii')))
yield observation
示例11: b85decode
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def b85decode(b):
_b85dec = [None] * 256
for i, c in enumerate(iterbytes(_b85alphabet)):
_b85dec[c] = i
padding = (-len(b)) % 5
b = b + b'~' * padding
out = []
packI = struct.Struct('!I').pack
for i in range(0, len(b), 5):
chunk = b[i:i + 5]
acc = 0
try:
for c in iterbytes(chunk):
acc = acc * 85 + _b85dec[c]
except TypeError:
for j, c in enumerate(iterbytes(chunk)):
if _b85dec[c] is None:
raise ValueError(
'bad base85 character at position %d' % (i + j)
)
raise
try:
out.append(packI(acc))
except struct.error:
raise ValueError('base85 overflow in hunk starting at byte %d'
% i)
result = b''.join(out)
if padding:
result = result[:-padding]
return result
示例12: token_retrieve
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def token_retrieve(request):
token = None
if 'X_TOKEN' in request.META:
token = request.META['X_TOKEN']
elif 'HTTP_X_TOKEN' in request.META:
token = request.META['HTTP_X_TOKEN']
if token is not None:
if len(token) == 20:
token = UUID(hexlify(b85decode(token.encode())).decode())
if len(token) == 25:
hasher = Hasher(salt=settings.SECRET_KEY)
token = UUID(hasher.decode(token))
try:
token = Token.objects.get(id=token, is_active=True, is_anonymous=False)
request.user = token.owner
if token.due is not None and token.due < timezone.now():
token.is_active = False
token.save()
token = None
except Exception:
token = None
return token
示例13: unprocess
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b85decode [as 别名]
def unprocess(self, data):
super(DeenPluginBase85, self).unprocess(data)
# Remove new lines and carriage returns from
# Base85 encoded data.
data = data.replace(b'\n', b'').replace(b'\r', b'')
try:
data = base64.b85decode(data)
except (binascii.Error, TypeError, ValueError) as e:
self.error = e
self.log.error(self.error)
self.log.debug(self.error, exc_info=True)
return data