• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python _compat.text_type函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mutagen._compat.text_type函数的典型用法代码示例。如果您正苦于以下问题:Python text_type函数的具体用法?Python text_type怎么用?Python text_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了text_type函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: delete_frames

def delete_frames(deletes, filenames):

    try:
        deletes = frame_from_fsnative(deletes)
    except ValueError as err:
        print_(text_type(err), file=sys.stderr)

    frames = deletes.split(",")

    for filename in filenames:
        with _sig.block():
            if verbose:
                print_(u"deleting %s from" % deletes, filename,
                       file=sys.stderr)
            try:
                id3 = mutagen.id3.ID3(filename)
            except mutagen.id3.ID3NoHeaderError:
                if verbose:
                    print_(u"No ID3 header found; skipping.", file=sys.stderr)
            except Exception as err:
                print_(text_type(err), file=sys.stderr)
                raise SystemExit(1)
            else:
                for frame in frames:
                    id3.delall(frame)
                id3.save()
开发者ID:2216288075,项目名称:meiduo_project,代码行数:26,代码来源:mid3v2.py


示例2: call2

 def call2(self, *args):
     for arg in args:
         self.assertTrue(isinstance(arg, fsnative))
     old_stdout = sys.stdout
     old_stderr = sys.stderr
     try:
         out = StringIO()
         err = StringIO()
         sys.stdout = out
         sys.stderr = err
         try:
             ret = self._main([fsnative(self.TOOL_NAME)] + list(args))
         except SystemExit as e:
             ret = e.code
         ret = ret or 0
         out_val = out.getvalue()
         err_val = err.getvalue()
         if os.name == "nt" and PY2:
             encoding = getattr(sys.stdout, "encoding", None) or "mbcs"
             out_val = text_type(out_val, encoding)
             err_val = text_type(err_val, encoding)
         return (ret, out_val, err_val)
     finally:
         sys.stdout = old_stdout
         sys.stderr = old_stderr
开发者ID:quodlibet,项目名称:mutagen,代码行数:25,代码来源:test_tools.py


示例3: update_to_v24

    def update_to_v24(self):
        """Convert older tags into an ID3v2.4 tag.

        This updates old ID3v2 frames to ID3v2.4 ones (e.g. TYER to
        TDRC). If you intend to save tags, you must call this function
        at some point; it is called by default when loading the tag.
        """

        self.__update_common()

        # TDAT, TYER, and TIME have been turned into TDRC.
        try:
            date = text_type(self.get("TYER", ""))
            if date.strip(u"\x00"):
                self.pop("TYER")
                dat = text_type(self.get("TDAT", ""))
                if dat.strip("\x00"):
                    self.pop("TDAT")
                    date = "%s-%s-%s" % (date, dat[2:], dat[:2])
                    time = text_type(self.get("TIME", ""))
                    if time.strip("\x00"):
                        self.pop("TIME")
                        date += "T%s:%s:00" % (time[:2], time[2:])
                if "TDRC" not in self:
                    self.add(TDRC(encoding=0, text=date))
        except UnicodeDecodeError:
            # Old ID3 tags have *lots* of Unicode problems, so if TYER
            # is bad, just chuck the frames.
            pass

        # TORY can be the first part of a TDOR.
        if "TORY" in self:
            f = self.pop("TORY")
            if "TDOR" not in self:
                try:
                    self.add(TDOR(encoding=0, text=str(f)))
                except UnicodeDecodeError:
                    pass

        # IPLS is now TIPL.
        if "IPLS" in self:
            f = self.pop("IPLS")
            if "TIPL" not in self:
                self.add(TIPL(encoding=f.encoding, people=f.people))

        # These can't be trivially translated to any ID3v2.4 tags, or
        # should have been removed already.
        for key in ["RVAD", "EQUA", "TRDA", "TSIZ", "TDAT", "TIME"]:
            if key in self:
                del(self[key])

        # Recurse into chapters
        for f in self.getall("CHAP"):
            f.sub_frames.update_to_v24()
        for f in self.getall("CTOC"):
            f.sub_frames.update_to_v24()
