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

Python _compat.xrange函数代码示例

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

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



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

示例1: test_random_data_roundtrip

 def test_random_data_roundtrip(self):
     try:
         random_file = open("/dev/urandom", "rb")
     except (IOError, OSError):
         print("WARNING: Random data round trip test disabled.")
         return
     for i in xrange(10):
         num_packets = random.randrange(2, 100)
         lengths = [random.randrange(10, 10000)
                    for i in xrange(num_packets)]
         packets = list(map(random_file.read, lengths))
         self.failUnlessEqual(
             packets, OggPage.to_packets(OggPage.from_packets(packets)))
开发者ID:douglaskastle,项目名称:mutagen,代码行数:13,代码来源:test_ogg.py


示例2: iter_test_file_objects

def iter_test_file_objects(fileobj):
    """Given a file object yields the same file object which fails differently
    each time
    """

    t = TestFileObj(fileobj)
    # first figure out how much a successful attempt reads and how many
    # file object operations it executes.
    yield t
    for i in xrange(t.dataread):
        yield TestFileObj(fileobj, stop_after=i)
    for i in xrange(t.operations):
        yield TestFileObj(fileobj, fail_after=i)
开发者ID:gdelfresno,项目名称:mutagen,代码行数:13,代码来源:test___init__.py


示例3: _parse_adif

    def _parse_adif(self, fileobj):
        r = BitReader(fileobj)
        try:
            copyright_id_present = r.bits(1)
            if copyright_id_present:
                r.skip(72)  # copyright_id
            r.skip(1 + 1)  # original_copy, home
            bitstream_type = r.bits(1)
            self.bitrate = r.bits(23)
            npce = r.bits(4)
            if bitstream_type == 0:
                r.skip(20)  # adif_buffer_fullness

            pce = ProgramConfigElement(r)
            try:
                self.sample_rate = _FREQS[pce.sampling_frequency_index]
            except IndexError:
                pass
            self.channels = pce.channels

            # other pces..
            for i in xrange(npce):
                ProgramConfigElement(r)
            r.align()
        except BitReaderError as e:
            raise AACError(e)

        # use bitrate + data size to guess length
        start = fileobj.tell()
        fileobj.seek(0, 2)
        length = fileobj.tell() - start
        if self.bitrate != 0:
            self.length = (8.0 * length) / self.bitrate
开发者ID:dcramer,项目名称:sickbeard_mp4_automator,代码行数:33,代码来源:aac.py


示例4: test_find_last

 def test_find_last(self):
     pages = [OggPage() for i in xrange(10)]
     for i, page in enumerate(pages):
         page.sequence = i
     data = BytesIO(b"".join([page.write() for page in pages]))
     self.failUnlessEqual(
         OggPage.find_last(data, pages[0].serial), pages[-1])
开发者ID:douglaskastle,项目名称:mutagen,代码行数:7,代码来源:test_ogg.py


示例5: test_renumber_muxed

 def test_renumber_muxed(self):
     pages = [OggPage() for i in xrange(10)]
     for seq, page in enumerate(pages[0:1] + pages[2:]):
         page.serial = 0
         page.sequence = seq
     pages[1].serial = 2
     pages[1].sequence = 100
     data = BytesIO(b"".join([page.write() for page in pages]))
     OggPage.renumber(data, 0, 20)
     data.seek(0)
     pages = [OggPage(data) for i in xrange(10)]
     self.failUnlessEqual(pages[1].serial, 2)
     self.failUnlessEqual(pages[1].sequence, 100)
     pages.pop(1)
     self.failUnlessEqual(
         [page.sequence for page in pages], list(xrange(20, 29)))
开发者ID:douglaskastle,项目名称:mutagen,代码行数:16,代码来源:test_ogg.py


示例6: test_renumber

    def test_renumber(self):
        self.failUnlessEqual(
            [page.sequence for page in self.pages], [0, 1, 2])
        fileobj = BytesIO()
        for page in self.pages:
            fileobj.write(page.write())
        fileobj.seek(0)
        OggPage.renumber(fileobj, 1, 10)
        fileobj.seek(0)
        pages = [OggPage(fileobj) for i in xrange(3)]
        self.failUnlessEqual([page.sequence for page in pages], [10, 11, 12])

        fileobj.seek(0)
        OggPage.renumber(fileobj, 1, 20)
        fileobj.seek(0)
        pages = [OggPage(fileobj) for i in xrange(3)]
        self.failUnlessEqual([page.sequence for page in pages], [20, 21, 22])
