Commits

Travis Shirk committed 4225440

python3

  • Participants
  • Parent commits 3569727
  • Branches stable

Comments (0)

Files changed (14)

examples/chapters.py

     # Start and end offset - tuple. None is used to set to "no offset"
     print("-- Start offset: %s; End offset: %s" %
           tuple((str(o) for o in chapter.offsets)))
-    print("-- Sub frames:", str(chapter.sub_frames.keys()))
+    print("-- Sub frames:", str(list(chapter.sub_frames.keys())))
 
 tag = Tag()
 if len(sys.argv) > 1:
          ])
 def run2to3(options):
     cmd = "2to3-3.3" if not options.run2to3.modernize else "python-modernize"
-    common_opts = "-x unicode -x future"
+    common_opts = "-p -x unicode -x future"
     cmd_opts = "" if not options.run2to3.modernize else "--no-six"
     paths = "./src ./examples"
 

src/eyed3/compat.py

 
 if PY2:
     StringTypes = types.StringTypes
+    import ConfigParser as configparser
+    from StringIO import StringIO
 else:
     StringTypes = (str,)
+    import ConfigParser as configparser
+    from io import StringIO

src/eyed3/core.py

 '''Basic core types and utilities.'''
 import os
 import time
-from . import Exception, LOCAL_FS_ENCODING
+from . import LOCAL_FS_ENCODING
 from .utils import guessMimetype
 
 import logging
         The encoding used for the file name is :attr:`eyed3.LOCAL_FS_ENCODING`
         unless overridden by ``fsencoding``. Note, if the target file already
         exists, or the full path contains non-existent directories the
-        operation will fail with :class:`eyed3.Exception`.'''
+        operation will fail with :class:`IOError`.'''
         base = os.path.basename(self.path)
         base_ext = os.path.splitext(base)[1]
         dir = os.path.dirname(self.path)

src/eyed3/id3/frames.py

 #
 ################################################################################
 import re
-from cStringIO import StringIO
 from collections import namedtuple
 import logging
 
 from .. import core
 from ..utils import requireUnicode
 from ..utils.binfuncs import *