开发者ID:2216288075,项目名称:meiduo_project,代码行数:56,代码来源:_tags.py


示例4: test_ASFGUIDAttribute_dunder

 def test_ASFGUIDAttribute_dunder(self):
     attr = ASFGUIDAttribute(data=b"\xff")
     self.assertEqual(bytes(attr), b"\xff")
     if PY3:
         self.assertEqual(text_type(attr), u"b'\\xff'")
         self.assertEqual(repr(attr), "ASFGUIDAttribute(b'\\xff')")
     else:
         self.assertEqual(text_type(attr), u"'\\xff'")
         self.assertEqual(repr(attr), "ASFGUIDAttribute('\\xff')")
     self.assertRaises(TypeError, int, attr)
开发者ID:Shutshutnunte,项目名称:mutagen,代码行数:10,代码来源:test_asf.py


示例5: list_tags_raw

def list_tags_raw(filenames):
    for filename in filenames:
        print_("Raw IDv2 tag info for", filename)
        try:
            id3 = mutagen.id3.ID3(filename, translate=False)
        except mutagen.id3.ID3NoHeaderError:
            print_(u"No ID3 header found; skipping.")
        except Exception as err:
            print_(text_type(err), file=sys.stderr)
            raise SystemExit(1)
        else:
            for frame in id3.values():
                print_(text_type(repr(frame)))
开发者ID:2216288075,项目名称:meiduo_project,代码行数:13,代码来源:mid3v2.py


示例6: test_types

 def test_types(self):
     if PY3:
         self.assertRaises(TypeError, ID3TimeStamp, b"blah")
     self.assertEquals(
         text_type(ID3TimeStamp(u"2000-01-01")), u"2000-01-01")
     self.assertEquals(
         bytes(ID3TimeStamp(u"2000-01-01")), b"2000-01-01")
开发者ID:gdelfresno,项目名称:mutagen,代码行数:7,代码来源:test__id3frames.py


示例7: __setitem__

    def __setitem__(self, key, values):
        """Set a key's value or values.

        Setting a value overwrites all old ones. The value may be a
        list of Unicode or UTF-8 strings, or a single Unicode or UTF-8
        string.

        """
        if not isinstance(values, list):
            values = [values]
        try:
            del(self[key])
        except KeyError:
            pass
        for value in values:
            if key in _standard_attribute_names:
                value = text_type(value)
            elif not isinstance(value, ASFBaseAttribute):
                if isinstance(value, string_types):
                    value = ASFUnicodeAttribute(value)
                elif isinstance(value, bool):
                    value = ASFBoolAttribute(value)
                elif isinstance(value, int):
                    value = ASFDWordAttribute(value)
                elif isinstance(value, long):
                    value = ASFQWordAttribute(value)
            self.append((key, value))
开发者ID:fourth-4,项目名称:mutagen,代码行数:27,代码来源:asf.py


示例8: test_ASFByteArrayAttribute_dunder

 def test_ASFByteArrayAttribute_dunder(self):
     attr = ASFByteArrayAttribute(data=b"\xff")
     self.assertEqual(bytes(attr), b"\xff")
     self.assertEqual(text_type(attr), u"[binary data (1 bytes)]")
     if PY3:
         self.assertEqual(repr(attr), r"ASFByteArrayAttribute(b'\xff')")
     else:
         self.assertEqual(repr(attr), r"ASFByteArrayAttribute('\xff')")
     self.assertRaises(TypeError, int, attr)
开发者ID:Shutshutnunte,项目名称:mutagen,代码行数:9,代码来源:test_asf.py


示例9: update

