Show More
@@ -88,10 +88,10 b' def _wraphttpresponse(resp):' | |||||
88 |
|
88 | |||
89 | class httppeer(wireproto.wirepeer): |
|
89 | class httppeer(wireproto.wirepeer): | |
90 | def __init__(self, ui, path): |
|
90 | def __init__(self, ui, path): | |
91 | self.path = path |
|
91 | self._path = path | |
92 | self.caps = None |
|
92 | self._caps = None | |
93 | self.urlopener = None |
|
93 | self._urlopener = None | |
94 | self.requestbuilder = None |
|
94 | self._requestbuilder = None | |
95 | u = util.url(path) |
|
95 | u = util.url(path) | |
96 | if u.query or u.fragment: |
|
96 | if u.query or u.fragment: | |
97 | raise error.Abort(_('unsupported URL component: "%s"') % |
|
97 | raise error.Abort(_('unsupported URL component: "%s"') % | |
@@ -103,33 +103,33 b' class httppeer(wireproto.wirepeer):' | |||||
103 | self.ui = ui |
|
103 | self.ui = ui | |
104 | self.ui.debug('using %s\n' % self._url) |
|
104 | self.ui.debug('using %s\n' % self._url) | |
105 |
|
105 | |||
106 | self.urlopener = url.opener(ui, authinfo) |
|
106 | self._urlopener = url.opener(ui, authinfo) | |
107 | self.requestbuilder = urlreq.request |
|
107 | self._requestbuilder = urlreq.request | |
108 |
|
108 | |||
109 | def __del__(self): |
|
109 | def __del__(self): | |
110 | urlopener = getattr(self, 'urlopener', None) |
|
110 | urlopener = getattr(self, '_urlopener', None) | |
111 | if urlopener: |
|
111 | if urlopener: | |
112 | for h in urlopener.handlers: |
|
112 | for h in urlopener.handlers: | |
113 | h.close() |
|
113 | h.close() | |
114 | getattr(h, "close_all", lambda : None)() |
|
114 | getattr(h, "close_all", lambda : None)() | |
115 |
|
115 | |||
116 | def url(self): |
|
116 | def url(self): | |
117 | return self.path |
|
117 | return self._path | |
118 |
|
118 | |||
119 | # look up capabilities only when needed |
|
119 | # look up capabilities only when needed | |
120 |
|
120 | |||
121 | def _fetchcaps(self): |
|
121 | def _fetchcaps(self): | |
122 | self.caps = set(self._call('capabilities').split()) |
|
122 | self._caps = set(self._call('capabilities').split()) | |
123 |
|
123 | |||
124 | def _capabilities(self): |
|
124 | def _capabilities(self): | |
125 | if self.caps is None: |
|
125 | if self._caps is None: | |
126 | try: |
|
126 | try: | |
127 | self._fetchcaps() |
|
127 | self._fetchcaps() | |
128 | except error.RepoError: |
|
128 | except error.RepoError: | |
129 | self.caps = set() |
|
129 | self._caps = set() | |
130 | self.ui.debug('capabilities: %s\n' % |
|
130 | self.ui.debug('capabilities: %s\n' % | |
131 | (' '.join(self.caps or ['none']))) |
|
131 | (' '.join(self._caps or ['none']))) | |
132 | return self.caps |
|
132 | return self._caps | |
133 |
|
133 | |||
134 | def _callstream(self, cmd, _compressible=False, **args): |
|
134 | def _callstream(self, cmd, _compressible=False, **args): | |
135 | if cmd == 'pushkey': |
|
135 | if cmd == 'pushkey': | |
@@ -144,7 +144,7 b' class httppeer(wireproto.wirepeer):' | |||||
144 | # Important: don't use self.capable() here or else you end up |
|
144 | # Important: don't use self.capable() here or else you end up | |
145 | # with infinite recursion when trying to look up capabilities |
|
145 | # with infinite recursion when trying to look up capabilities | |
146 | # for the first time. |
|
146 | # for the first time. | |
147 | postargsok = self.caps is not None and 'httppostargs' in self.caps |
|
147 | postargsok = self._caps is not None and 'httppostargs' in self._caps | |
148 | # TODO: support for httppostargs when data is a file-like |
|
148 | # TODO: support for httppostargs when data is a file-like | |
149 | # object rather than a basestring |
|
149 | # object rather than a basestring | |
150 | canmungedata = not data or isinstance(data, basestring) |
|
150 | canmungedata = not data or isinstance(data, basestring) | |
@@ -189,7 +189,7 b' class httppeer(wireproto.wirepeer):' | |||||
189 | protoparams = [] |
|
189 | protoparams = [] | |
190 |
|
190 | |||
191 | mediatypes = set() |
|
191 | mediatypes = set() | |
192 | if self.caps is not None: |
|
192 | if self._caps is not None: | |
193 | mt = self.capable('httpmediatype') |
|
193 | mt = self.capable('httpmediatype') | |
194 | if mt: |
|
194 | if mt: | |
195 | protoparams.append('0.1') |
|
195 | protoparams.append('0.1') | |
@@ -217,13 +217,13 b' class httppeer(wireproto.wirepeer):' | |||||
217 | if varyheaders: |
|
217 | if varyheaders: | |
218 | headers['Vary'] = ','.join(varyheaders) |
|
218 | headers['Vary'] = ','.join(varyheaders) | |
219 |
|
219 | |||
220 | req = self.requestbuilder(cu, data, headers) |
|
220 | req = self._requestbuilder(cu, data, headers) | |
221 |
|
221 | |||
222 | if data is not None: |
|
222 | if data is not None: | |
223 | self.ui.debug("sending %s bytes\n" % size) |
|
223 | self.ui.debug("sending %s bytes\n" % size) | |
224 | req.add_unredirected_header('Content-Length', '%d' % size) |
|
224 | req.add_unredirected_header('Content-Length', '%d' % size) | |
225 | try: |
|
225 | try: | |
226 | resp = self.urlopener.open(req) |
|
226 | resp = self._urlopener.open(req) | |
227 | except urlerr.httperror as inst: |
|
227 | except urlerr.httperror as inst: | |
228 | if inst.code == 401: |
|
228 | if inst.code == 401: | |
229 | raise error.Abort(_('authorization failed')) |
|
229 | raise error.Abort(_('authorization failed')) |
General Comments 0
You need to be logged in to leave comments.
Login now