+from ..compat import StringIO
 from .. import Exception as BaseException
 from . import ID3_V2, ID3_V2_3, ID3_V2_4
 from . import (LATIN1_ENCODING, UTF_8_ENCODING, UTF_16BE_ENCODING,

src/eyed3/id3/tag.py

 from . import Genre
 from . import frames
 from .headers import TagHeader, ExtendedTagHeader
+from ..compat import StringTypes
 
 import logging
 log = logging.getLogger(__name__)
         close_file = False
         if isinstance(fileobj, types.FileType):
             filename = fileobj.name
-        elif type(fileobj) in types.StringTypes:
+        elif type(fileobj) in StringTypes:
             filename = fileobj
             fileobj = file(filename, "rb")
             close_file = True
             if date_type is int:
                 # The integer year
                 date = core.Date(date)
-            elif date_type in types.StringTypes:
+            elif date_type in StringTypes:
                 date = core.Date.parse(date)
             elif not isinstance(date, core.Date):
                 raise TypeError("Invalid type: %s" % str(type(date)))

src/eyed3/main.py

 import eyed3.utils.cli
 import eyed3.plugins
 import eyed3.info
+from eyed3.compat import configparser, StringIO
 
 
 DEFAULT_PLUGIN = "classic"
 
 def _loadConfig(args):
     import os
-    import ConfigParser
 
     config = None
     config_file = None
 
     if os.path.isfile(config_file):
         try:
-            config = ConfigParser.SafeConfigParser()
+            config = configparser.SafeConfigParser()
             config.read(config_file)
-        except ConfigParser.Error as ex:
+        except configparser.Error as ex:
             eyed3.log.warning("User config error: " + str(ex))
             return None
     elif config_file != DEFAULT_CONFIG:
     '''
     import cProfile
     import pstats
-    import StringIO
 
     eyed3.log.debug("driver profileMain")
     prof = cProfile.Profile()
     prof = prof.runctx("main(args)", globals(), locals())
 
-    stream = StringIO.StringIO()
+    stream = StringIO()
     stats = pstats.Stats(prof, stream=stream)
     stats.sort_stats("time")  # Or cumulative
     stats.print_stats(100)  # 80 = how many to print

src/eyed3/plugins/__init__.py

     refresh the cache.'''
     global _PLUGINS
 
-    if len(_PLUGINS.keys()) and reload == False:
+    if len(list(_PLUGINS.keys())) and not reload:
         # Return from the cache if possible
         try:
             return _PLUGINS[name] if name else _PLUGINS
                     continue
 
                 for attr in [getattr(mod, a) for a in dir(mod)]:
-                    if (type(attr) == types.TypeType and
-                            issubclass(attr, Plugin)):
+                    if (type(attr) == type and issubclass(attr, Plugin)):
                         # This is a eyed3.plugins.Plugin
                         PluginClass = attr
                         if (PluginClass not in list(_PLUGINS.values()) and

src/eyed3/utils/__init__.py

 ID3_MIME_TYPE = "application/x-id3"
 ID3_MIME_TYPE_EXTENSIONS = (".id3", ".tag")
 
-import StringIO
+from ..compat import StringIO
 import mimetypes
 _mime_types = mimetypes.MimeTypes()
-_mime_types.readfp(StringIO.StringIO("%s %s" %
+_mime_types.readfp(StringIO("%s %s" %
                    (ID3_MIME_TYPE,
                     " ".join((e[1:] for e in ID3_MIME_TYPE_EXTENSIONS)))))
 del mimetypes

src/test/__init__.py

 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 ################################################################################
-from StringIO import StringIO
+from eyed3.compat import StringIO
 import os
 import sys
 import logging

src/test/id3/test_frames.py

 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 ################################################################################
-import unittest, cStringIO
+import unittest
 from nose.tools import *
 from eyed3.id3 import (LATIN1_ENCODING, UTF_8_ENCODING, UTF_16_ENCODING,
                        UTF_16BE_ENCODING)

src/test/id3/test_headers.py

 #
 ################################################################################
 import unittest
-from cStringIO import StringIO
 from nose.tools import *
 from eyed3.utils.binfuncs import dec2bin, bin2bytes, bin2synchsafe
 from eyed3.id3.headers import *
 from eyed3.id3 import ID3_DEFAULT_VERSION, TagException
+from eyed3.compat import StringIO
 from ..compat import *
 
 

src/test/mp3/test_mp3.py

 else:
     import unittest
 import os
-import StringIO
+from eyed3.compat import StringIO
 from nose.tools import *
 from .. import DATA_D
 
     from eyed3.mp3.headers import findHeader
 
     # No header
-    buffer = StringIO.StringIO('\x00' * 1024)
+    buffer = StringIO(b'\x00' * 1024)
     (offset, header_int, header_bytes) = findHeader(buffer, 0)
     assert_equal(header_int, None)
 
     # Valid header
-    buffer = StringIO.StringIO('\x11\x12\x23' * 1024 + "\xff\xfb\x90\x64" +
-                               "\x00" * 1024)
+    buffer = StringIO(b'\x11\x12\x23' * 1024 + b"\xff\xfb\x90\x64" +
+                      b"\x00" * 1024)
     (offset, header_int, header_bytes) = findHeader(buffer, 0)
     assert_equal(header_int, 0xfffb9064)
 
     # Same thing with a false sync in the mix
-    buffer = StringIO.StringIO('\x11\x12\x23' * 1024 +
-                               "\x11" * 100 +
-                               "\xff\xea\x00\x00" + # false sync
-                               "\x22" * 100 +
-                               "\xff\xe2\x1c\x34" + # false sync
-                               "\xee" * 100 +
-                               "\xff\xfb\x90\x64" +
-                               "\x00" * 1024)
+    buffer = StringIO(b'\x11\x12\x23' * 1024 +
+                      b"\x11" * 100 +
+                      b"\xff\xea\x00\x00" + # false sync
+                      b"\x22" * 100 +
+                      b"\xff\xe2\x1c\x34" + # false sync
+                      b"\xee" * 100 +
+                      b"\xff\xfb\x90\x64" +
+                      b"\x00" * 1024)
     (offset, header_int, header_bytes) = findHeader(buffer, 0)
     assert_equal(header_int, 0xfffb9064)
 

src/test/test_main.py

 #
 ################################################################################
 import unittest
-from StringIO import StringIO
+from eyed3.compat import StringIO
 from nose.tools import *
 from eyed3 import main, info
 from eyed3.utils import cli