def update(options, filenames):
    encoding = options.encoding or getpreferredencoding()
    verbose = options.verbose
    noupdate = options.noupdate
    force_v1 = options.force_v1
    remove_v1 = options.remove_v1

    def conv(uni):
        return uni.encode('iso-8859-1').decode(encoding)

    for filename in filenames:
        with _sig.block():
            if verbose != "quiet":
                print_(u"Updating", filename)

            if has_id3v1(filename) and not noupdate and force_v1:
                mutagen.id3.delete(filename, False, True)

            try:
                id3 = mutagen.id3.ID3(filename)
            except mutagen.id3.ID3NoHeaderError:
                if verbose != "quiet":
                    print_(u"No ID3 header found; skipping...")
                continue
            except Exception as err:
                print_(text_type(err), file=sys.stderr)
                continue

            for tag in filter(lambda t: t.startswith(("T", "COMM")), id3):
                frame = id3[tag]
                if isinstance(frame, mutagen.id3.TimeStampTextFrame):
                    # non-unicode fields
                    continue
                try:
                    text = frame.text
                except AttributeError:
                    continue
                try:
                    text = [conv(x) for x in frame.text]
                except (UnicodeError, LookupError):
                    continue
                else:
                    frame.text = text
                    if not text or min(map(isascii, text)):
                        frame.encoding = 3
                    else:
                        frame.encoding = 1

            if verbose == "debug":
                print_(id3.pprint())

            if not noupdate:
                if remove_v1:
                    id3.save(filename, v1=False)
                else:
                    id3.save(filename)
开发者ID:YipYup,项目名称:headphones,代码行数:56,代码来源:mid3iconv.py


示例10: test_ASFUnicodeAttribute_dunder

    def test_ASFUnicodeAttribute_dunder(self):
        attr = ASFUnicodeAttribute(u"foo")

        self.assertEqual(bytes(attr), b"f\x00o\x00o\x00")
        self.assertEqual(text_type(attr), u"foo")
        if PY3:
            self.assertEqual(repr(attr), "ASFUnicodeAttribute('foo')")
        else:
            self.assertEqual(repr(attr), "ASFUnicodeAttribute(u'foo')")
        self.assertRaises(TypeError, int, attr)
开发者ID:Shutshutnunte,项目名称:mutagen,代码行数:10,代码来源:test_asf.py


示例11: test_basic

    def test_basic(self):
        d = os.path.dirname(self.filename)
        p = os.path.join(d, fsn(u"%(stream)d.%(ext)s"))
        res, out = self.call(fsn(u"--pattern"), p, self.filename)
        self.failIf(res)
        self.failIf(out)

        for stream in [1002429366, 1806412655]:
            stream_path = os.path.join(
                d, fsn(text_type(stream)) + fsn(u".ogg"))
            self.failUnless(os.path.exists(stream_path))
            os.unlink(stream_path)
开发者ID:akerbis,项目名称:mutagen,代码行数:12,代码来源:test_tools_moggsplit.py


示例12: test_conv_basic

    def test_conv_basic(self):
        from mutagen.id3 import TALB

        for codec in CODECS:
            f = ID3(self.filename)
            f.add(TALB(text=[AMBIGUOUS.decode("latin-1")], encoding=0))
            f.save()
            res, out = self.call(
                fsn(u"-d"), fsn(u"-e"), fsn(text_type(codec)), self.filename)
            f = ID3(self.filename)
            self.failUnlessEqual(f["TALB"].encoding, 1)
            self.failUnlessEqual(f["TALB"].text[0], AMBIGUOUS.decode(codec))
开发者ID:akerbis,项目名称:mutagen,代码行数:12,代码来源:test_tools_mid3iconv.py


示例13: test_timestampspec

 def test_timestampspec(self):
     from mutagen.id3 import TimeStampSpec, Frame, ID3TimeStamp
     s = TimeStampSpec('name')
     f = Frame(); f.encoding = 0
     self.assertEquals((ID3TimeStamp('ab'), b'fg'), s.read(f, b'ab\x00fg'))
     self.assertEquals((ID3TimeStamp('1234'), b''), s.read(f, b'1234\x00'))
     self.assertEquals(b'1234\x00', s.write(f, ID3TimeStamp('1234')))
     self.assertRaises(AttributeError, s.write, f, None)
     if PY3:
         self.assertRaises(TypeError, ID3TimeStamp, b"blah")
     self.assertEquals(
         text_type(ID3TimeStamp(u"2000-01-01")),  u"2000-01-01")
     self.assertEquals(
         bytes(ID3TimeStamp(u"2000-01-01")), b"2000-01-01")
