Mercurial > public > mercurial-scm > hg-stable
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 Thu Sep 15 00:49:40 2005 -0500 +++ b/mercurial/util.py Thu Sep 15 02:59:16 2005 -0500 @@ -12,7 +12,23 @@ 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"""