Commits

Travis Shirk  committed 21c55d3

Fixes for python 3 compatability

  • Participants
  • Parent commits a518a65

Comments (0)

Files changed (13)

File src/eyed3/binfuncs.py

     bits.reverse()  # MSB
 
     multi = 1
-    value = long(0)
+    value = 0
     for b in bits:
         value += b * multi
         multi *= 2

File src/eyed3/id3/__init__.py

             return
 
         val = int(val)
-        if val not in genres.keys():
+        if val not in list(genres.keys()):
             raise ValueError("Invalid numeric genre ID: %d" % val)
 
         name = genres[val]
             self._name = None
             return
 
-        if val.lower() in genres.keys():
+        if val.lower() in list(genres.keys()):
             self._id = genres[val]
             # normalize the name
             self._name = genres[self._id]
 from .tag import Tag, FileInfo, TagException, TagTemplate
 genres = GenreMap()
 
-import frames
+from . import frames

File src/eyed3/id3/frames.py

         return padding_size
 
     def __getitem__(self, fid):
-        if self.has_key(fid):
+        if fid in self:
             return dict.__getitem__(self, fid)
         else:
             return None
     def __setitem__(self, fid, frame):
         assert(fid == frame.id)
 
-        if self.has_key(fid):
+        if fid in self:
             self[fid].append(frame)
         else:
             dict.__setitem__(self, fid, [frame])
 
     def getAllFrames(self):
         frames = []
