本文整理汇总了Python中base64.encode方法的典型用法代码示例。如果您正苦于以下问题:Python base64.encode方法的具体用法?Python base64.encode怎么用?Python base64.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块base64的用法示例。
在下文中一共展示了base64.encode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: write_payload
点赞 6
# 需要导入模块: 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()
开发者ID:martenjacobs,项目名称:ToonRooter,代码行数:23,
示例2: encode
点赞 6
# 需要导入模块: 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
开发者ID:glmcdona,项目名称:meddle,代码行数:24,
示例3: dump_struct
点赞 6
# 需要导入模块: 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("\n")
for k, v in value.items():
write("\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("%s\n" % escape(k))
dump(v, write)
write("\n")
write("\n")
del self.memo[i]
开发者ID:glmcdona,项目名称:meddle,代码行数:21,
示例4: send_content
点赞 6
# 需要导入模块: 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.
开发者ID:glmcdona,项目名称:meddle,代码行数:20,
示例5: dump_struct
点赞 6
# 需要导入模块: 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("\n")
for k, v in value.items():
write("\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("%s\n" % k)
dump(v, write)
write("\n")
write("\n")
del self.memo[i]
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,
示例6: test_encode
点赞 6
# 需要导入模块: 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())
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,
示例7: dump_struct
点赞 6
# 需要导入模块: 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("\n")
for k, v in value.items():
write("\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("%s\n" % escape(k))
dump(v, write)
write("\n")
write("\n")
del self.memo[i]
开发者ID:ofermend,项目名称:medicare-demo,代码行数:21,
示例8: _stringify
点赞 5
# 需要导入模块: 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
开发者ID:glmcdona,项目名称:meddle,代码行数:8,
示例9: encode
点赞 5
# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import encode [as 别名]
def encode(self, out):
out.write("%d\n" % self.value)
开发者ID:glmcdona,项目名称:meddle,代码行数:4,
注:本文中的base64.encode方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。