Show More
@@ -134,32 +134,20 b' class _multifile(object):' | |||||
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): |
|
137 | def __init__(self, ui, path, url, opener): | |
|
138 | self._ui = ui | |||
138 | self._path = path |
|
139 | self._path = path | |
|
140 | self._url = url | |||
139 | self._caps = None |
|
141 | self._caps = None | |
140 |
self._urlopener = |
|
142 | self._urlopener = opener | |
141 | # This is an its own attribute to facilitate extensions overriding |
|
143 | # This is an its own attribute to facilitate extensions overriding | |
142 | # the default type. |
|
144 | # the default type. | |
143 | self._requestbuilder = urlreq.request |
|
145 | self._requestbuilder = urlreq.request | |
144 | u = util.url(path) |
|
|||
145 | if u.query or u.fragment: |
|
|||
146 | raise error.Abort(_('unsupported URL component: "%s"') % |
|
|||
147 | (u.query or u.fragment)) |
|
|||
148 |
|
||||
149 | # urllib cannot handle URLs with embedded user or passwd |
|
|||
150 | self._url, authinfo = u.authinfo() |
|
|||
151 |
|
||||
152 | self._ui = ui |
|
|||
153 | ui.debug('using %s\n' % self._url) |
|
|||
154 |
|
||||
155 | self._urlopener = urlmod.opener(ui, authinfo) |
|
|||
156 |
|
146 | |||
157 | def __del__(self): |
|
147 | def __del__(self): | |
158 | urlopener = getattr(self, '_urlopener', None) |
|
148 | for h in self._urlopener.handlers: | |
159 | if urlopener: |
|
149 | h.close() | |
160 | for h in urlopener.handlers: |
|
150 | getattr(h, "close_all", lambda: None)() | |
161 | h.close() |
|
|||
162 | getattr(h, "close_all", lambda: None)() |
|
|||
163 |
|
151 | |||
164 | def _openurl(self, req): |
|
152 | def _openurl(self, req): | |
165 | if (self._ui.debugflag |
|
153 | if (self._ui.debugflag | |
@@ -483,6 +471,20 b' class httppeer(wireproto.wirepeer):' | |||||
483 | def _abort(self, exception): |
|
471 | def _abort(self, exception): | |
484 | raise exception |
|
472 | raise exception | |
485 |
|
473 | |||
|
474 | def makepeer(ui, path): | |||
|
475 | u = util.url(path) | |||
|
476 | if u.query or u.fragment: | |||
|
477 | raise error.Abort(_('unsupported URL component: "%s"') % | |||
|
478 | (u.query or u.fragment)) | |||
|
479 | ||||
|
480 | # urllib cannot handle URLs with embedded user or passwd. | |||
|
481 | url, authinfo = u.authinfo() | |||
|
482 | ui.debug('using %s\n' % url) | |||
|
483 | ||||
|
484 | opener = urlmod.opener(ui, authinfo) | |||
|
485 | ||||
|
486 | return httppeer(ui, path, url, opener) | |||
|
487 | ||||
486 | def instance(ui, path, create): |
|
488 | def instance(ui, path, create): | |
487 | if create: |
|
489 | if create: | |
488 | raise error.Abort(_('cannot create new http repository')) |
|
490 | raise error.Abort(_('cannot create new http repository')) | |
@@ -491,7 +493,7 b' def instance(ui, path, create):' | |||||
491 | raise error.Abort(_('Python support for SSL and HTTPS ' |
|
493 | raise error.Abort(_('Python support for SSL and HTTPS ' | |
492 | 'is not installed')) |
|
494 | 'is not installed')) | |
493 |
|
495 | |||
494 |
inst = |
|
496 | inst = makepeer(ui, path) | |
495 | inst._fetchcaps() |
|
497 | inst._fetchcaps() | |
496 |
|
498 | |||
497 | return inst |
|
499 | return inst |
@@ -50,10 +50,13 b' class dummyrepo(object):' | |||||
50 | def _restrictcapabilities(self, caps): |
|
50 | def _restrictcapabilities(self, caps): | |
51 | pass |
|
51 | pass | |
52 |
|
52 | |||
|
53 | class dummyopener(object): | |||
|
54 | handlers = [] | |||
|
55 | ||||
53 | # Facilitates testing sshpeer without requiring an SSH server. |
|
56 | # Facilitates testing sshpeer without requiring an SSH server. | |
54 | class badpeer(httppeer.httppeer): |
|
57 | class badpeer(httppeer.httppeer): | |
55 | def __init__(self): |
|
58 | def __init__(self): | |
56 |
super(badpeer, self).__init__( |
|
59 | super(badpeer, self).__init__(None, None, None, dummyopener()) | |
57 | self.badattribute = True |
|
60 | self.badattribute = True | |
58 |
|
61 | |||
59 | def badmethod(self): |
|
62 | def badmethod(self): | |
@@ -67,7 +70,7 b' def main():' | |||||
67 | ui = uimod.ui() |
|
70 | ui = uimod.ui() | |
68 |
|
71 | |||
69 | checkobject(badpeer()) |
|
72 | checkobject(badpeer()) | |
70 |
checkobject(httppeer.httppeer( |
|
73 | checkobject(httppeer.httppeer(None, None, None, dummyopener())) | |
71 | checkobject(localrepo.localpeer(dummyrepo())) |
|
74 | checkobject(localrepo.localpeer(dummyrepo())) | |
72 | checkobject(sshpeer.sshv1peer(ui, 'ssh://localhost/foo', None, dummypipe(), |
|
75 | checkobject(sshpeer.sshv1peer(ui, 'ssh://localhost/foo', None, dummypipe(), | |
73 | dummypipe(), None, None)) |
|
76 | dummypipe(), None, None)) |
General Comments 0
You need to be logged in to leave comments.
Login now