Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2789)

Unified Diff: python/lilylib.py

Issue 553420043: Switch to Python 3.x (Closed)
Patch Set: Remove coverage.py Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « python/langdefs.py ('k') | python/midi.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: python/lilylib.py
diff --git a/python/lilylib.py b/python/lilylib.py
index 7fe3ad016a7e76b2f62a8d8b5f69bb37e6ae02b3..7080f38a3555c47341df30d44030f364c0281fc4 100644
--- a/python/lilylib.py
+++ b/python/lilylib.py
@@ -50,19 +50,10 @@ except:
return p
underscore = _
-# Urg, Python 2.4 does not define stderr/stdout encoding
-# Maybe guess encoding from LANG/LC_ALL/LC_CTYPE?
-
-reload (sys)
-sys.setdefaultencoding ('utf-8')
import codecs
-sys.stdout = codecs.getwriter ('utf8') (sys.stdout)
-sys.stderr = codecs.getwriter ('utf8') (sys.stderr)
-
-# ugh, Python 2.5 optparse requires Unicode strings in some argument
-# functions, and refuse them in some other places
-def display_encode (s):
- return s.encode (sys.stderr.encoding or 'utf-8', 'replace')
+sys.stdin = codecs.getreader ('utf8') (sys.stdin.detach ())
+sys.stdout = codecs.getwriter ('utf8') (sys.stdout.detach ())
+sys.stderr = codecs.getwriter ('utf8') (sys.stderr.detach ())
# Lilylib globals.
program_version = '@TOPLEVEL_VERSION@'
@@ -75,7 +66,7 @@ program_name = os.path.basename (sys.argv[0])
# makefiles and use its value.
at_re = re.compile (r'@')
if at_re.match (program_version):
- if os.environ.has_key('LILYPOND_VERSION'):
+ if 'LILYPOND_VERSION' in os.environ:
program_version = os.environ['LILYPOND_VERSION']
else:
program_version = "unknown"
@@ -222,18 +213,18 @@ def subprocess_system (cmd,
retval = proc.returncode
if retval:
- print >>sys.stderr, 'command failed:', cmd
+ print('command failed:', cmd, file=sys.stderr)
if retval < 0:
- print >>sys.stderr, "Child was terminated by signal", -retval
+ print("Child was terminated by signal", -retval, file=sys.stderr)
elif retval > 0:
- print >>sys.stderr, "Child returned", retval
+ print("Child returned", retval, file=sys.stderr)
if ignore_error:
- print >>sys.stderr, "Error ignored by lilylib"
+ print("Error ignored by lilylib", file=sys.stderr)
else:
if not show_progress:
- print log[0]
- print log[1]
+ print(log[0])
+ print(log[1])
sys.exit (1)
return abs (retval)
@@ -255,14 +246,14 @@ def ossystem_system (cmd,
retval = os.system (cmd)
if retval:
- print >>sys.stderr, 'command failed:', cmd
+ print('command failed:', cmd, file=sys.stderr)
if retval < 0:
- print >>sys.stderr, "Child was terminated by signal", -retval
+ print("Child was terminated by signal", -retval, file=sys.stderr)
elif retval > 0:
- print >>sys.stderr, "Child returned", retval
+ print("Child returned", retval, file=sys.stderr)
if ignore_error:
- print >>sys.stderr, "Error ignored"
+ print("Error ignored", file=sys.stderr)
else:
sys.exit (1)
@@ -293,7 +284,7 @@ def search_exe_path (name):
def print_environment ():
- for (k,v) in os.environ.items ():
+ for (k,v) in list(os.environ.items ()):
sys.stderr.write ("%s=\"%s\"\n" % (k, v))
class NonDentedHeadingFormatter (optparse.IndentedHelpFormatter):
@@ -337,7 +328,7 @@ class NonEmptyOptionParser (optparse.OptionParser):
def parse_args (self, args=None, values=None):
options, args = optparse.OptionParser.parse_args (self, args, values)
- return options, filter (None, args)
+ return options, [_f for _f in args if _f]
def get_option_parser (*args, **kwargs):
p = NonEmptyOptionParser (*args, **kwargs)
« no previous file with comments | « python/langdefs.py ('k') | python/midi.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b