[Shtoom] unicode filename breaks incoming calls

Adrien Di Mascio Adrien.DiMascio at logilab.fr
Wed Apr 6 18:01:42 CEST 2005


With today's SVN revision (1366), I get a traceback on incoming calls
for the filename used in play_wav_file is a unicode string. It breaks
deep down in std module wave when Wave_read.__init__ tries to figure
out if the file passed in argument is a string or a file object. It
tests for type(fp) == type('') but since fp is a unicode string, this
piece of code thinks that if it is not a string, it must be an open

A simple fix follows:

[shtoom]$ svn diff 
Index: shtoom/app/phone.py
--- shtoom/app/phone.py (revision 1366)
+++ shtoom/app/phone.py (working copy)
@@ -58,7 +58,7 @@
     def play_wav_file(self, soundconfigurename):
         fname = self.getPref(soundconfigurename)
         if fname:
-            fullfname = self.find_resource_file(fname)
+            fullfname = str(self.find_resource_file(fname))
     def needsThreadedUI(self):
Index: shtoom/audio/aufile.py
--- shtoom/audio/aufile.py      (revision 1366)
+++ shtoom/audio/aufile.py      (working copy)
@@ -1,4 +1,4 @@
-import wave, sunau, aifc, sndhdr
+import wave, sunau, aifc, sndhdr, types
 from audioop import tomono, lin2lin, ulaw2lin, ratecv
 import struct
@@ -12,6 +12,7 @@
     _freqCvt = { 8000: 160, 16000: 320, 32000: 640, 64000: 1280 }
     def __init__(self, fp):
+        assert type(fp) is types.StringType, '%s is not of
StringType' % type(fp)
         self.fp = self.module.open(fp, 'rb')
         p = self.fp.getparams()
         print p

Adrien Di Mascio
LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr   http://www.logilab.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/shtoom/attachments/20050406/f708df1f/attachment.pgp>

More information about the Shtoom mailing list