本文整理汇总了Python中base64.encode方法的典型用法代码示例。如果您正苦于以下问题:Python base64.encode方法的具体用法?Python base64.encode怎么用?Python base64.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类base64
的用法示例。
在下文中一共展示了base64.encode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_payload
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import encode [as 别名]
def write_payload(self):
port = self._port
tar_path = self.create_payload_tar()
log.debug(port.read_until("/ # "))
port.write("base64 -d | tar zxf -\n")
port.flush()
#(tarr, tarw) = os.pipe()
#tar = tarfile.open(mode='w|gz', fileobj=tarw)
#tar.add("payload/patch_toon.sh")
log.info("Transferring payload")
with open(tar_path, 'r') as f:
base64.encode(f, port)
os.remove(tar_path)
port.flush()
port.reset_input_buffer()
port.write("\x04")
port.flush()
示例2: encode
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import encode [as 别名]
def encode(input, output, encoding):
"""Encode common content-transfer-encodings (base64, quopri, uuencode)."""
if encoding == 'base64':
import base64
return base64.encode(input, output)
if encoding == 'quoted-printable':
import quopri
return quopri.encode(input, output, 0)
if encoding in ('uuencode', 'x-uuencode', 'uue', 'x-uue'):
import uu
return uu.encode(input, output)
if encoding in ('7bit', '8bit'):
return output.write(input.read())
if encoding in encodetab:
pipethrough(input, encodetab[encoding], output)
else:
raise ValueError, \
'unknown Content-Transfer-Encoding: %s' % encoding
# The following is no longer used for standard encodings
# XXX This requires that uudecode and mmencode are in $PATH
示例3: dump_struct
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import encode [as 别名]
def dump_struct(self, value, write, escape=escape):
i = id(value)
if i in self.memo:
raise TypeError, "cannot marshal recursive dictionaries"
self.memo[i] = None
dump = self.__dump
write("<value><struct>\n")
for k, v in value.items():
write("<member>\n")
if type(k) is not StringType:
if unicode and type(k) is UnicodeType:
k = k.encode(self.encoding)
else:
raise TypeError, "dictionary key must be string"
write("<name>%s</name>\n" % escape(k))
dump(v, write)
write("</member>\n")
write("</struct></value>\n")
del self.memo[i]
示例4: send_content
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import encode [as 别名]
def send_content(self, connection, request_body):
connection.putheader("Content-Type", "text/xml")
#optionally encode the request
if (self.encode_threshold is not None and
self.encode_threshold < len(request_body) and
gzip):
connection.putheader("Content-Encoding", "gzip")
request_body = gzip_encode(request_body)
connection.putheader("Content-Length", str(len(request_body)))
connection.endheaders(request_body)
##
# Parse response.
#
# @param file Stream.
# @return Response tuple and target method.
示例5: dump_struct
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import encode [as 别名]
def dump_struct(self, value, write, escape=escape):
i = id(value)
if i in self.memo:
raise TypeError, "cannot marshal recursive dictionaries"
self.memo[i] = None
dump = self.__dump
write("<value><struct>\n")
for k, v in value.items():
write("<member>\n")
if type(k) is StringType:
k = escape(k)
elif unicode and type(k) is UnicodeType:
k = escape(k).encode(self.encoding, 'xmlcharrefreplace')
else:
raise TypeError, "dictionary key must be string"
write("<name>%s</name>\n" % k)
dump(v, write)
write("</member>\n")
write("</struct></value>\n")
del self.memo[i]
示例6: test_encode
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import encode [as 别名]
def test_encode(self):
eq = self.assertEqual
from io import BytesIO, StringIO
infp = BytesIO(b'abcdefghijklmnopqrstuvwxyz'
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
b'0123456789!@#0^&*();:<>,. []{}')
outfp = BytesIO()
base64.encode(infp, outfp)
eq(outfp.getvalue(),
b'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE'
b'RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT'
b'Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n')
# Non-binary files
self.assertRaises(TypeError, base64.encode, StringIO('abc'), BytesIO())
self.assertRaises(TypeError, base64.encode, BytesIO(b'abc'), StringIO())
self.assertRaises(TypeError, base64.encode, StringIO('abc'), StringIO())
示例7: dump_struct
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import encode [as 别名]
def dump_struct(self, value, write, escape=escape):
i = id(value)
if self.memo.has_key(i):
raise TypeError, "cannot marshal recursive dictionaries"
self.memo[i] = None
dump = self.__dump
write("<value><struct>\n")
for k, v in value.items():
write("<member>\n")
if type(k) is not StringType:
if unicode and type(k) is UnicodeType:
k = k.encode(self.encoding)
else:
raise TypeError, "dictionary key must be string"
write("<name>%s</name>\n" % escape(k))
dump(v, write)
write("</member>\n")
write("</struct></value>\n")
del self.memo[i]
示例8: _stringify
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import encode [as 别名]
def _stringify(string):
# convert to 7-bit ascii if possible
try:
return string.encode("ascii")
except UnicodeError:
return string
示例9: encode
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import encode [as 别名]
def encode(self, out):
out.write("<value><boolean>%d</boolean></value>\n" % self.value)