comparison mercurial/ui.py @ 5337:8c5ef3b87cb1

Don't try to determine interactivity if ui() called with interactive=False. WSGI applications are not supposed to refer to sys.stdin. In ed6df6b1c29a, hgweb and hgwebdir were fixed to pass interactive=False to their ui()'s, but sys.stdin.isatty() was still called by the ui objects. This change makes sure only the ui.fixconfig() method will call ui.isatty() (by making the ui._readline() method, which is currently only called from ui.prompt(), private). ui.fixconfig() is changed to let config files override the initial interactivity setting, but not check isatty() if interactive=False was specified in the creation of the ui.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Tue, 25 Sep 2007 19:05:34 +0200
parents 67afecb8d6cc
children 2e76e5a23c2b b5605d88dc27
comparison
equal deleted inserted replaced
5336:24de027551c1 5337:8c5ef3b87cb1
209 # update verbosity/interactive/report_untrusted settings 209 # update verbosity/interactive/report_untrusted settings
210 if section is None or section == 'ui': 210 if section is None or section == 'ui':
211 if name is None or name in ('quiet', 'verbose', 'debug'): 211 if name is None or name in ('quiet', 'verbose', 'debug'):
212 self.verbosity_constraints() 212 self.verbosity_constraints()
213 if name is None or name == 'interactive': 213 if name is None or name == 'interactive':
214 self.interactive = self.configbool("ui", "interactive", None) 214 interactive = self.configbool("ui", "interactive", None)
215 if self.interactive is None: 215 if interactive is None and self.interactive:
216 self.interactive = self.isatty() 216 self.interactive = self.isatty()
217 else:
218 self.interactive = interactive
217 if name is None or name == 'report_untrusted': 219 if name is None or name == 'report_untrusted':
218 self.report_untrusted = ( 220 self.report_untrusted = (
219 self.configbool("ui", "report_untrusted", True)) 221 self.configbool("ui", "report_untrusted", True))
220 222
221 # update trust information 223 # update trust information
389 try: sys.stdout.flush() 391 try: sys.stdout.flush()
390 except: pass 392 except: pass
391 try: sys.stderr.flush() 393 try: sys.stderr.flush()
392 except: pass 394 except: pass
393 395
394 def readline(self, prompt=''): 396 def _readline(self, prompt=''):
395 if self.isatty(): 397 if self.isatty():
396 try: 398 try:
397 # magically add command line editing support, where 399 # magically add command line editing support, where
398 # available 400 # available
399 import readline 401 import readline
404 return raw_input(prompt) 406 return raw_input(prompt)
405 407
406 def prompt(self, msg, pat=None, default="y", matchflags=0): 408 def prompt(self, msg, pat=None, default="y", matchflags=0):
407 if not self.interactive: return default 409 if not self.interactive: return default
408 try: 410 try:
409 r = self.readline(msg + ' ') 411 r = self._readline(msg + ' ')
410 if not pat or re.match(pat, r, matchflags): 412 if not pat or re.match(pat, r, matchflags):
411 return r 413 return r
412 else: 414 else:
413 self.write(_("unrecognized response\n")) 415 self.write(_("unrecognized response\n"))
414 except EOFError: 416 except EOFError: