comparison mercurial/util.py @ 30473:39d13b8c101d

py3: bulk replace sys.stdin/out/err by util's Almost all sys.stdin/out/err in hgext/ and mercurial/ are replaced by util's. There are a few exceptions: - lsprof.py and statprof.py are untouched since they are a kind of vendor code and they never import mercurial modules right now. - ui._readline() needs to replace sys.stdin and stdout to pass them to raw_input(). We'll need another workaround here.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 20 Oct 2016 23:53:36 +0900
parents 277f4fe6d01a
children 98d7636c4729
comparison
equal deleted inserted replaced
30472:277f4fe6d01a 30473:39d13b8c101d
984 if out is specified, it is assumed to be a file-like object that has a 984 if out is specified, it is assumed to be a file-like object that has a
985 write() method. stdout and stderr will be redirected to out.''' 985 write() method. stdout and stderr will be redirected to out.'''
986 if environ is None: 986 if environ is None:
987 environ = {} 987 environ = {}
988 try: 988 try:
989 sys.stdout.flush() 989 stdout.flush()
990 except Exception: 990 except Exception:
991 pass 991 pass
992 def py2shell(val): 992 def py2shell(val):
993 'convert python object into string that is useful to shell' 993 'convert python object into string that is useful to shell'
994 if val is None or val is False: 994 if val is None or val is False:
2757 try: 2757 try:
2758 return func(*args, **kwargs) 2758 return func(*args, **kwargs)
2759 finally: 2759 finally:
2760 elapsed = time.time() - start 2760 elapsed = time.time() - start
2761 _timenesting[0] -= indent 2761 _timenesting[0] -= indent
2762 sys.stderr.write('%s%s: %s\n' % 2762 stderr.write('%s%s: %s\n' %
2763 (' ' * _timenesting[0], func.__name__, 2763 (' ' * _timenesting[0], func.__name__,
2764 timecount(elapsed))) 2764 timecount(elapsed)))
2765 return wrapper 2765 return wrapper
2766 2766
2767 _sizeunits = (('m', 2**20), ('k', 2**10), ('g', 2**30), 2767 _sizeunits = (('m', 2**20), ('k', 2**10), ('g', 2**30),
2768 ('kb', 2**10), ('mb', 2**20), ('gb', 2**30), ('b', 1)) 2768 ('kb', 2**10), ('mb', 2**20), ('gb', 2**30), ('b', 1))
2769 2769
2824 if line is None: 2824 if line is None:
2825 yield (fnmax, fnln, func) 2825 yield (fnmax, fnln, func)
2826 else: 2826 else:
2827 yield line % (fnmax, fnln, func) 2827 yield line % (fnmax, fnln, func)
2828 2828
2829 def debugstacktrace(msg='stacktrace', skip=0, f=sys.stderr, otherf=sys.stdout): 2829 def debugstacktrace(msg='stacktrace', skip=0, f=stderr, otherf=stdout):
2830 '''Writes a message to f (stderr) with a nicely formatted stacktrace. 2830 '''Writes a message to f (stderr) with a nicely formatted stacktrace.
2831 Skips the 'skip' last entries. By default it will flush stdout first. 2831 Skips the 'skip' last entries. By default it will flush stdout first.
2832 It can be used everywhere and intentionally does not require an ui object. 2832 It can be used everywhere and intentionally does not require an ui object.
2833 Not be used in production code but very convenient while developing. 2833 Not be used in production code but very convenient while developing.
2834 ''' 2834 '''