[llvm] r329123 - 'cat' command for internal shell - Support Python 3
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 3 15:38:25 PDT 2018
Author: rnk
Date: Tue Apr 3 15:38:25 2018
New Revision: 329123
URL: http://llvm.org/viewvc/llvm-project?rev=329123&view=rev
Log:
'cat' command for internal shell - Support Python 3
LLVM Bug Id : 36449
Revision 328563 caused tests to fail under python 3.
This patch modified cat.py file to support both python 2 and 3.
This patch also fixes CRLF issues on Windows.
Patch by Chamal de Silva
Differential Revision: https://reviews.llvm.org/D45077
Modified:
llvm/trunk/utils/lit/lit/builtin_commands/cat.py
Modified: llvm/trunk/utils/lit/lit/builtin_commands/cat.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/builtin_commands/cat.py?rev=329123&r1=329122&r2=329123&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/builtin_commands/cat.py (original)
+++ llvm/trunk/utils/lit/lit/builtin_commands/cat.py Tue Apr 3 15:38:25 2018
@@ -7,8 +7,10 @@ except ImportError:
def convertToCaretAndMNotation(data):
newdata = StringIO()
- for char in data:
- intval = ord(char)
+ if isinstance(data, str):
+ data = bytearray(data)
+
+ for intval in data:
if intval == 9 or intval == 10:
newdata.write(chr(intval))
continue
@@ -23,7 +25,7 @@ def convertToCaretAndMNotation(data):
else:
newdata.write(chr(intval))
- return newdata.getvalue();
+ return newdata.getvalue().encode()
def main(argv):
@@ -42,13 +44,19 @@ def main(argv):
if option == "-v" or option == "--show-nonprinting":
show_nonprinting = True;
+ writer = getattr(sys.stdout, 'buffer', None)
+ if writer is None:
+ writer = sys.stdout
+ if sys.platform == "win32":
+ import os, msvcrt
+ msvcrt.setmode(sys.stdout.fileno(),os.O_BINARY)
for filename in filenames:
try:
fileToCat = open(filename,"rb")
contents = fileToCat.read()
if show_nonprinting:
contents = convertToCaretAndMNotation(contents)
- sys.stdout.write(contents)
+ writer.write(contents)
sys.stdout.flush()
fileToCat.close()
except IOError as error:
More information about the llvm-commits
mailing list