Let's have the interface live next to things that define it.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
Let's have the interface live next to things that define it.
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/wireproto.py (40 lines) | |||
| M | mercurial/wireprotoserver.py (44 lines) |
| urlerr = util.urlerr | urlerr = util.urlerr | ||||
| urlreq = util.urlreq | urlreq = util.urlreq | ||||
| bundle2requiredmain = _('incompatible Mercurial client; bundle2 required') | bundle2requiredmain = _('incompatible Mercurial client; bundle2 required') | ||||
| bundle2requiredhint = _('see https://www.mercurial-scm.org/wiki/' | bundle2requiredhint = _('see https://www.mercurial-scm.org/wiki/' | ||||
| 'IncompatibleClient') | 'IncompatibleClient') | ||||
| bundle2required = '%s\n(%s)\n' % (bundle2requiredmain, bundle2requiredhint) | bundle2required = '%s\n(%s)\n' % (bundle2requiredmain, bundle2requiredhint) | ||||
| class abstractserverproto(object): | |||||
| """abstract class that summarizes the protocol API | |||||
| Used as reference and documentation. | |||||
| """ | |||||
| def getargs(self, args): | |||||
| """return the value for arguments in <args> | |||||
| returns a list of values (same order as <args>)""" | |||||
| raise NotImplementedError() | |||||
| def getfile(self, fp): | |||||
| """write the whole content of a file into a file like object | |||||
| The file is in the form:: | |||||
| (<chunk-size>\n<chunk>)+0\n | |||||
| chunk size is the ascii version of the int. | |||||
| """ | |||||
| raise NotImplementedError() | |||||
| def redirect(self): | |||||
| """may setup interception for stdout and stderr | |||||
| See also the `restore` method.""" | |||||
| raise NotImplementedError() | |||||
| # If the `redirect` function does install interception, the `restore` | |||||
| # function MUST be defined. If interception is not used, this function | |||||
| # MUST NOT be defined. | |||||
| # | |||||
| # left commented here on purpose | |||||
| # | |||||
| #def restore(self): | |||||
| # """reinstall previous stdout and stderr and return intercepted stdout | |||||
| # """ | |||||
| # raise NotImplementedError() | |||||
| class remoteiterbatcher(peer.iterbatcher): | class remoteiterbatcher(peer.iterbatcher): | ||||
| def __init__(self, remote): | def __init__(self, remote): | ||||
| super(remoteiterbatcher, self).__init__() | super(remoteiterbatcher, self).__init__() | ||||
| self._remote = remote | self._remote = remote | ||||
| def __getattr__(self, name): | def __getattr__(self, name): | ||||
| # Validate this method is batchable, since submit() only supports | # Validate this method is batchable, since submit() only supports | ||||
| # batchable methods. | # batchable methods. | ||||
| urlreq = util.urlreq | urlreq = util.urlreq | ||||
| HTTP_OK = 200 | HTTP_OK = 200 | ||||
| HGTYPE = 'application/mercurial-0.1' | HGTYPE = 'application/mercurial-0.1' | ||||
| HGTYPE2 = 'application/mercurial-0.2' | HGTYPE2 = 'application/mercurial-0.2' | ||||
| HGERRTYPE = 'application/hg-error' | HGERRTYPE = 'application/hg-error' | ||||
| class abstractserverproto(object): | |||||
| """abstract class that summarizes the protocol API | |||||
| Used as reference and documentation. | |||||
| """ | |||||
| def getargs(self, args): | |||||
| """return the value for arguments in <args> | |||||
| returns a list of values (same order as <args>)""" | |||||
| raise NotImplementedError() | |||||
| def getfile(self, fp): | |||||
| """write the whole content of a file into a file like object | |||||
| The file is in the form:: | |||||
| (<chunk-size>\n<chunk>)+0\n | |||||
| chunk size is the ascii version of the int. | |||||
| """ | |||||
| raise NotImplementedError() | |||||
| def redirect(self): | |||||
| """may setup interception for stdout and stderr | |||||
| See also the `restore` method.""" | |||||
| raise NotImplementedError() | |||||
| # If the `redirect` function does install interception, the `restore` | |||||
| # function MUST be defined. If interception is not used, this function | |||||
| # MUST NOT be defined. | |||||
| # | |||||
| # left commented here on purpose | |||||
| # | |||||
| #def restore(self): | |||||
| # """reinstall previous stdout and stderr and return intercepted stdout | |||||
| # """ | |||||
| # raise NotImplementedError() | |||||
| def decodevaluefromheaders(req, headerprefix): | def decodevaluefromheaders(req, headerprefix): | ||||
| """Decode a long value from multiple HTTP request headers. | """Decode a long value from multiple HTTP request headers. | ||||
| Returns the value as a bytes, not a str. | Returns the value as a bytes, not a str. | ||||
| """ | """ | ||||
| chunks = [] | chunks = [] | ||||
| i = 1 | i = 1 | ||||
| prefix = headerprefix.upper().replace(r'-', r'_') | prefix = headerprefix.upper().replace(r'-', r'_') | ||||
| while True: | while True: | ||||
| v = req.env.get(r'HTTP_%s_%d' % (prefix, i)) | v = req.env.get(r'HTTP_%s_%d' % (prefix, i)) | ||||
| if v is None: | if v is None: | ||||
| break | break | ||||
| chunks.append(pycompat.bytesurl(v)) | chunks.append(pycompat.bytesurl(v)) | ||||
| i += 1 | i += 1 | ||||
| return ''.join(chunks) | return ''.join(chunks) | ||||
| class webproto(wireproto.abstractserverproto): | class webproto(abstractserverproto): | ||||
| def __init__(self, req, ui): | def __init__(self, req, ui): | ||||
| self.req = req | self.req = req | ||||
| self.response = '' | self.response = '' | ||||
| self.ui = ui | self.ui = ui | ||||
| self.name = 'http' | self.name = 'http' | ||||
| def getargs(self, args): | def getargs(self, args): | ||||
| knownargs = self._args() | knownargs = self._args() | ||||
| req.respond(HTTP_OK, HGTYPE, body=rsp) | req.respond(HTTP_OK, HGTYPE, body=rsp) | ||||
| return [] | return [] | ||||
| elif isinstance(rsp, wireproto.ooberror): | elif isinstance(rsp, wireproto.ooberror): | ||||
| rsp = rsp.message | rsp = rsp.message | ||||
| req.respond(HTTP_OK, HGERRTYPE, body=rsp) | req.respond(HTTP_OK, HGERRTYPE, body=rsp) | ||||
| return [] | return [] | ||||
| raise error.ProgrammingError('hgweb.protocol internal failure', rsp) | raise error.ProgrammingError('hgweb.protocol internal failure', rsp) | ||||
| class sshserver(wireproto.abstractserverproto): | class sshserver(abstractserverproto): | ||||
| def __init__(self, ui, repo): | def __init__(self, ui, repo): | ||||
| self.ui = ui | self.ui = ui | ||||
| self.repo = repo | self.repo = repo | ||||
| self.lock = None | self.lock = None | ||||
| self.fin = ui.fin | self.fin = ui.fin | ||||
| self.fout = ui.fout | self.fout = ui.fout | ||||
| self.name = 'ssh' | self.name = 'ssh' | ||||