本文整理匯總了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)