Python string.encode() Examples
The following are 30
code examples of string.encode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
string
, or try the search function
.
Example #1
Source File: xmlrpclib.py From pmatic with GNU General Public License v2.0 | 6 votes |
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.
Example #2
Source File: xmlrpclib.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
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.
Example #3
Source File: xmlrpclib.py From oss-ftp with MIT License | 6 votes |
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.
Example #4
Source File: xmlrpclib.py From ironpython2 with Apache License 2.0 | 6 votes |
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.
Example #5
Source File: xmlrpclib.py From BinderFilter with MIT License | 6 votes |
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.
Example #6
Source File: xmlrpclib.py From meddle with MIT License | 6 votes |
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.
Example #7
Source File: provision.py From aiotuya with MIT License | 6 votes |
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
Example #8
Source File: xmlrpclib.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def encode(self, out): out.write("<value><base64>\n") base64.encode(StringIO.StringIO(self.data), out) out.write("</base64></value>\n")
Example #9
Source File: utils.py From zulip with Apache License 2.0 | 5 votes |
def make_safe_digest(string: str, hash_func: Callable[[bytes], Any]=hashlib.sha1) -> str: """ return a hex digest of `string`. """ # hashlib.sha1, md5, etc. expect bytes, so non-ASCII strings must # be encoded. return hash_func(string.encode('utf-8')).hexdigest()
Example #10
Source File: utils.py From zulip with Apache License 2.0 | 5 votes |
def generate_api_key() -> str: choices = string.ascii_letters + string.digits altchars = ''.join([choices[ord(os.urandom(1)) % 62] for _ in range(2)]).encode("utf-8") api_key = base64.b64encode(os.urandom(24), altchars=altchars).decode("utf-8") return api_key
Example #11
Source File: encoding.py From NullCTF with GNU General Public License v3.0 | 5 votes |
def b64(self, ctx, encode_or_decode, string): byted_str = str.encode(string) if encode_or_decode == 'decode': decoded = base64.b64decode(byted_str).decode('utf-8') await ctx.send(decoded) if encode_or_decode == 'encode': encoded = base64.b64encode(byted_str).decode('utf-8').replace('\n', '') await ctx.send(encoded)
Example #12
Source File: xmlrpclib.py From pmatic with GNU General Public License v2.0 | 5 votes |
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)
Example #13
Source File: coders.py From gd.py with MIT License | 5 votes |
def unzip(cls, string: Union[bytes, str]) -> Union[bytes, str]: """Decompresses a level string. Used to unzip level data. Parameters ---------- string: Union[:class:`bytes`, :class:`str`] String to unzip, encoded in Base64. Returns ------- Union[:class:`bytes`, :class:`str`] Unzipped level data, as a stream. """ if isinstance(string, str): string = string.encode() unzipped = inflate(urlsafe_b64decode(string)) try: final = unzipped.decode() except UnicodeDecodeError: final = unzipped return final
Example #14
Source File: xmlrpclib.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _stringify(string): # convert to 7-bit ascii if possible try: return string.encode("ascii") except UnicodeError: return string
Example #15
Source File: xmlrpclib.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def encode(self, out): out.write("<value><boolean>%d</boolean></value>\n" % self.value)
Example #16
Source File: xmlrpclib.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def encode(self, out): out.write("<value><dateTime.iso8601>") out.write(self.value) out.write("</dateTime.iso8601></value>\n")
Example #17
Source File: xmlrpclib.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #18
Source File: gen_vault.py From picoCTF with MIT License | 5 votes |
def write_file(fname, string): with open(fname, 'wb') as out: out.write(string.encode('utf-8'))
Example #19
Source File: xmlrpclib.py From pmatic with GNU General Public License v2.0 | 5 votes |
def __init__(self, uri, transport=None, encoding=None, verbose=0, allow_none=0, use_datetime=0): # establish a "logical" server connection if 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) else: transport = Transport(use_datetime=use_datetime) self.__transport = transport self.__encoding = encoding self.__verbose = verbose self.__allow_none = allow_none
Example #20
Source File: encoding.py From NullCTF with GNU General Public License v3.0 | 5 votes |
def hex(self, ctx, encode_or_decode, string): if encode_or_decode == 'decode': string = string.replace(" ", "") decoded = binascii.unhexlify(string).decode('ascii') await ctx.send(decoded) if encode_or_decode == 'encode': byted = string.encode() encoded = binascii.hexlify(byted).decode('ascii') await ctx.send(encoded)
Example #21
Source File: xmlrpclib.py From pmatic with GNU General Public License v2.0 | 5 votes |
def dump_unicode(self, value, write, escape=escape): value = value.encode(self.encoding) write("<value><string>") write(escape(value)) write("</string></value>\n")
Example #22
Source File: xmlrpclib.py From pmatic with GNU General Public License v2.0 | 5 votes |
def encode(self, out): out.write("<value><base64>\n") base64.encode(StringIO.StringIO(self.data), out) out.write("</base64></value>\n")
Example #23
Source File: xmlrpclib.py From pmatic with GNU General Public License v2.0 | 5 votes |
def encode(self, out): out.write("<value><dateTime.iso8601>") out.write(self.value) out.write("</dateTime.iso8601></value>\n")
Example #24
Source File: xmlrpclib.py From pmatic with GNU General Public License v2.0 | 5 votes |
def encode(self, out): out.write("<value><boolean>%d</boolean></value>\n" % self.value)
Example #25
Source File: xmlrpclib.py From pmatic with GNU General Public License v2.0 | 5 votes |
def _stringify(string): # convert to 7-bit ascii if possible try: return string.encode("ascii") except UnicodeError: return string
Example #26
Source File: _pydev_xmlrpclib.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
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)
Example #27
Source File: _pydev_xmlrpclib.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
def dump_unicode(self, value, write, escape=escape): value = value.encode(self.encoding) write("<value><string>") write(escape(value)) write("</string></value>\n")
Example #28
Source File: _pydev_xmlrpclib.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
def encode(self, out): out.write("<value><base64>\n") base64.encode(StringIO.StringIO(self.data), out) out.write("</base64></value>\n")
Example #29
Source File: _pydev_xmlrpclib.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
def encode(self, out): out.write("<value><dateTime.iso8601>") out.write(self.value) out.write("</dateTime.iso8601></value>\n")
Example #30
Source File: _pydev_xmlrpclib.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
def encode(self, out): out.write("<value><boolean>%d</boolean></value>\n" % self.value)