annotate hgext/win32text.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 8c5aca855b5d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4849
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
1 from mercurial import util, ui
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
2 from mercurial.i18n import gettext as _
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
3 import re
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
4
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
5 # regexp for single LF without CR preceding.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
6 re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
7
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
8 def dumbdecode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
9 # warn if already has CRLF in repository.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
10 # it might cause unexpected eol conversion.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
11 # see issue 302:
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
12 # http://www.selenic.com/mercurial/bts/issue302
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
13 if '\r\n' in s:
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
14 u = ui.ui()
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
15 u.warn(_('WARNING: file in repository already has CRLF line ending \n'
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
16 ' which does not need eol conversion by win32text plugin.\n'
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
17 ' Please reconsider encode/decode setting in'
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
18 ' mercurial.ini or .hg/hgrc\n'
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
19 ' before next commit.\n'))
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
20 # replace single LF to CRLF
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
21 return re_single_lf.sub('\\1\r\n', s)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
22
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
23 def dumbencode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
24 return s.replace('\r\n', '\n')
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
25
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
26 def clevertest(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
27 if '\0' in s: return False
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
28 return True
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
29
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
30 def cleverdecode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
31 if clevertest(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
32 return dumbdecode(s, cmd)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
33 return s
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
34
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
35 def cleverencode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
36 if clevertest(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
37 return dumbencode(s, cmd)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
38 return s
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
39
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
40 util.filtertable.update({
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
41 'dumbdecode:': dumbdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
42 'dumbencode:': dumbencode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
43 'cleverdecode:': cleverdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
44 'cleverencode:': cleverencode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4848
diff changeset
45 })