use 2 streams (input and output) instead of 1 in parse_from_memory()
[diff2html.git] / diff2html.py
index d573d8f..b361491 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,13 @@ 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 "
+    input_stream = StringIO.StringIO(txt)
+    output_stream = StringIO.StringIO()
+    parse_input(input_stream, output_stream, exclude_headers, show_hunk_infos)
+    return output_stream.getvalue()
+
 
 if __name__ == "__main__":
     main()