开发者ID:douglaskastle,项目名称:mutagen,代码行数:17,代码来源:test_ogg.py


示例7: test_apic_duplicate_hash

    def test_apic_duplicate_hash(self):
        id3 = ID3Tags()
        for i in xrange(10):
            apic = APIC(encoding=0, mime=u"b", type=3, desc=u"", data=b"a")
            id3._add(apic, False)

        self.assertEqual(len(id3), 10)
        for key, value in id3.items():
            self.assertEqual(key, value.HashKey)
开发者ID:quodlibet,项目名称:mutagen,代码行数:9,代码来源:test_id3.py


示例8: test_delete_6106_79_51760

 def test_delete_6106_79_51760(self):
     # This appears to be due to ANSI C limitations in read/write on rb+
     # files. The problematic behavior only showed up in our mmap fallback
     # code for transfers of this or similar sizes.
     data = u''.join(map(text_type, xrange(12574)))  # 51760 bytes
     data = data.encode("ascii")
     o = self.file(data[:6106 + 79] + data[79:])
     delete_bytes(o, 6106, 79)
     self.failUnless(data == self.read(o))
开发者ID:akerbis,项目名称:mutagen,代码行数:9,代码来源:test__util.py


示例9: test_bits

    def test_bits(self):
        data = b"\x12\x34\x56\x78\x89\xAB\xCD\xEF"
        ref = cdata.uint64_be(data)

        for i in xrange(64):
            fo = cBytesIO(data)
            r = BitReader(fo)
            v = r.bits(i) << (64 - i) | r.bits(64 - i)
            self.assertEqual(v, ref)
开发者ID:akerbis,项目名称:mutagen,代码行数:9,代码来源:test__util.py


示例10: _parse_adts

    def _parse_adts(self, fileobj, start_offset):
        max_initial_read = 512
        max_resync_read = 10
        max_sync_tries = 10

        frames_max = 100
        frames_needed = 3

        # Try up to X times to find a sync word and read up to Y frames.
        # If more than Z frames are valid we assume a valid stream
        offset = start_offset
        for i in xrange(max_sync_tries):
            fileobj.seek(offset)
            s = _ADTSStream.find_stream(fileobj, max_initial_read)
            if s is None:
                raise AACError("sync not found")
            # start right after the last found offset
            offset += s.offset + 1

            for i in xrange(frames_max):
                if not s.parse_frame():
                    break
                if not s.sync(max_resync_read):
                    break

            if s.parsed_frames >= frames_needed:
                break
        else:
            raise AACError(
                "no valid stream found (only %d frames)" % s.parsed_frames)

        self.sample_rate = s.frequency
        self.channels = s.channels
        self.bitrate = s.bitrate

        # size from stream start to end of file
        fileobj.seek(0, 2)
        stream_size = fileobj.tell() - (offset + s.offset)
        # approx
        self.length = float(s.samples * stream_size) / (s.size * s.frequency)
开发者ID:2216288075,项目名称:meiduo_project,代码行数:40,代码来源:aac.py


示例11: setUp

    def setUp(self):
        self.fileobj = open(os.path.join(DATA_DIR, "empty.ogg"), "rb")
        self.page = OggPage(self.fileobj)

        pages = [OggPage(), OggPage(), OggPage()]
        pages[0].packets = [b"foo"]
        pages[1].packets = [b"bar"]
        pages[2].packets = [b"baz"]
        for i in xrange(len(pages)):
            pages[i].sequence = i
        for page in pages:
            page.serial = 1
        self.pages = pages
开发者ID:douglaskastle,项目名称:mutagen,代码行数:13,代码来源:test_ogg.py


示例12: _item_sort_key

