当前位置: 首页>>代码示例>>Python>>正文


Python aifc.Error方法代码示例

本文整理汇总了Python中aifc.Error方法的典型用法代码示例。如果您正苦于以下问题:Python aifc.Error方法的具体用法?Python aifc.Error怎么用?Python aifc.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aifc的用法示例。


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

示例1: test_aifc

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_aifc(h, f):
    import aifc
    if h[:4] != 'FORM':
        return None
    if h[8:12] == 'AIFC':
        fmt = 'aifc'
    elif h[8:12] == 'AIFF':
        fmt = 'aiff'
    else:
        return None
    f.seek(0)
    try:
        a = aifc.openfp(f, 'r')
    except (EOFError, aifc.Error):
        return None
    return (fmt, a.getframerate(), a.getnchannels(), \
            a.getnframes(), 8*a.getsampwidth()) 
开发者ID:glmcdona,项目名称:meddle,代码行数:19,代码来源:sndhdr.py

示例2: test_close

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_close(self):
        class Wrapfile(object):
            def __init__(self, file):
                self.file = open(file, 'rb')
                self.closed = False
            def close(self):
                self.file.close()
                self.closed = True
            def __getattr__(self, attr): return getattr(self.file, attr)
        testfile = Wrapfile(self.sndfilepath)
        f = self.f = aifc.open(testfile)
        self.assertEqual(testfile.closed, False)
        f.close()
        self.assertEqual(testfile.closed, True)
        testfile = open(TESTFN, 'wb')
        fout = aifc.open(testfile, 'wb')
        self.assertFalse(testfile.closed)
        with self.assertRaises(aifc.Error):
            fout.close()
        self.assertTrue(testfile.closed)
        fout.close() # do nothing 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:23,代码来源:test_aifc.py

