本文整理汇总了Python中string.encode方法的典型用法代码示例。如果您正苦于以下问题:Python string.encode方法的具体用法?Python string.encode怎么用?Python string.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string
的用法示例。
在下文中一共展示了string.encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_content
# 需要导入模块: import string [as 别名]
# 或者: from string 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.
示例2: sendlinkdata
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def sendlinkdata(self):
delay = 0
for x in range(30):
if self.abortbroadcast:
break
if delay > 26:
delay = 6
for s in self.provisiondata:
string="\x00"*s
self.transport.sendto(string.encode(), self.target)
await aio.sleep(delay/1000.0)
await aio.sleep(0.2)
delay += 3
self.abortbroadcast = False
示例3: write_file
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def write_file(fname, string):
with open(fname, 'wb') as out:
out.write(string.encode('utf-8'))
示例4: _data_mem_size
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def _data_mem_size(self):
# This is probably better to be done in the parsing/writeout stage...
data_len = 0
for e in self.xml_doc.iter(tag=etree.Element):
t = e.attrib.get('__type')
if t is None:
continue
count = e.attrib.get('__count', 1)
size = e.attrib.get('__size', 1)
x = xml_formats[xml_types[t]]
if x['count'] > 0:
m = x['count'] * calcsize(x['type']) * count * size
elif x['name'] == 'bin':
m = len(e.text) // 2
else: # string
# null terminator space
m = len(e.text.encode(self.encoding)) + 1
if m <= 4:
continue
if x['name'] == 'bin':
data_len += (m + 1) & ~1
else:
data_len += (m + 3) & ~3
return data_len
示例5: data_append_string
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def data_append_string(self, string):
string = bytes(string.encode(self.encoding) + b'\0')
self.data_append_auto(string)
# has its own separate state and other assorted garbage
示例6: append_node_name
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def append_node_name(self, name):
if self.compressed:
pack_sixbit(name, self.nodeBuf)
else:
enc = name.encode(self.encoding)
self.nodeBuf.append_u8((len(enc) - 1) | 64)
self.nodeBuf.append_bytes(enc)
示例7: main
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def main():
if len(sys.argv) != 2:
print('bin_xml.py file.[xml/bin]')
exit()
with open(sys.argv[1], 'rb') as f:
input = f.read()
xml = KBinXML(input)
if KBinXML.is_binary_xml(input):
stdout.write(xml.to_text().encode('utf-8'))
else:
stdout.write(xml.to_binary())
示例8: _stringify
# 需要导入模块: import string [as 别名]
# 或者: from string 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 string [as 别名]
# 或者: from string import encode [as 别名]
def encode(self, out):
out.write("<value><boolean>%d</boolean></value>\n" % self.value)
示例10: dump_unicode
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def dump_unicode(self, value, write, escape=escape):
value = value.encode(self.encoding)
write("<value><string>")
write(escape(value))
write("</string></value>\n")
示例11: dump_instance
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def dump_instance(self, value, write):
# check for special wrappers
if value.__class__ in WRAPPERS:
self.write = write
value.encode(self)
del self.write
else:
# store instance attributes as a struct (really?)
self.dump_struct(value.__dict__, write)
示例12: dump_unicode
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def dump_unicode(self, value, write, escape=escape):
write("<value><string>")
write(escape(value).encode(self.encoding, 'xmlcharrefreplace'))
write("</string></value>\n")
示例13: __init__
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def __init__(self, uri, transport=None, encoding=None, verbose=0,
allow_none=0, use_datetime=0, context=None):
# establish a "logical" server connection
if unicode and isinstance(uri, unicode):
uri = uri.encode('ISO-8859-1')
# get the url
import urllib
type, uri = urllib.splittype(uri)
if type not in ("http", "https"):
raise IOError, "unsupported XML-RPC protocol"
self.__host, self.__handler = urllib.splithost(uri)
if not self.__handler:
self.__handler = "/RPC2"
if transport is None:
if type == "https":
transport = SafeTransport(use_datetime=use_datetime, context=context)
else:
transport = Transport(use_datetime=use_datetime)
self.__transport = transport
self.__encoding = encoding
self.__verbose = verbose
self.__allow_none = allow_none
示例14: login
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def login(self):
data = {"countryCode": self.region,
"email": self.email,
"passwd": md5(self.password.encode()).hexdigest()}
if self.hmacsecret == None:
resu = await self._request( 'tuya.m.user.email.password.login',data)
else:
resu = await self._request( 'tuya.m.user.email.password.login',data, version="2.0")
self.sessionid = resu["sid"]
return resu
示例15: register
# 需要导入模块: import string [as 别名]
# 或者: from string import encode [as 别名]
def register(self):
data = {"countryCode": self.region,
"email": self.email,
"passwd": md5(self.password.encode()).hexdigest()}
resu = await self._request( 'tuya.m.user.email.register',data)
self.sessionid = resu["sid"]
return resu