def _item_sort_key(key, value):
    # iTunes always writes the tags in order of "relevance", try
    # to copy it as closely as possible.
    order = ["\xa9nam", "\xa9ART", "\xa9wrt", "\xa9alb",
             "\xa9gen", "gnre", "trkn", "disk",
             "\xa9day", "cpil", "pgap", "pcst", "tmpo",
             "\xa9too", "----", "covr", "\xa9lyr"]
    order = dict(izip(order, xrange(len(order))))
    last = len(order)
    # If there's no key-based way to distinguish, order by length.
    # If there's still no way, go by string comparison on the
    # values, so we at least have something determinstic.
    return (order.get(key[:4], last), len(repr(value)), repr(value))
开发者ID:jbcurtin,项目名称:mutagen,代码行数:13,代码来源:__init__.py


示例13: test_many_changes

    def test_many_changes(self, num_runs=5, num_changes=300,
                          min_change_size=500, max_change_size=1000,
                          min_buffer_size=1, max_buffer_size=2000):
        self.failUnless(min_buffer_size < min_change_size and
                        max_buffer_size > max_change_size and
                        min_change_size < max_change_size and
                        min_buffer_size < max_buffer_size,
                        "Given testing parameters make this test useless")
        for j in xrange(num_runs):
            data = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" * 1024
            fobj = self.file(data)
            filesize = len(data)
            # Generate the list of changes to apply
            changes = []
            for i in xrange(num_changes):
                change_size = random.randrange(
                    min_change_size, max_change_size)
                change_offset = random.randrange(0, filesize)
                filesize += change_size
                changes.append((change_offset, change_size))

            # Apply the changes, and make sure they all took.
            for offset, size in changes:
                buffer_size = random.randrange(
                    min_buffer_size, max_buffer_size)
                insert_bytes(fobj, size, offset, BUFFER_SIZE=buffer_size)
            fobj.seek(0)
            self.failIfEqual(fobj.read(len(data)), data)
            fobj.seek(0, 2)
            self.failUnlessEqual(fobj.tell(), filesize)

            # Then, undo them.
            changes.reverse()
            for offset, size in changes:
                buffer_size = random.randrange(
                    min_buffer_size, max_buffer_size)
                delete_bytes(fobj, size, offset, BUFFER_SIZE=buffer_size)
            fobj.seek(0)
            self.failUnless(fobj.read() == data)
开发者ID:akerbis,项目名称:mutagen,代码行数:39,代码来源:test__util.py


示例14: test_renumber_extradata

 def test_renumber_extradata(self):
     fileobj = BytesIO()
     for page in self.pages:
         fileobj.write(page.write())
     fileobj.write(b"left over data")
     fileobj.seek(0)
     # Trying to rewrite should raise an error...
     self.failUnlessRaises(Exception, OggPage.renumber, fileobj, 1, 10)
     fileobj.seek(0)
     # But the already written data should remain valid,
     pages = [OggPage(fileobj) for i in xrange(3)]
     self.failUnlessEqual([page.sequence for page in pages], [10, 11, 12])
     # And the garbage that caused the error should be okay too.
     self.failUnlessEqual(fileobj.read(), b"left over data")
开发者ID:douglaskastle,项目名称:mutagen,代码行数:14,代码来源:test_ogg.py


示例15: parse_full

    def parse_full(cls, asf, fileobj):
        """Raises ASFHeaderError"""

        header = cls()

        size, num_objects = cls.parse_size(fileobj)
        for i in xrange(num_objects):
            guid, size = struct.unpack("<16sQ", fileobj.read(24))
            obj = BaseObject._get_object(guid)
            data = fileobj.read(size - 24)
            obj.parse(asf, data)
            header.objects.append(obj)

        return header
开发者ID:4everGhost,项目名称:PlexKodiConnect,代码行数:14,代码来源:_objects.py


示例16: test_find_last_last_empty

 def test_find_last_last_empty(self):
     # https://github.com/quodlibet/mutagen/issues/308
     pages = [OggPage() for i in xrange(10)]
     for i, page in enumerate(pages):
         page.sequence = i
         page.position = i
     pages[-1].last = True
     pages[-1].position = -1
     data = BytesIO(b"".join([page.write() for page in pages]))
     page = OggPage.find_last(data, pages[-1].serial, finishing=True)
     assert page is not None
     assert page.position == 8
     page = OggPage.find_last(data, pages[-1].serial, finishing=False)
     assert page is not None
     assert page.position == -1
