[gtk-doc] fixxref: don’t mix and match bytes and strings



commit 7946cdfa841bb573652f29cd7eee6c4bb4d0f0ef
Author: Ernestas Kulik <ernestask gnome org>
Date:   Sun Apr 30 23:32:17 2017 +0300

    fixxref: don’t mix and match bytes and strings
    
    NamedTemporaryFile() opens the file in binary mode by default, which
    doesn’t work, since strings are being written to it. Additionally, the
    code tries to perform a regex substitution on subprocess.check_output()
    return value, which is not a string.
    
    Signed-off-by: Ernestas Kulik <ernestask gnome org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781994

 gtkdoc/fixxref.py |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/gtkdoc/fixxref.py b/gtkdoc/fixxref.py
index 4893b87..0db6c46 100755
--- a/gtkdoc/fixxref.py
+++ b/gtkdoc/fixxref.py
@@ -335,7 +335,7 @@ def HighlightSource(options, type, source):
 
     # write source to a temp file
     # FIXME: use .c for now to hint the language to the highlighter
-    with tempfile.NamedTemporaryFile(suffix='.c') as f:
+    with tempfile.NamedTemporaryFile(mode='w+', suffix='.c') as f:
         f.write(source)
         f.flush()
         temp_source_file = f.name
@@ -344,8 +344,9 @@ def HighlightSource(options, type, source):
         logging.info('running %s %s %s', config.highlight, highlight_options, temp_source_file)
 
         # format source
+        # returns bytes, thus needs to be decoded to use in re.sub()
         highlighted_source = subprocess.check_output(
-            [config.highlight] + shlex.split(highlight_options) + [temp_source_file])
+            [config.highlight] + shlex.split(highlight_options) + [temp_source_file]).decode('utf-8')
         logging.debug('result: [%s]', highlighted_source)
         if config.highlight.endswith('/source-highlight'):
             highlighted_source = re.sub(r'^<\!-- .*? -->', '', highlighted_source, flags=re.MULTILINE | 
re.DOTALL)
@@ -371,7 +372,7 @@ def HighlightSourceVim(options, type, source):
     source = HighlightSourcePreProcess(source)
 
     # write source to a temp file
-    with tempfile.NamedTemporaryFile(suffix='.h') as f:
+    with tempfile.NamedTemporaryFile(mode='w+', suffix='.h') as f:
         f.write(source)
         f.flush()
         temp_source_file = f.name


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]