##// END OF EJS Templates
ui: move protectedstdio() context manager from procutil...
Yuya Nishihara -
r41320:b0e3f2d7 default
parent child Browse files
Show More
@@ -399,7 +399,7 b' class pipeservice(object):'
399 ui = self.ui
399 ui = self.ui
400 # redirect stdio to null device so that broken extensions or in-process
400 # redirect stdio to null device so that broken extensions or in-process
401 # hooks will never cause corruption of channel protocol.
401 # hooks will never cause corruption of channel protocol.
402 with procutil.protectedstdio(ui.fin, ui.fout) as (fin, fout):
402 with ui.protectedfinout() as (fin, fout):
403 sv = server(ui, self.repo, fin, fout)
403 sv = server(ui, self.repo, fin, fout)
404 try:
404 try:
405 return sv.serve()
405 return sv.serve()
@@ -1080,6 +1080,15 b' class ui(object):'
1080 return False
1080 return False
1081 return procutil.isatty(fh)
1081 return procutil.isatty(fh)
1082
1082
1083 @contextlib.contextmanager
1084 def protectedfinout(self):
1085 """Run code block with protected standard streams"""
1086 fin, fout = procutil.protectstdio(self._fin, self._fout)
1087 try:
1088 yield fin, fout
1089 finally:
1090 procutil.restorestdio(self._fin, self._fout, fin, fout)
1091
1083 def disablepager(self):
1092 def disablepager(self):
1084 self._disablepager = True
1093 self._disablepager = True
1085
1094
@@ -299,15 +299,6 b' def restorestdio(uin, uout, fin, fout):'
299 os.dup2(f.fileno(), uif.fileno())
299 os.dup2(f.fileno(), uif.fileno())
300 f.close()
300 f.close()
301
301
302 @contextlib.contextmanager
303 def protectedstdio(uin, uout):
304 """Run code block with protected standard streams"""
305 fin, fout = protectstdio(uin, uout)
306 try:
307 yield fin, fout
308 finally:
309 restorestdio(uin, uout, fin, fout)
310
311 def shellenviron(environ=None):
302 def shellenviron(environ=None):
312 """return environ with optional override, useful for shelling out"""
303 """return environ with optional override, useful for shelling out"""
313 def py2shell(val):
304 def py2shell(val):
General Comments 0
You need to be logged in to leave comments. Login now