--- a/yml2proc Fri Feb 15 10:45:57 2019 +0100
+++ b/yml2proc Mon Sep 23 19:25:58 2019 +0200
@@ -1,9 +1,9 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# vim: set fileencoding=utf-8 :
"""\
-YML/YSLT 2 processor version 5.10
-Copyleft (c), 2009-2018 Volker Birk http://fdik.org/yml/
+YML/YSLT 2 processor version 6.0
+Copyleft (c), 2009-2019 Volker Birk http://fdik.org/yml/
"""
@@ -33,7 +33,7 @@
msg = str(msg) + "\n"
except:
msg = u(msg) + u"\n"
- if type(msg) is unicode:
+ if type(msg) is str:
msg = codecs.encode(msg, sys.stderr.encoding)
sys.stderr.write(msg)
@@ -182,7 +182,7 @@
if options.params:
params = eval(options.params)
for key, value in params.iteritems():
- if type(value) != unicode:
+ if type(value) is not str:
params[key] = u(value)
if options.stringparams:
for key, value in eval(options.stringparams).iteritems():
@@ -203,10 +203,10 @@
if options.pretty:
plaintext = etree.tostring(etree.fromstring(rtext), pretty_print=True, xml_declaration=True, encoding=options.encoding)
else:
- if isinstance(rtext, unicode):
+ if isinstance(rtext, str):
plaintext = codecs.encode(rtext, options.encoding)
else:
- plaintext = str(rtext)
+ plaintext = rtext
try:
if plaintext[-1] == "\n":
@@ -214,11 +214,13 @@
except: pass
if options.outputFile and options.outputFile != "-":
- outfile = open(options.outputFile, "w")
+ outfile = open(options.outputFile, "wb")
outfile.write(plaintext)
outfile.close()
else:
- print(plaintext)
+ sys.stdout.buffer.write(plaintext)
+ if not options.pretty:
+ print()
except KeyboardInterrupt:
w("\n")