[gtk-doc] fixxref: make python 2/3 compat



commit 17a12bb48670e0ca31644c5fad02503197c32e37
Author: Stefan Sauer <ensonic users sf net>
Date:   Fri Jun 16 22:49:42 2017 +0200

    fixxref: make python 2/3 compat
    
    Also move more common code into the helper we already have.

 gtkdoc/fixxref.py |   20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)
---
diff --git a/gtkdoc/fixxref.py b/gtkdoc/fixxref.py
index 8dbdf78..2b4c836 100755
--- a/gtkdoc/fixxref.py
+++ b/gtkdoc/fixxref.py
@@ -337,14 +337,10 @@ def MakeGtkDocLink(pre, symbol, post):
 
 
 def HighlightSource(options, type, source):
-    source = HighlightSourcePreProcess(source)
-
     # write source to a temp file
     # FIXME: use .c for now to hint the language to the highlighter
     with tempfile.NamedTemporaryFile(mode='w+', suffix='.c') as f:
-        f.write(source)
-        f.flush()
-        temp_source_file = f.name
+        temp_source_file = HighlightSourcePreProcess(f, source)
         highlight_options = config.highlight_options.replace('$SRC_LANG', options.src_lang)
 
         logging.info('running %s %s %s', config.highlight, highlight_options, temp_source_file)
@@ -374,13 +370,9 @@ def HighlightSource(options, type, source):
 
 
 def HighlightSourceVim(options, type, source):
-    source = HighlightSourcePreProcess(source)
-
     # write source to a temp file
     with tempfile.NamedTemporaryFile(mode='w+', suffix='.h') as f:
-        f.write(source)
-        f.flush()
-        temp_source_file = f.name
+        temp_source_file = HighlightSourcePreProcess(f, source)
 
         # format source
         # TODO(ensonic): use p.communicate()
@@ -408,7 +400,7 @@ def HighlightSourceVim(options, type, source):
     return HighlightSourcePostprocess(type, highlighted_source)
 
 
-def HighlightSourcePreProcess(source):
+def HighlightSourcePreProcess(f, source):
     # chop of leading and trailing empty lines, leave leading space in first real line
     source = source.strip(' ')
     source = source.strip('\n')
@@ -422,7 +414,11 @@ def HighlightSourcePreProcess(source):
     source = source.replace('&lt;', '<')
     source = source.replace('&gt;', '>')
     source = source.replace('&amp;', '&')
-    return source
+    if sys.version_info < (3,):
+        source = source.encode('utf-8')
+    f.write(source)
+    f.flush()
+    return f.name
 
 
 def HighlightSourcePostprocess(type, highlighted_source):


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