diff mercurial/util.py @ 1258:1945754e466b

Add file encoding/decoding support
author mpm@selenic.com
date Thu, 15 Sep 2005 02:59:16 -0500
parents 3b4f05ff3130
children fc3b41570082
line wrap: on
line diff
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -12,7 +12,23 @@ platform-specific details from the core.
 
 import os, errno
 from demandload import *
-demandload(globals(), "re cStringIO shutil")
+demandload(globals(), "re cStringIO shutil popen2 threading")
+
+def filter(s, cmd):
+    "filter a string through a command that transforms its input to its output"
+    (pout, pin) = popen2.popen2(cmd, -1, 'b')
+    def writer():
+        pin.write(s)
+        pin.close()
+
+    # we should use select instead on UNIX, but this will work on most
+    # systems, including Windows
+    w = threading.Thread(target=writer)
+    w.start()
+    f = pout.read()
+    pout.close()
+    w.join()
+    return f
 
 def binary(s):
     """return true if a string is binary data using diff's heuristic"""