pvl.args: apply_file: default to no unicode..
authorTero Marttila <terom@paivola.fi>
Mon, 16 Dec 2013 22:21:27 +0200
changeset 22 3e93880d3a40
parent 21 559a6ce73f40
child 23 8583af57ad86
child 25 538c02bd95e0
pvl.args: apply_file: default to no unicode..
pvl/args.py
--- a/pvl/args.py	Mon Dec 16 15:25:15 2013 +0200
+++ b/pvl/args.py	Mon Dec 16 22:21:27 2013 +0200
@@ -94,9 +94,9 @@
             log.error("refusing to run as root, use --uid 0 to override")
             sys.exit(2)
 
-def apply_file (path=None, mode='r', charset='utf-8') :
+def apply_file (path=None, mode='r', charset=None) :
     """
-        Open unicode-enabled file from path, with - using stdio.
+        Open (unicode-enabled) file from path, with - using stdio.
     """
 
     if not path or path == '-' :
@@ -106,12 +106,16 @@
             'w':    (sys.stdout, codecs.getwriter),
         }[mode[0]]
 
-        # wrap
-        return func(charset)(stream)
+        if charset :
+            return func(charset)(stream)
+        else :
+            return stream
 
     else :
-        # open
-        return codecs.open(path, mode, charset)
+        if charset :
+            return codecs.open(path, mode, charset)
+        else :
+            return open(path, mode)
 
 def apply_files (paths, *args, **opts) :
     """