Felix Krull committed e1d1772

Don't fail in case sys.getfilesystemencoding ever returns None.

  • Participants
  • Parent commits 9608e42

Comments (0)

Files changed (3)


 import rgain.rgio
-stdout_encoding = sys.stdout.encoding or sys.getfilesystemencoding()
+__all__ = [
+    "getfilesystemencoding",
+    "ou",
+    "un",
+    "Error",
+    "init_gstreamer",
+    "common_options"]
+def getfilesystemencoding():
+    # get file system encoding, making sure never to return None
+    return sys.getfilesystemencoding() or sys.getdefaultencoding()
+stdout_encoding = sys.stdout.encoding or getfilesystemencoding()
 def ou(arg):
     if isinstance(arg, str):
         return arg.decode("ascii").encode(stdout_encoding)


 from mutagen.id3 import TXXX
 from rgain import albumid, rgio
-from rgain.script import ou, un, Error, common_options, init_gstreamer
+from rgain.script import *
 from rgain.script.replaygain import do_gain
     for dirpath, dirnames, filenames in os.walk(music_dir):
         for filename in filenames:
             filepath = un(relpath(os.path.join(dirpath, filename), music_dir),
-                                  sys.getfilesystemencoding())
+                                  getfilesystemencoding())
             properpath = os.path.join(dirpath, filename)
             mtime = os.path.getmtime(properpath)
 def do_collectiongain(music_dir, ref_level=89, force=False, dry_run=False,
                       mp3_format=None, ignore_cache=False, jobs=0):
-    music_dir = un(music_dir, sys.getfilesystemencoding())
+    music_dir = un(music_dir, getfilesystemencoding())
     music_abspath = os.path.abspath(music_dir)
     musicpath_hash = md5(music_abspath.encode("utf-8")).hexdigest()


 from gi.repository import GObject
 from rgain import rgcalc, rgio, util
-from rgain.script import ou, un, Error, common_options, init_gstreamer
+from rgain.script import *
 # calculate the gain for the given files
 def do_gain(files, ref_level=89, force=False, dry_run=False, album=True,
-    files = [un(filename, sys.getfilesystemencoding()) for filename in files]
+    files = [un(filename, getfilesystemencoding()) for filename in files]
     formats_map = rgio.BaseFormatsMap(mp3_format)
     formats_map = rgio.BaseFormatsMap(mp3_format)
     for filename in filenames:
-        filename = un(filename, sys.getfilesystemencoding())
+        filename = un(filename, getfilesystemencoding())
         print ou(filename)
             trackdata, albumdata = formats_map.read_gain(filename)