Python codecs 模块,escape_decode() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用codecs.escape_decode()

项目:DevOps    作者:YoLoveLife    | 项目源码 | 文件源码
def files_in_archive(self, force_refresh=False):
        if self._files_in_archive and not force_refresh:
            return self._files_in_archive

        cmd = [ self.cmd_path, '--list', '-C', self.dest ]
        if self.zipflag:
            cmd.append(self.zipflag)
        if self.opts:
            cmd.extend([ '--show-transformed-names' ] + self.opts)
        if self.excludes:
            cmd.extend([ '--exclude=' + quote(f) for f in self.excludes ])
        cmd.extend([ '-f', self.src ])
        rc, out, err = self.module.run_command(cmd, cwd=self.dest, environ_update=dict(LANG='C', LC_ALL='C', LC_MESSAGES='C'))
        if rc != 0:
            raise UnarchiveError('Unable to list files in the archive')

        for filename in out.splitlines():
            # Compensate for locale-related problems in gtar output (octal unicode representation) #11348
#            filename = filename.decode('string_escape')
            filename = codecs.escape_decode(filename)[0]
            if filename and filename not in self.excludes:
                self._files_in_archive.append(to_native(filename))
        return self._files_in_archive
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:infi.clickhouse_orm    作者:Infinidat    | 项目源码 | 文件源码
def unescape(value):
    return codecs.escape_decode(value)[0].decode('utf-8')
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:RPoint    作者:george17-meet    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:Taigabot    作者:FrozenPigs    | 项目源码 | 文件源码
def raw_bytes(raw):
    """Make a bytes object out of a raw string.

    This is analogous to raw_unicode, but processes byte escape characters
    to produce a bytes object.
    """
    return codecs.escape_decode(raw)[0]
项目:habilitacion    作者:GabrielBD    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:threatdetectionservice    作者:flyballlabs    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:DevOps    作者:YoLoveLife    | 项目源码 | 文件源码
def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None, ignore_hidden=False):
    ''' assemble a file from a directory of fragments '''
    tmpfd, temp_path = tempfile.mkstemp()
    tmp = os.fdopen(tmpfd, 'wb')
    delimit_me = False
    add_newline = False

    for f in sorted(os.listdir(src_path)):
        if compiled_regexp and not compiled_regexp.search(f):
            continue
        fragment = u"%s/%s" % (src_path, f)
        if not os.path.isfile(fragment) or (ignore_hidden and os.path.basename(fragment).startswith('.')):
            continue
        fragment_content = open(fragment, 'rb').read()

        # always put a newline between fragments if the previous fragment didn't end with a newline.
        if add_newline:
            tmp.write(b('\n'))

        # delimiters should only appear between fragments
        if delimit_me:
            if delimiter:
                # un-escape anything like newlines
                delimiter = codecs.escape_decode(delimiter)[0]
                tmp.write(delimiter)
                # always make sure there's a newline after the
                # delimiter, so lines don't run together
                if delimiter[-1] != b('\n'):
                    tmp.write(b('\n'))

        tmp.write(fragment_content)
        delimit_me = True
        if fragment_content.endswith(b('\n')):
            add_newline = False
        else:
            add_newline = True

    tmp.close()
    return temp_path
项目:DevOps    作者:YoLoveLife    | 项目源码 | 文件源码
def _assemble_from_fragments(self, src_path, delimiter=None, compiled_regexp=None, ignore_hidden=False):
        ''' assemble a file from a directory of fragments '''

        tmpfd, temp_path = tempfile.mkstemp()
        tmp = os.fdopen(tmpfd, 'wb')
        delimit_me = False
        add_newline = False

        for f in (to_text(p, errors='surrogate_or_strict') for p in sorted(os.listdir(src_path))):
            if compiled_regexp and not compiled_regexp.search(f):
                continue
            fragment = u"%s/%s" % (src_path, f)
            if not os.path.isfile(fragment) or (ignore_hidden and os.path.basename(fragment).startswith('.')):
                continue

            fragment_content = open(self._loader.get_real_file(fragment), 'rb').read()

            # always put a newline between fragments if the previous fragment didn't end with a newline.
            if add_newline:
                tmp.write(b'\n')

            # delimiters should only appear between fragments
            if delimit_me:
                if delimiter:
                    # un-escape anything like newlines
                    delimiter = codecs.escape_decode(delimiter)[0]
                    tmp.write(delimiter)
                    # always make sure there's a newline after the
                    # delimiter, so lines don't run together
                    if delimiter[-1] != b'\n':
                        tmp.write(b'\n')

            tmp.write(fragment_content)
            delimit_me = True
            if fragment_content.endswith(b'\n'):
                add_newline = False
            else:
                add_newline = True

        tmp.close()
        return temp_path