开发者ID:quodlibet,项目名称:mutagen,代码行数:15,代码来源:test_ogg.py


示例17: _parse_desc_length_file

    def _parse_desc_length_file(cls, fileobj):
        """May raise ValueError"""

        value = 0
        for i in xrange(4):
            try:
                b = cdata.uint8(fileobj.read(1))
            except cdata.error as e:
                raise ValueError(e)
            value = (value << 7) | (b & 0x7F)
            if not b >> 7:
                break
        else:
            raise ValueError("invalid descriptor length")

        return value
开发者ID:dcramer,项目名称:sickbeard_mp4_automator,代码行数:16,代码来源:_as_entry.py


示例18: parse

 def parse(self, asf, data):
     super(ExtendedContentDescriptionObject, self).parse(asf, data)
     num_attributes, = struct.unpack("<H", data[0:2])
     pos = 2
     for i in xrange(num_attributes):
         name_length, = struct.unpack("<H", data[pos:pos + 2])
         pos += 2
         name = data[pos:pos + name_length]
         name = name.decode("utf-16-le").strip("\x00")
         pos += name_length
         value_type, value_length = struct.unpack("<HH", data[pos:pos + 4])
         pos += 4
         value = data[pos:pos + value_length]
         pos += value_length
         attr = ASFBaseAttribute._get_type(value_type)(data=value)
         asf._tags.setdefault(self.GUID, []).append((name, attr))
开发者ID:2216288075,项目名称:meiduo_project,代码行数:16,代码来源:_objects.py


示例19: __init__

    def __init__(self, r):
        """Reads the program_config_element()

        Raises BitReaderError
        """

        self.element_instance_tag = r.bits(4)
        self.object_type = r.bits(2)
        self.sampling_frequency_index = r.bits(4)
        num_front_channel_elements = r.bits(4)
        num_side_channel_elements = r.bits(4)
        num_back_channel_elements = r.bits(4)
        num_lfe_channel_elements = r.bits(2)
        num_assoc_data_elements = r.bits(3)
        num_valid_cc_elements = r.bits(4)

        mono_mixdown_present = r.bits(1)
        if mono_mixdown_present == 1:
            r.skip(4)
        stereo_mixdown_present = r.bits(1)
        if stereo_mixdown_present == 1:
            r.skip(4)
        matrix_mixdown_idx_present = r.bits(1)
        if matrix_mixdown_idx_present == 1:
            r.skip(3)

        elms = (
            num_front_channel_elements
            + num_side_channel_elements
            + num_back_channel_elements
        )
        channels = 0
        for i in xrange(elms):
            channels += 1
            element_is_cpe = r.bits(1)
            if element_is_cpe:
                channels += 1
            r.skip(4)
        channels += num_lfe_channel_elements
        self.channels = channels

        r.skip(4 * num_lfe_channel_elements)
        r.skip(4 * num_assoc_data_elements)
        r.skip(5 * num_valid_cc_elements)
        r.align()
        comment_field_bytes = r.bits(8)
        r.skip(8 * comment_field_bytes)
开发者ID:dcramer,项目名称:sickbeard_mp4_automator,代码行数:47,代码来源:aac.py


示例20: _parse_desc_length

def _parse_desc_length(data, offset):
    """Returns the decoded value and the new offset in data after the value.
    Can raise ValueError in case the value is too long or data too short.
    """

    value = 0
    for i in xrange(4):
        try:
            b, offset = cdata.uint8_from(data, offset)
        except cdata.error as e:
            raise ValueError(e)
        value = (value << 7) | (b & 0x7f)
        if not b >> 7:
            break
    else:
        raise ValueError("invalid descriptor length")

    return value, offset
开发者ID:GymWenFLL,项目名称:tpp_libs,代码行数:18,代码来源:mp4.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python _toolsutil.fsn函数代码示例发布时间:2022-05-27
下一篇:
Python _compat.text_type函数代码示例发布时间: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