-        for flist in self.values():
+        for flist in list(self.values()):
             frames += flist
         return frames
 
         the same Id is already in the list it's value is changed, otherwise
         the frame is added.
         '''
-        assert(fid[0] == "T" and fid in ID3_FRAMES.keys())
+        assert(fid[0] == "T" and fid in list(ID3_FRAMES.keys()))
 
-        if self.has_key(fid):
+        if fid in self:
             curr = self[fid][0]
             if isinstance(curr, DateFrame):
                 curr.date = text
     fid = frame_header.id
     FrameClass = None
 
-    if ID3_FRAMES.has_key(fid):
+    if fid in ID3_FRAMES:
         (desc, ver, FrameClass) = ID3_FRAMES[fid]
-    elif NONSTANDARD_ID3_FRAMES.has_key(fid):
+    elif fid in NONSTANDARD_ID3_FRAMES:
         log.warning("Non standard frame '%s' encountered" % fid)
         (desc, ver, FrameClass) = NONSTANDARD_ID3_FRAMES[fid]
     else:
 }
 
 
-def map2_2FrameId(originalId):
-    if not TAGS2_2_TO_TAGS_2_3_AND_4.has_key(originalId):
-        return originalId
-    return TAGS2_2_TO_TAGS_2_3_AND_4[originalId]
+def map2_2FrameId(orig_id):
+    if orig_id not in TAGS2_2_TO_TAGS_2_3_AND_4:
+        return orig_id
+    return TAGS2_2_TO_TAGS_2_3_AND_4[orig_id]
 
 # FIXME: these mappings do not handle 2.3 *and* 2.4 support..
 #        TOR->TORY(2.3)->???(2.4)

File src/eyed3/id3/tag.py

 
     def _getBpm(self):
         bpm = None
-        if self.frame_set.has_key(frames.BPM_FID):
+        if frames.BPM_FID in self.frame_set:
             bpm_str = self.frame_set[frames.BPM_FID][0].text or u"0"
             try:
                 # Round floats since the spec says this is an integer
 
     @property
     def play_count(self):
-        if self.frame_set.has_key(frames.PLAYCOUNT_FID):
+        if frames.PLAYCOUNT_FID in self.frame_set:
             pc = self.frame_set[frames.PLAYCOUNT_FID][0]
-            assert(type(pc.count) in (int, long))
+            assert(type(pc.count) in (int,))
             return pc.count
         else:
             return None
                     frames.PlayCountFrame(count=count)
 
     def _getPublisher(self):
-        if self.frame_set.has_key(frames.PUBLISHER_FID):
+        if frames.PUBLISHER_FID in self.frame_set:
             pub = self.frame_set[frames.PUBLISHER_FID]
             return pub[0].text
         else:
 
     @property
     def cd_id(self):
-        if self.frame_set.has_key(frames.CDID_FID):
+        if frames.CDID_FID in self.frame_set:
             return self.frame_set[frames.CDID_FID][0].toc
         else:
             return None
             raise TypeError("Invalid type: %s" % str(type(date)))
 
         date_text = unicode(str(date))
-        if self.frame_set.has_key(fid):
+        if fid in self.frame_set:
             self.frame_set[fid][0].date = date
         else:
             self.frame_set[fid] = frames.DateFrame(fid, date=date_text)
 
     def _getDate(self, fid):
-        if self.frame_set.has_key(fid):
+        if fid in self.frame_set:
             return self.frame_set[fid][0].date
         else:
             return None
                       {f.id: f for f in flist if f.id in DATE_FIDS}
         if date_frames:
             if version == ID3_V2_4:
-                if date_frames.has_key("TORY"):
+                if "TORY" in date_frames:
                     # TORY -> TDOR (year only)
                     date = self._v23OrignalReleaseDate()
                     if date:
                         converted_frames.append(DateFrame("TDRC",
                                                           unicode(date)))
                     for fid in ["TYER", "TDAT", "TIME"]:
-                        if date_frames.has_key(fid):
+                        if fid in date_frames:
                             flist.remove(date_frames[fid])
                             del date_frames[fid]
 
             elif version == ID3_V2_3:
-                if date_frames.has_key("TDOR"):
+                if "TDOR" in date_frames:
                     date = date_frames["TDOR"].date
                     if date:
                         converted_frames.append(DateFrame("TORY",
                     flist.remove(date_frames["TDOR"])
                     del date_frames["TDOR"]
 
-                if date_frames.has_key("TDRL"):
+                if "TDRL" in date_frames:
                     date = date_frames["TDRL"].date
 
                     if date:
                     del date_frames["TDRL"]
 
             # All other date frames have no conversion
-            for fid in date_frames.keys():
+            for fid in date_frames:
                 log.warning("%s frame being dropped due to conversion to %s" %
                             (fid, versionToString(version)))
 

File src/eyed3/mp3/__init__.py

                 self.mp3_header = headers.Mp3Header(header_int)
                 log.debug("mp3 header %x found at position: 0x%x" %
                           (header_int, header_pos))
-            except headers.Mp3Exception, ex:
+            except headers.Mp3Exception as ex:
                 log.debug("Invalid mp3 header: %s" % str(ex))
                 # keep looking...
                 start_offset += 4

File src/eyed3/mp3/headers.py

             # got files with longer version strings)
             lamever = []
             for c in frame[pos:pos + 30]:
-                if ord(c) not in range(32, 127):
+                if ord(c) not in list(range(32, 127)):
                     break
                 lamever.append(c)
             self['encoder_version'] = ''.join(lamever).rstrip('\x55')

File src/eyed3/plugins/__init__.py

     from eyed3.info import PLUGIN_DIRS
     global _PLUGINS
 
-    if _PLUGINS.keys() and reload == False:
+    if list(_PLUGINS.keys()) and reload == False:
         # Return from the cache if possible
         try:
             return _PLUGINS[plugin] if plugin else _PLUGINS
                             issubclass(attr, Plugin)):
                         # This is a eyed3.plugins.Plugin
                         PluginClass = attr
-                        if (PluginClass not in _PLUGINS.values() and
+                        if (PluginClass not in list(_PLUGINS.values()) and
                                 len(PluginClass.NAMES)):
                             log.debug("loading plugin '%s' fron '%s%s%s'",
                                       mod, d, os.path.sep, f)

File src/eyed3/plugins/classic.py

         def PlayCountArg(pc):
             increment = False
             if pc[0] == '+':
-                pc = long(pc[1:])
+                pc = int(pc[1:])
                 increment = True
             else:
-                pc = long(pc)
+                pc = int(pc)
             if pc < 0:
                 raise ValueError("out of range")
             return (increment, pc)
 
 def _getTemplateKeys():
     from eyed3.id3.tag import TagTemplate
-    keys = id3.TagTemplate("")._makeMapping(None, False).keys()
+    keys = list(id3.TagTemplate("")._makeMapping(None, False).keys())
     keys.sort()
     return ", ".join(["$%s" % v for v in keys])
 

File src/eyed3/plugins/examples.py

 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 ################################################################################
+from __future__ import print_function
 import math, os
 from eyed3 import core
 from eyed3.plugins import Plugin, LoaderPlugin
         mt = eyed3.utils.guessMimetype(f)
         if mt is None:
             printMsg("No mime-type: %s" % f)
-        if self.mts.has_key(mt):
+        if mt in self.mts:
             self.mts[mt] += 1
         else:
             self.mts[mt] = 1

File src/eyed3/plugins/lameinfo.py

 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 ################################################################################
+from __future__ import print_function
 import os
-
 from eyed3 import LOCAL_ENCODING as ENCODING
 from eyed3.utils import formatSize, formatTime
 from eyed3.utils.cli import (printMsg, printError, printWarning, boldText,

File src/eyed3/plugins/nfo.py

 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 ################################################################################
+from __future__ import print_function
 import time
 from eyed3 import LOCAL_ENCODING as ENCODING
 from eyed3.utils.cli import printMsg, printError
         if self.audio_file and self.audio_file.tag:
             tag = self.audio_file.tag
             album = tag.album
-            if album and not self.albums.has_key(album):
+            if album and album not in self.albums:
                 self.albums[album] = []
                 self.albums[album].append(self.audio_file)
             elif album:
                 # Compute average bitrate
                 avg_bitrate += audio_file.info.bit_rate[1]
                 # Grab the last lame version in case not all files have one
-                if audio_file.info.lame_tag.has_key('encoder_version'):
+                if "encoder_version" in audio_file.info.lame_tag:
                     version = audio_file.info.lame_tag['encoder_version']
                     encoder_info = (version or encoder_info)
             avg_bitrate = avg_bitrate / len(audio_files)

File src/eyed3/plugins/statistics.py

 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 ################################################################################
+from __future__ import print_function
 import sys, os, operator
 
 from eyed3 import id3

File src/eyed3/utils/__init__.py

 ################################################################################
 import os, re
 
-import mimetypes, cStringIO
+import mimetypes, StringIO
 _mime_types = mimetypes.MimeTypes()
-_mime_types.readfp(cStringIO.StringIO("application/x-id3 id3 tag"))
+_mime_types.readfp(StringIO.StringIO("application/x-id3 id3 tag"))
 del mimetypes
-del cStringIO
+del StringIO
 
 from eyed3 import LOCAL_ENCODING, LOCAL_FS_ENCODING
 
                     raise TypeError("%s(argument %d) must be unicode" %
                                     (fn.__name__, i))
             for name in kwarg_names:
-                if (kwargs.has_key(name) and kwargs[name] is not None and
+                if (name in kwargs and kwargs[name] is not None and
                         not isinstance(kwargs[name], unicode)):
                     raise TypeError("%s(argument %s) must be unicode" %
                                     (fn.__name__, name))
                     new_args.append(a)
             args = tuple(new_args)
 
-            for kw in kwargs.keys():
+            for kw in kwargs:
                 if type(kwargs[kw]) is unicode:
                     kwargs[kw] = kwargs[kw].encode(LOCAL_ENCODING, enc_err)
             return fn(*args, **kwargs)