Mercurial > hg
annotate mercurial/formatter.py @ 20172:181108726ea5
http: reuse authentication info after the first failed request (issue3567)
Context: mercurial access to repository server with http access, and this
server is protected by basic auth.
Before patch:
* mercurial try an anonymous access to server, server return 401 response and
mercurial resend request with login / password information
After patch:
* mercurial try an anonymous access to server, server return 401
response. For all subsequent requests, mercurial keep in memory this
information (this server need basic auth information).
This patch reduce the number of http access against mercurial server.
Example, before patch :
10.10.168.170 - - [25/Oct/2013:15:44:51 +0200] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:44:52 +0200] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 200 147 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:00 +0200] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:01 +0200] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 200 147 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:03 +0200] "GET /hg/testagt?cmd=batch
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:04 +0200] "GET /hg/testagt?cmd=batch
HTTP/1.1" 200 42 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:06 +0200] "GET /hg/testagt?cmd=getbundle
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:07 +0200] "GET /hg/testagt?cmd=getbundle
HTTP/1.1" 200 61184 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:09 +0200] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:10 +0200] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 200 15 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:12 +0200] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [25/Oct/2013:15:45:12 +0200] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 200 - "-" "mercurial/proto-1.0"
Example after patch :
10.10.168.170 - - [28/Oct/2013:11:49:14 +0100] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 401 260 "-" "mercurial/proto-1.0"
10.10.168.170 - - [28/Oct/2013:11:49:15 +0100] "GET /hg/testagt?cmd=capabilities
HTTP/1.1" 200 147 "-" "mercurial/proto-1.0"
10.10.168.170 - - [28/Oct/2013:11:49:17 +0100] "GET /hg/testagt?cmd=batch
HTTP/1.1" 200 42 "-" "mercurial/proto-1.0"
10.10.168.170 - - [28/Oct/2013:11:49:19 +0100] "GET /hg/testagt?cmd=getbundle
HTTP/1.1" 200 61184 "-" "mercurial/proto-1.0"
10.10.168.170 - - [28/Oct/2013:11:49:22 +0100] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 200 15 "-" "mercurial/proto-1.0"
10.10.168.170 - - [28/Oct/2013:11:49:24 +0100] "GET /hg/testagt?cmd=listkeys
HTTP/1.1" 200 - "-" "mercurial/proto-1.0"
In this last example, you can see only one 401 response.
author | Stéphane Klein <contact@stephane-klein.info> |
---|---|
date | Mon, 25 Nov 2013 17:18:12 +0100 |
parents | 3326fd05eb1f |
children | 1f72226064b8 |
rev | line source |
---|---|
16134 | 1 # formatter.py - generic output formatting for mercurial |
2 # | |
3 # Copyright 2012 Matt Mackall <mpm@selenic.com> | |
4 # | |
5 # This software may be used and distributed according to the terms of the | |
6 # GNU General Public License version 2 or any later version. | |
7 | |
8 class baseformatter(object): | |
9 def __init__(self, ui, topic, opts): | |
10 self._ui = ui | |
11 self._topic = topic | |
12 self._style = opts.get("style") | |
13 self._template = opts.get("template") | |
14 self._item = None | |
15 def __bool__(self): | |
16 '''return False if we're not doing real templating so we can | |
17 skip extra work''' | |
18 return True | |
19 def _showitem(self): | |
20 '''show a formatted item once all data is collected''' | |
21 pass | |
22 def startitem(self): | |
23 '''begin an item in the format list''' | |
24 if self._item is not None: | |
25 self._showitem() | |
26 self._item = {} | |
27 def data(self, **data): | |
28 '''insert data into item that's not shown in default output''' | |
17630
ff5ed1ecd43a
formatter: improve implementation of data method
David M. Carr <david@carrclan.us>
parents:
17597
diff
changeset
|
29 self._item.update(data) |
16134 | 30 def write(self, fields, deftext, *fielddata, **opts): |
31 '''do default text output while assigning data to item''' | |
32 for k, v in zip(fields.split(), fielddata): | |
33 self._item[k] = v | |
17909
3326fd05eb1f
formatter: add condwrite method
Matt Mackall <mpm@selenic.com>
parents:
17630
diff
changeset
|
34 def condwrite(self, cond, fields, deftext, *fielddata, **opts): |
3326fd05eb1f
formatter: add condwrite method
Matt Mackall <mpm@selenic.com>
parents:
17630
diff
changeset
|
35 '''do conditional write (primarily for plain formatter)''' |
3326fd05eb1f
formatter: add condwrite method
Matt Mackall <mpm@selenic.com>
parents:
17630
diff
changeset
|
36 for k, v in zip(fields.split(), fielddata): |
3326fd05eb1f
formatter: add condwrite method
Matt Mackall <mpm@selenic.com>
parents:
17630
diff
changeset
|
37 self._item[k] = v |
16134 | 38 def plain(self, text, **opts): |
39 '''show raw text for non-templated mode''' | |
40 pass | |
41 def end(self): | |
42 '''end output for the formatter''' | |
43 if self._item is not None: | |
44 self._showitem() | |
45 | |
46 class plainformatter(baseformatter): | |
47 '''the default text output scheme''' | |
48 def __init__(self, ui, topic, opts): | |
49 baseformatter.__init__(self, ui, topic, opts) | |
50 def __bool__(self): | |
51 return False | |
52 def startitem(self): | |
53 pass | |
54 def data(self, **data): | |
55 pass | |
56 def write(self, fields, deftext, *fielddata, **opts): | |
57 self._ui.write(deftext % fielddata, **opts) | |
17909
3326fd05eb1f
formatter: add condwrite method
Matt Mackall <mpm@selenic.com>
parents:
17630
diff
changeset
|
58 def condwrite(self, cond, fields, deftext, *fielddata, **opts): |
3326fd05eb1f
formatter: add condwrite method
Matt Mackall <mpm@selenic.com>
parents:
17630
diff
changeset
|
59 '''do conditional write''' |
3326fd05eb1f
formatter: add condwrite method
Matt Mackall <mpm@selenic.com>
parents:
17630
diff
changeset
|
60 if cond: |
3326fd05eb1f
formatter: add condwrite method
Matt Mackall <mpm@selenic.com>
parents:
17630
diff
changeset
|
61 self._ui.write(deftext % fielddata, **opts) |
16134 | 62 def plain(self, text, **opts): |
63 self._ui.write(text, **opts) | |
64 def end(self): | |
65 pass | |
66 | |
67 class debugformatter(baseformatter): | |
68 def __init__(self, ui, topic, opts): | |
69 baseformatter.__init__(self, ui, topic, opts) | |
70 self._ui.write("%s = {\n" % self._topic) | |
71 def _showitem(self): | |
72 self._ui.write(" " + repr(self._item) + ",\n") | |
73 def end(self): | |
74 baseformatter.end(self) | |
75 self._ui.write("}\n") | |
76 | |
77 def formatter(ui, topic, opts): | |
78 if ui.configbool('ui', 'formatdebug'): | |
79 return debugformatter(ui, topic, opts) | |
80 return plainformatter(ui, topic, opts) |