diff options
author | rsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-06-14 09:49:07 +0000 |
---|---|---|
committer | rsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-06-14 09:49:07 +0000 |
commit | 5117df9d9a1e63a1a2c1e9ccaee3d27ac4bc59ab (patch) | |
tree | 52f402c774ce9e4dc890f8ca02e15d1229f23ba0 /contrib | |
parent | 201ae58560d7a7886ef18dd390897b138c0328e2 (diff) | |
download | gcc-5117df9d9a1e63a1a2c1e9ccaee3d27ac4bc59ab.tar.gz |
contrib/
* dg-extract-results.py: For Python 3, force sys.stdout to handle
surrogate escape sequences.
(safe_open): New function.
(output_segment, main): Use it.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@211666 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/ChangeLog | 7 | ||||
-rw-r--r-- | contrib/dg-extract-results.py | 17 |
2 files changed, 22 insertions, 2 deletions
diff --git a/contrib/ChangeLog b/contrib/ChangeLog index 90a154e69b2..550a9ebb8e6 100644 --- a/contrib/ChangeLog +++ b/contrib/ChangeLog @@ -1,3 +1,10 @@ +2014-06-14 Richard Sandiford <rdsandiford@googlemail.com> + + * dg-extract-results.py: For Python 3, force sys.stdout to handle + surrogate escape sequences. + (safe_open): New function. + (output_segment, main): Use it. + 2014-05-25 Richard Sandiford <rdsandiford@googlemail.com> * dg-extract-results.py (Named): Remove __cmp__ method. diff --git a/contrib/dg-extract-results.py b/contrib/dg-extract-results.py index a5dfc5d8e92..cccbfd391dc 100644 --- a/contrib/dg-extract-results.py +++ b/contrib/dg-extract-results.py @@ -10,6 +10,7 @@ import sys import getopt import re +import io from datetime import datetime from operator import attrgetter @@ -21,6 +22,18 @@ strict = False # they should keep the original order. sort_logs = True +# A version of open() that is safe against whatever binary output +# might be added to the log. +def safe_open (filename): + if sys.version_info >= (3, 0): + return open (filename, 'r', errors = 'surrogateescape') + return open (filename, 'r') + +# Force stdout to handle escape sequences from a safe_open file. +if sys.version_info >= (3, 0): + sys.stdout = io.TextIOWrapper (sys.stdout.buffer, + errors = 'surrogateescape') + class Named: def __init__ (self, name): self.name = name @@ -457,7 +470,7 @@ class Prog: # Output a segment of text. def output_segment (self, segment): - with open (segment.filename, 'r') as file: + with safe_open (segment.filename) as file: file.seek (segment.start) for i in range (segment.lines): sys.stdout.write (file.readline()) @@ -540,7 +553,7 @@ class Prog: try: # Parse the input files. for filename in self.files: - with open (filename, 'r') as file: + with safe_open (filename) as file: self.parse_file (filename, file) # Decide what to output. |