Mercurial > public > mercurial-scm > hg
comparison mercurial/wireprototypes.py @ 37612:5e71dea79aae
wireproto: move value encoding functions to wireprototypes (API)
These functions should live in the same place. I plan to separate
client from server code in upcoming commits. wireprototypes is
where we are putting shared code like this.
Differential Revision: https://phab.mercurial-scm.org/D3257
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 11 Apr 2018 10:50:58 -0700 |
parents | 0b7475ea38cf |
children | 96d735601ca1 |
comparison
equal
deleted
inserted
replaced
37611:ae8730877371 | 37612:5e71dea79aae |
---|---|
3 # This software may be used and distributed according to the terms of the | 3 # This software may be used and distributed according to the terms of the |
4 # GNU General Public License version 2 or any later version. | 4 # GNU General Public License version 2 or any later version. |
5 | 5 |
6 from __future__ import absolute_import | 6 from __future__ import absolute_import |
7 | 7 |
8 from .node import ( | |
9 bin, | |
10 hex, | |
11 ) | |
8 from .thirdparty.zope import ( | 12 from .thirdparty.zope import ( |
9 interface as zi, | 13 interface as zi, |
10 ) | 14 ) |
11 | 15 |
12 # Names of the SSH protocol implementations. | 16 # Names of the SSH protocol implementations. |
100 class cborresponse(object): | 104 class cborresponse(object): |
101 """Encode the response value as CBOR.""" | 105 """Encode the response value as CBOR.""" |
102 def __init__(self, v): | 106 def __init__(self, v): |
103 self.value = v | 107 self.value = v |
104 | 108 |
109 # list of nodes encoding / decoding | |
110 def decodelist(l, sep=' '): | |
111 if l: | |
112 return [bin(v) for v in l.split(sep)] | |
113 return [] | |
114 | |
115 def encodelist(l, sep=' '): | |
116 try: | |
117 return sep.join(map(hex, l)) | |
118 except TypeError: | |
119 raise | |
120 | |
121 # batched call argument encoding | |
122 | |
123 def escapebatcharg(plain): | |
124 return (plain | |
125 .replace(':', ':c') | |
126 .replace(',', ':o') | |
127 .replace(';', ':s') | |
128 .replace('=', ':e')) | |
129 | |
130 def unescapebatcharg(escaped): | |
131 return (escaped | |
132 .replace(':e', '=') | |
133 .replace(':s', ';') | |
134 .replace(':o', ',') | |
135 .replace(':c', ':')) | |
136 | |
105 class baseprotocolhandler(zi.Interface): | 137 class baseprotocolhandler(zi.Interface): |
106 """Abstract base class for wire protocol handlers. | 138 """Abstract base class for wire protocol handlers. |
107 | 139 |
108 A wire protocol handler serves as an interface between protocol command | 140 A wire protocol handler serves as an interface between protocol command |
109 handlers and the wire protocol transport layer. Protocol handlers provide | 141 handlers and the wire protocol transport layer. Protocol handlers provide |