Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Commit

Permalink
Work around Debian bug 712596, fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Jul 10, 2013
1 parent fb6d9a9 commit e2fa4e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tagpy/__init__.py
Expand Up @@ -6,7 +6,7 @@
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

Expand All @@ -19,27 +19,21 @@
# SOFTWARE.




import _tagpy
from _tagpy import Tag, File, AudioProperties, StringType, ReadStyle
#AudioProperties.ReadStyle = _tagpy.ReadStyle




class FileTypeResolver(object):
def createFile(self, fileName, readAudioProperties=True,
def createFile(self, fileName, readAudioProperties=True,
audioPropertiesStyle=ReadStyle.Average):
raise NotImplementedError




class FileRef(object):
fileTypeResolvers = []

def __init__(self, f, readAudioProperties=True,
def __init__(self, f, readAudioProperties=True,
audioPropertiesStyle=ReadStyle.Average):
if isinstance(f, FileRef):
self._file = f._file
Expand Down Expand Up @@ -77,7 +71,9 @@ def addFileTypeResolver(cls, resolver):
def _getExtToModule():
import tagpy.ogg.vorbis
import tagpy.ogg.flac
import tagpy.mpeg, tagpy.flac, tagpy.mpc
import tagpy.mpeg
import tagpy.flac
import tagpy.mpc

#import tagpy.wavpack, tagpy.ogg.speex, tagpy.trueaudio

Expand All @@ -93,14 +89,18 @@ def _getExtToModule():
}

@classmethod
def create(cls, fileName, readAudioProperties=True,
def create(cls, fileName, readAudioProperties=True,
audioPropertiesStyle=ReadStyle.Average):
for resolver in cls.fileTypeResolvers:
file = resolver.createFile(fileName, readAudioProperties,
audioPropertiesStyle)
if file:
return file

from os.path import exists
if not exists(fileName):
raise IOError("File does not exist")

from os.path import splitext
ext = splitext(fileName)[1][1:].lower()

Expand Down
20 changes: 20 additions & 0 deletions test/test_tagpy.py
@@ -0,0 +1,20 @@
import tagpy
try:
import faulthandler
except:
pass
else:
faulthandler.enable()


def test_non_existing_fileref():
tagpy.FileRef('does_not_exist.ogg')


if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
exec(sys.argv[1])
else:
from py.test.cmdline import main
main([__file__])

0 comments on commit e2fa4e6

Please sign in to comment.