allow to be called with strings instead of IO files
authorOlivier Matz <olivier.matz@6wind.com>
Fri, 15 Jun 2012 13:36:25 +0000 (15:36 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 9 Aug 2012 18:10:08 +0000 (20:10 +0200)
Signed-off-by: Sergey Satskiy <sergey.satskiy@gmail.com>
Signed-off-by: Olivier Matz <zer0@droids-corp.org>
diff2html.py

index d573d8f..337667f 100644 (file)
@@ -33,7 +33,7 @@
 #   and display those directly.
 
 
-import sys, re, htmlentitydefs, getopt
+import sys, re, htmlentitydefs, getopt, StringIO
 
 # minimum line size, we add a zero-sized breakable space every
 # LINESIZE characters
@@ -422,6 +422,11 @@ def main():
     parse_input(input_file, output_file,
                 exclude_headers, show_hunk_infos)
 
+def parse_from_memory(txt, exclude_headers, show_hunk_infos):
+    " Parses diff from memory and returns a string with html "
+    stream = StringIO.StringIO(txt)
+    parse_input(stream, stream, exclude_headers, show_hunk_infos)
+    return stream.buf
 
 if __name__ == "__main__":
     main()