项目:Indushell    作者:SecarmaLabs    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def load_string(self):
        orig = self.readline()
        rep = orig[:-1]
        for q in (b'"', b"'"): # double or single quote
            if rep.startswith(q):
                if not rep.endswith(q):
                    raise ValueError("insecure string pickle")
                rep = rep[len(q):-len(q)]
                break
        else:
            raise ValueError("insecure string pickle: %r" % orig)
        self.append(codecs.escape_decode(rep)[0]
                    .decode(self.encoding, self.errors))
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_empty(self):
        self.assertEqual(codecs.escape_decode(""), ("", 0))
项目:CaScale    作者:Thatsillogical    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:respeaker_virtualenv    作者:respeaker    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:infinite-lorem-ipsum    作者:patjm1992    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_empty(self):
        self.assertEqual(codecs.escape_decode(""), ("", 0))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_raw(self):
        decode = codecs.escape_decode
        for b in range(256):
            b = chr(b)
            if b != '\\':
                self.assertEqual(decode(b + '0'), (b + '0', 2))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_escape(self):
        decode = codecs.escape_decode
        check = coding_checker(self, decode)
        check(b"[\\\n]", b"[]")
        check(br'[\"]', b'["]')
        check(br"[\']", b"[']")
        check(br"[\\]", br"[\]")
        check(br"[\a]", b"[\x07]")
        check(br"[\b]", b"[\x08]")
        check(br"[\t]", b"[\x09]")
        check(br"[\n]", b"[\x0a]")
        check(br"[\v]", b"[\x0b]")
        check(br"[\f]", b"[\x0c]")
        check(br"[\r]", b"[\x0d]")
        check(br"[\7]", b"[\x07]")
        check(br"[\8]", br"[\8]")
        check(br"[\78]", b"[\x078]")
        check(br"[\41]", b"[!]")
        check(br"[\418]", b"[!8]")
        check(br"[\101]", b"[A]")
        check(br"[\1010]", b"[A0]")
        check(br"[\501]", b"[A]")
        check(br"[\x41]", b"[A]")
        check(br"[\X41]", br"[\X41]")
        check(br"[\x410]", b"[A0]")
        for b in range(256):
            b = chr(b)
            if b not in '\n"\'\\abtnvfr01234567x':
                check('\\' + b, '\\' + b)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_errors(self):
        decode = codecs.escape_decode
        self.assertRaises(ValueError, decode, br"\x")
        self.assertRaises(ValueError, decode, br"[\x]")
        self.assertEqual(decode(br"[\x]\x", "ignore"), (b"[]", 6))
        self.assertEqual(decode(br"[\x]\x", "replace"), (b"[?]?", 6))
        self.assertRaises(ValueError, decode, br"\x0")
        self.assertRaises(ValueError, decode, br"[\x0]")
        self.assertEqual(decode(br"[\x0]\x0", "ignore"), (b"[]", 8))
        self.assertEqual(decode(br"[\x0]\x0", "replace"), (b"[?]?", 8))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_empty(self):
        self.assertEqual(codecs.escape_decode(""), ("", 0))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_raw(self):
        decode = codecs.escape_decode
        for b in range(256):
            b = chr(b)
            if b != '\\':
                self.assertEqual(decode(b + '0'), (b + '0', 2))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_escape(self):
        decode = codecs.escape_decode
        check = coding_checker(self, decode)
        check(b"[\\\n]", b"[]")
        check(br'[\"]', b'["]')
        check(br"[\']", b"[']")
        check(br"[\\]", br"[\]")
        check(br"[\a]", b"[\x07]")
        check(br"[\b]", b"[\x08]")
        check(br"[\t]", b"[\x09]")
        check(br"[\n]", b"[\x0a]")
        check(br"[\v]", b"[\x0b]")
        check(br"[\f]", b"[\x0c]")
        check(br"[\r]", b"[\x0d]")
        check(br"[\7]", b"[\x07]")
        check(br"[\8]", br"[\8]")
        check(br"[\78]", b"[\x078]")
        check(br"[\41]", b"[!]")
        check(br"[\418]", b"[!8]")
        check(br"[\101]", b"[A]")
        check(br"[\1010]", b"[A0]")
        check(br"[\501]", b"[A]")
        check(br"[\x41]", b"[A]")
        check(br"[\X41]", br"[\X41]")
        check(br"[\x410]", b"[A0]")
        for b in range(256):
            b = chr(b)
            if b not in '\n"\'\\abtnvfr01234567x':
                check('\\' + b, '\\' + b)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_errors(self):
        decode = codecs.escape_decode
        self.assertRaises(ValueError, decode, br"\x")
        self.assertRaises(ValueError, decode, br"[\x]")
        self.assertEqual(decode(br"[\x]\x", "ignore"), (b"[]", 6))
        self.assertEqual(decode(br"[\x]\x", "replace"), (b"[?]?", 6))
        self.assertRaises(ValueError, decode, br"\x0")
        self.assertRaises(ValueError, decode, br"[\x0]")
        self.assertEqual(decode(br"[\x0]\x0", "ignore"), (b"[]", 8))
        self.assertEqual(decode(br"[\x0]\x0", "replace"), (b"[?]?", 8))