开发者ID:banool,项目名称:random-projects,代码行数:14,代码来源:test__id3specs.py


示例14: test_ASFUnicodeAttribute

    def test_ASFUnicodeAttribute(self):
        if PY3:
            self.assertRaises(TypeError, ASFUnicodeAttribute, b"\xff")
        else:
            self.assertRaises(ValueError, ASFUnicodeAttribute, b"\xff")
            val = u'\xf6\xe4\xfc'
            self.assertEqual(ASFUnicodeAttribute(val.encode("utf-8")), val)

        self.assertRaises(ASFError, ASFUnicodeAttribute, data=b"\x00")
        self.assertEqual(ASFUnicodeAttribute(u"foo").value, u"foo")
        self.assertEqual(
            bytes(ASFUnicodeAttribute(u"foo")), b"f\x00o\x00o\x00")
        self.assertEqual(
            text_type(ASFUnicodeAttribute(u"foo")), u"foo")
开发者ID:svetlio2,项目名称:hackbg,代码行数:14,代码来源:test_asf.py


示例15: description

    def description(self):
        """string or None if unknown"""

        name = None
        try:
            name = self._TYPE_NAMES[self.audioObjectType]
        except IndexError:
            pass
        if name is None:
            return
        if self.sbrPresentFlag == 1:
            name += "+SBR"
        if self.psPresentFlag == 1:
            name += "+PS"
        return text_type(name)
开发者ID:2216288075,项目名称:meiduo_project,代码行数:15,代码来源:_as_entry.py


示例16: test_comm

    def test_comm(self):
        from mutagen.id3 import COMM

        for codec in CODECS:
            f = ID3(self.filename)
            frame = COMM(desc="", lang="eng", encoding=0,
                         text=[AMBIGUOUS.decode("latin-1")])
            f.add(frame)
            f.save()
            res, out = self.call(
                fsn(u"-d"), fsn(u"-e"), fsn(text_type(codec)), self.filename)
            f = ID3(self.filename)
            new_frame = f[frame.HashKey]
            self.failUnlessEqual(new_frame.encoding, 1)
            self.failUnlessEqual(new_frame.text[0], AMBIGUOUS.decode(codec))
开发者ID:akerbis,项目名称:mutagen,代码行数:15,代码来源:test_tools_mid3iconv.py


示例17: main

def main(argv):
    from mutagen import File

    parser = OptionParser()
    parser.add_option("--no-flac", help="Compatibility; does nothing.")
    parser.add_option("--no-mp3", help="Compatibility; does nothing.")
    parser.add_option("--no-apev2", help="Compatibility; does nothing.")

    (options, args) = parser.parse_args(argv[1:])
    if not args:
        raise SystemExit(parser.print_help() or 1)

    for filename in args:
        print_(u"--", filename)
        try:
            print_(u"-", File(filename).pprint())
        except AttributeError:
            print_(u"- Unknown file type")
        except Exception as err:
            print_(text_type(err))
        print_(u"")
开发者ID:2216288075,项目名称:meiduo_project,代码行数:21,代码来源:mutagen_inspect.py


示例18: test_fileobj_name

 def test_fileobj_name(self):
     with tempfile.TemporaryFile(mode="rb") as h:
         self.assertEqual(fileobj_name(h), text_type(h.name))
开发者ID:maphew,项目名称:mutagen,代码行数:3,代码来源:test__util.py


示例19: test_compare_to_unicode

 def test_compare_to_unicode(self):
     frame = self.Frame(encoding=0, text=[u'1987', u'1988'])
     self.failUnlessEqual(frame, text_type(frame))
开发者ID:douglaskastle,项目名称:mutagen,代码行数:3,代码来源:test__id3frames.py


示例20: __str__

 def __str__(self):
     return text_type(self.value)
开发者ID:2216288075,项目名称:meiduo_project,代码行数:2,代码来源:_attrs.py



注:本文中的mutagen._compat.text_type函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python _compat.xrange函数代码示例发布时间:2022-05-27
下一篇:
Python _compat.cBytesIO函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap