當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。