项目:chalktalk_docs    作者:loremIpsum1771    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:python-group-proj    作者:Sharcee    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:covar_me_app    作者:CovarMe    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:better-exceptions    作者:Qix-    | 项目源码 | 文件源码
def to_byte(val):
    unicode_type = str if PY3 else unicode
    if isinstance(val, unicode_type):
        try:
            return val.encode(ENCODING)
        except UnicodeEncodeError:
            if PY3:
                return codecs.escape_decode(val)[0]
            else:
                return val.encode("unicode-escape").decode("string-escape")

    return val
项目:Callandtext    作者:iaora    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:NeuroMobile    作者:AndrewADykman    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_empty(self):
        self.assertEqual(codecs.escape_decode(b""), (b"", 0))
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_raw(self):
        decode = codecs.escape_decode
        for b in range(256):
            b = bytes([b])
            if b != b'\\':
                self.assertEqual(decode(b + b'0'), (b + b'0', 2))
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_escape(self):
        decode = codecs.escape_decode
        check = coding_checker(self, decode)
        check(b"[\\\n]", b"[]")
        check(br'[\"]', b'["]')
        check(br"[\']", b"[']")
        check(br"[\\]", br"[\]")
        check(br"[\a]", b"[\x07]")
        check(br"[\b]", b"[\x08]")
        check(br"[\t]", b"[\x09]")
        check(br"[\n]", b"[\x0a]")
        check(br"[\v]", b"[\x0b]")
        check(br"[\f]", b"[\x0c]")
        check(br"[\r]", b"[\x0d]")
        check(br"[\7]", b"[\x07]")
        check(br"[\8]", br"[\8]")
        check(br"[\78]", b"[\x078]")
        check(br"[\41]", b"[!]")
        check(br"[\418]", b"[!8]")
        check(br"[\101]", b"[A]")
        check(br"[\1010]", b"[A0]")
        check(br"[\501]", b"[A]")
        check(br"[\x41]", b"[A]")
        check(br"[\X41]", br"[\X41]")
        check(br"[\x410]", b"[A0]")
        for b in range(256):
            if b not in b'\n"\'\\abtnvfr01234567x':
                b = bytes([b])
                check(b'\\' + b, b'\\' + b)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_errors(self):
        decode = codecs.escape_decode
        self.assertRaises(ValueError, decode, br"\x")
        self.assertRaises(ValueError, decode, br"[\x]")
        self.assertEqual(decode(br"[\x]\x", "ignore"), (b"[]", 6))
        self.assertEqual(decode(br"[\x]\x", "replace"), (b"[?]?", 6))
        self.assertRaises(ValueError, decode, br"\x0")
        self.assertRaises(ValueError, decode, br"[\x0]")
        self.assertEqual(decode(br"[\x0]\x0", "ignore"), (b"[]", 8))
        self.assertEqual(decode(br"[\x0]\x0", "replace"), (b"[?]?", 8))
项目:WebAct    作者:CreatCodeBuild    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:PornGuys    作者:followloda    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def decode(self, input, final=False):
        return codecs.escape_decode(input, self.errors)[0]