示例3: test_aifc

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_aifc(h, f):
    import aifc
    if not h.startswith(b'FORM'):
        return None
    if h[8:12] == b'AIFC':
        fmt = 'aifc'
    elif h[8:12] == b'AIFF':
        fmt = 'aiff'
    else:
        return None
    f.seek(0)
    try:
        a = aifc.open(f, 'r')
    except (EOFError, aifc.Error):
        return None
    return (fmt, a.getframerate(), a.getnchannels(),
            a.getnframes(), 8 * a.getsampwidth()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:sndhdr.py

示例4: test_close_opened_files_on_error

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_close_opened_files_on_error(self):
        non_aifc_file = findfile('pluck-pcm8.wav', subdir='audiodata')

        class Aifc(aifc.Aifc_read):
            def __init__(self):
                pass

        a = Aifc()
        with self.assertRaises(aifc.Error):
            aifc.Aifc_read.__init__(a, non_aifc_file)
        self.assertTrue(a._file.closed) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_aifc.py

示例5: test_read_markers

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_read_markers(self):
        fout = self.fout = aifc.open(TESTFN, 'wb')
        fout.aiff()
        fout.setparams((1, 1, 1, 1, 'NONE', ''))
        fout.setmark(1, 0, 'odd')
        fout.setmark(2, 0, 'even')
        fout.writeframes('\x00')
        fout.close()
        f = self.f = aifc.open(TESTFN, 'rb')
        self.assertEqual(f.getmarkers(), [(1, 0, 'odd'), (2, 0, 'even')])
        self.assertEqual(f.getmark(1), (1, 0, 'odd'))
        self.assertEqual(f.getmark(2), (2, 0, 'even'))
        self.assertRaises(aifc.Error, f.getmark, 3) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_aifc.py

示例6: test_wrong_open_mode

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_wrong_open_mode(self):
        with self.assertRaises(aifc.Error):
            aifc.open(TESTFN, 'wrong_mode') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_aifc.py

示例7: test_read_wrong_form

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_read_wrong_form(self):
        b1 = io.BytesIO('WRNG' + struct.pack('>L', 0))
        b2 = io.BytesIO('FORM' + struct.pack('>L', 4) + 'WRNG')
        self.assertRaises(aifc.Error, aifc.open, b1)
        self.assertRaises(aifc.Error, aifc.open, b2) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_aifc.py

示例8: test_read_no_ssnd_chunk

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_read_no_ssnd_chunk(self):
        b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
        b += b'COMM' + struct.pack('>LhlhhLL', 38, 0, 0, 0, 0, 0, 0)
        b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
        with self.assertRaisesRegexp(aifc.Error, 'COMM chunk and/or SSND chunk'
                                                 ' missing'):
            aifc.open(io.BytesIO(b)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_aifc.py

示例9: test_read_wrong_compression_type

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_read_wrong_compression_type(self):
        b = 'FORM' + struct.pack('>L', 4) + 'AIFC'
        b += 'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0)
        b += 'WRNG' + struct.pack('B', 0)
        self.assertRaises(aifc.Error, aifc.open, io.BytesIO(b)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_aifc.py

示例10: test_write_params_raises

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_write_params_raises(self):
        fout = aifc.open(io.BytesIO(), 'wb')
        wrong_params = (0, 0, 0, 0, 'WRNG', '')
        self.assertRaises(aifc.Error, fout.setparams, wrong_params)
        self.assertRaises(aifc.Error, fout.getparams)
        self.assertRaises(aifc.Error, fout.setnchannels, 0)
        self.assertRaises(aifc.Error, fout.getnchannels)
        self.assertRaises(aifc.Error, fout.setsampwidth, 0)
        self.assertRaises(aifc.Error, fout.getsampwidth)
        self.assertRaises(aifc.Error, fout.setframerate, 0)
        self.assertRaises(aifc.Error, fout.getframerate)
        self.assertRaises(aifc.Error, fout.setcomptype, 'WRNG', '')
        fout.aiff()
        fout.setnchannels(1)
        fout.setsampwidth(1)
        fout.setframerate(1)
        fout.setnframes(1)
        fout.writeframes('\x00')
        self.assertRaises(aifc.Error, fout.setparams, (1, 1, 1, 1, 1, 1))
        self.assertRaises(aifc.Error, fout.setnchannels, 1)
        self.assertRaises(aifc.Error, fout.setsampwidth, 1)
        self.assertRaises(aifc.Error, fout.setframerate, 1)
        self.assertRaises(aifc.Error, fout.setnframes, 1)
        self.assertRaises(aifc.Error, fout.setcomptype, 'NONE', '')
        self.assertRaises(aifc.Error, fout.aiff)
        self.assertRaises(aifc.Error, fout.aifc) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,代码来源:test_aifc.py

示例11: test_write_header_raises

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_write_header_raises(self):
        fout = aifc.open(io.BytesIO(), 'wb')
        self.assertRaises(aifc.Error, fout.close)
        fout = aifc.open(io.BytesIO(), 'wb')
        fout.setnchannels(1)
        self.assertRaises(aifc.Error, fout.close)
        fout = aifc.open(io.BytesIO(), 'wb')
        fout.setnchannels(1)
        fout.setsampwidth(1)
        self.assertRaises(aifc.Error, fout.close) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_aifc.py

示例12: test_write_header_comptype_raises

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def test_write_header_comptype_raises(self):
        for comptype in ('ULAW', 'ulaw', 'ALAW', 'alaw', 'G722'):
            fout = aifc.open(io.BytesIO(), 'wb')
            fout.setsampwidth(1)
            fout.setcomptype(comptype, '')
            self.assertRaises(aifc.Error, fout.close)
            fout.initfp(None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_aifc.py

示例13: tearDown

# 需要导入模块: import aifc [as 别名]
# 或者: from aifc import Error [as 别名]
def tearDown(self):
        if self.f is not None:
            self.f.close()
        if self.fout is not None:
            try:
                self.fout.close()
            except (aifc.Error, AttributeError):
                pass
        try:
            os.remove(TESTFN)
        except OSError:
            pass 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:14,代码来源:test_aifc.py


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