Mercurial > hg
comparison mercurial/httppeer.py @ 37321:e826fe7a08c7
peer: make ui an attribute
With abc interfaces, instance attributes could not satisfy
@abc.abstractproperty requirements because interface conformance
was tested at type creation time. When we created the abc
peer interfaces, we had to make "ui" a @property to satisfy
abc.
Now that peer interfaces are using zope.interface and there is no
import time validation (but there are tests validating instances
conform to the interface), we can go back to using regular object
attributes.
Differential Revision: https://phab.mercurial-scm.org/D3069
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 30 Mar 2018 18:57:13 -0700 |
parents | 39f7d4ee8bcd |
children | 3e1688711efd |
comparison
equal
deleted
inserted
replaced
37320:39f7d4ee8bcd | 37321:e826fe7a08c7 |
---|---|
133 f.seek(0) | 133 f.seek(0) |
134 self._index = 0 | 134 self._index = 0 |
135 | 135 |
136 class httppeer(wireproto.wirepeer): | 136 class httppeer(wireproto.wirepeer): |
137 def __init__(self, ui, path, url, opener): | 137 def __init__(self, ui, path, url, opener): |
138 self._ui = ui | 138 self.ui = ui |
139 self._path = path | 139 self._path = path |
140 self._url = url | 140 self._url = url |
141 self._caps = None | 141 self._caps = None |
142 self._urlopener = opener | 142 self._urlopener = opener |
143 # This is an its own attribute to facilitate extensions overriding | 143 # This is an its own attribute to facilitate extensions overriding |
148 for h in self._urlopener.handlers: | 148 for h in self._urlopener.handlers: |
149 h.close() | 149 h.close() |
150 getattr(h, "close_all", lambda: None)() | 150 getattr(h, "close_all", lambda: None)() |
151 | 151 |
152 def _openurl(self, req): | 152 def _openurl(self, req): |
153 if (self._ui.debugflag | 153 if (self.ui.debugflag |
154 and self._ui.configbool('devel', 'debug.peer-request')): | 154 and self.ui.configbool('devel', 'debug.peer-request')): |
155 dbg = self._ui.debug | 155 dbg = self.ui.debug |
156 line = 'devel-peer-request: %s\n' | 156 line = 'devel-peer-request: %s\n' |
157 dbg(line % '%s %s' % (req.get_method(), req.get_full_url())) | 157 dbg(line % '%s %s' % (req.get_method(), req.get_full_url())) |
158 hgargssize = None | 158 hgargssize = None |
159 | 159 |
160 for header, value in sorted(req.header_items()): | 160 for header, value in sorted(req.header_items()): |
177 dbg(line % ' %d bytes of data' % length) | 177 dbg(line % ' %d bytes of data' % length) |
178 | 178 |
179 start = util.timer() | 179 start = util.timer() |
180 | 180 |
181 ret = self._urlopener.open(req) | 181 ret = self._urlopener.open(req) |
182 if self._ui.configbool('devel', 'debug.peer-request'): | 182 if self.ui.configbool('devel', 'debug.peer-request'): |
183 dbg(line % ' finished in %.4f seconds (%s)' | 183 dbg(line % ' finished in %.4f seconds (%s)' |
184 % (util.timer() - start, ret.code)) | 184 % (util.timer() - start, ret.code)) |
185 return ret | 185 return ret |
186 | 186 |
187 # Begin of ipeerconnection interface. | 187 # Begin of ipeerconnection interface. |
188 | |
189 @util.propertycache | |
190 def ui(self): | |
191 return self._ui | |
192 | 188 |
193 def url(self): | 189 def url(self): |
194 return self._path | 190 return self._path |
195 | 191 |
196 def local(self): | 192 def local(self): |