python类escape_encode()的实例源码

tcp_serial_redirect.py 文件源码 项目:btc-fpga-miner 作者: marsohod4you 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def writer(self):
        """loop forever and copy socket->serial"""
        while self.alive:
            try:
                data = self.socket.recv(1024)
                if not data:
                    break
                if self.ser_newline and self.net_newline:
                    # do the newline conversion
                    # XXX fails for CR+LF in input when it is cut in half at the begin or end of the string
                    data = ser_newline.join(data.split(net_newline))
                self.serial.write(data)                 # get a bunch of bytes and send them
                # the spy shows what's on the serial port, so log it after converting newlines
                if self.spy:
                    sys.stdout.write(codecs.escape_encode(data)[0])
                    sys.stdout.flush()
            except socket.error, msg:
                sys.stderr.write('ERROR: %s\n' % msg)
                # probably got disconnected
                break
        self.alive = False
        self.thread_read.join()
python.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def _escape_bytes(val):
        """
        If val is pure ascii, returns it as a str(), otherwise escapes
        into a sequence of escaped bytes:
        b'\xc3\xb4\xc5\xd6' -> u'\\xc3\\xb4\\xc5\\xd6'

        note:
           the obvious "v.decode('unicode-escape')" will return
           valid utf-8 unicode if it finds them in the string, but we
           want to return escaped bytes for any byte, even if they match
           a utf-8 string.
        """
        # source: http://goo.gl/bGsnwC
        import codecs
        encoded_bytes, _ = codecs.escape_encode(val)
        return encoded_bytes.decode('ascii')
string_escape.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:swjtu-pyscraper 作者: Desgard 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
compat.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _escape_strings(val):
        """If val is pure ascii, returns it as a str().  Otherwise, escapes
        bytes objects into a sequence of escaped bytes:

        b'\xc3\xb4\xc5\xd6' -> u'\\xc3\\xb4\\xc5\\xd6'

        and escapes unicode objects into a sequence of escaped unicode
        ids, e.g.:

        '4\\nV\\U00043efa\\x0eMXWB\\x1e\\u3028\\u15fd\\xcd\\U0007d944'

        note:
           the obvious "v.decode('unicode-escape')" will return
           valid utf-8 unicode if it finds them in bytes, but we
           want to return escaped bytes for any byte, even if they match
           a utf-8 string.

        """
        if isinstance(val, bytes):
            if val:
                # source: http://goo.gl/bGsnwC
                encoded_bytes, _ = codecs.escape_encode(val)
                return encoded_bytes.decode('ascii')
            else:
                # empty bytes crashes codecs.escape_encode (#1087)
                return ''
        else:
            return val.encode('unicode_escape').decode('ascii')
string_escape.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:RPoint 作者: george17-meet 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:habilitacion 作者: GabrielBD 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:threatdetectionservice 作者: flyballlabs 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:oa_qian 作者: sunqb 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:Indushell 作者: SecarmaLabs 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
test_codecs.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_encode_length(self):
        # Issue 3739
        encoder = codecs.getencoder("unicode_internal")
        self.assertEqual(encoder("a")[1], 1)
        self.assertEqual(encoder("\xe9\u0142")[1], 2)

        self.assertEqual(codecs.escape_encode(br'\x00')[1], 4)

# From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html
string_escape.py 文件源码 项目:CaScale 作者: Thatsillogical 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:pyetje 作者: rorlika 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:respeaker_virtualenv 作者: respeaker 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:infinite-lorem-ipsum 作者: patjm1992 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
compat.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _escape_strings(val):
        """If val is pure ascii, returns it as a str().  Otherwise, escapes
        bytes objects into a sequence of escaped bytes:

        b'\xc3\xb4\xc5\xd6' -> u'\\xc3\\xb4\\xc5\\xd6'

        and escapes unicode objects into a sequence of escaped unicode
        ids, e.g.:

        '4\\nV\\U00043efa\\x0eMXWB\\x1e\\u3028\\u15fd\\xcd\\U0007d944'

        note:
           the obvious "v.decode('unicode-escape')" will return
           valid utf-8 unicode if it finds them in bytes, but we
           want to return escaped bytes for any byte, even if they match
           a utf-8 string.

        """
        if isinstance(val, bytes):
            if val:
                # source: http://goo.gl/bGsnwC
                encoded_bytes, _ = codecs.escape_encode(val)
                return encoded_bytes.decode('ascii')
            else:
                # empty bytes crashes codecs.escape_encode (#1087)
                return ''
        else:
            return val.encode('unicode_escape').decode('ascii')
string_escape.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:python-group-proj 作者: Sharcee 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]
string_escape.py 文件源码 项目:covar_me_app 作者: CovarMe 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def encode(self, input, final=False):
        return codecs.escape_encode(input, self.errors)[0]


问题


面经


文章

微信
公众号

扫码关注公众号