comparison 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
comparison
equal deleted inserted replaced
1256:8054fdb0b145 1258:1945754e466b
10 platform-specific details from the core. 10 platform-specific details from the core.
11 """ 11 """
12 12
13 import os, errno 13 import os, errno
14 from demandload import * 14 from demandload import *
15 demandload(globals(), "re cStringIO shutil") 15 demandload(globals(), "re cStringIO shutil popen2 threading")
16
17 def filter(s, cmd):
18 "filter a string through a command that transforms its input to its output"
19 (pout, pin) = popen2.popen2(cmd, -1, 'b')
20 def writer():
21 pin.write(s)
22 pin.close()
23
24 # we should use select instead on UNIX, but this will work on most
25 # systems, including Windows
26 w = threading.Thread(target=writer)
27 w.start()
28 f = pout.read()
29 pout.close()
30 w.join()
31 return f
16 32
17 def binary(s): 33 def binary(s):
18 """return true if a string is binary data using diff's heuristic""" 34 """return true if a string is binary data using diff's heuristic"""
19 if s and '\0' in s[:4096]: 35 if s and '\0' in s[:4096]:
20 return True 36 return True