##// END OF EJS Templates
wireprotoframing: use our CBOR module...
Gregory Szorc -
r39477:36f487a3 default
parent child Browse files
Show More
@@ -17,7 +17,6 b' import struct'
17 from .i18n import _
17 from .i18n import _
18 from .thirdparty import (
18 from .thirdparty import (
19 attr,
19 attr,
20 cbor,
21 )
20 )
22 from . import (
21 from . import (
23 encoding,
22 encoding,
@@ -25,6 +24,7 b' from . import ('
25 util,
24 util,
26 )
25 )
27 from .utils import (
26 from .utils import (
27 cborutil,
28 stringutil,
28 stringutil,
29 )
29 )
30
30
@@ -217,8 +217,8 b' def makeframefromhumanstring(s):'
217 finalflags |= int(flag)
217 finalflags |= int(flag)
218
218
219 if payload.startswith(b'cbor:'):
219 if payload.startswith(b'cbor:'):
220 payload = cbor.dumps(stringutil.evalpythonliteral(payload[5:]),
220 payload = b''.join(cborutil.streamencode(
221 canonical=True)
221 stringutil.evalpythonliteral(payload[5:])))
222
222
223 else:
223 else:
224 payload = stringutil.unescapestr(payload)
224 payload = stringutil.unescapestr(payload)
@@ -289,7 +289,7 b' def createcommandframes(stream, requesti'
289 if args:
289 if args:
290 data[b'args'] = args
290 data[b'args'] = args
291
291
292 data = cbor.dumps(data, canonical=True)
292 data = b''.join(cborutil.streamencode(data))
293
293
294 offset = 0
294 offset = 0
295
295
@@ -347,7 +347,7 b' def createcommandresponseframesfrombytes'
347 Returns a generator of bytearrays.
347 Returns a generator of bytearrays.
348 """
348 """
349 # Automatically send the overall CBOR response map.
349 # Automatically send the overall CBOR response map.
350 overall = cbor.dumps({b'status': b'ok'}, canonical=True)
350 overall = b''.join(cborutil.streamencode({b'status': b'ok'}))
351 if len(overall) > maxframesize:
351 if len(overall) > maxframesize:
352 raise error.ProgrammingError('not yet implemented')
352 raise error.ProgrammingError('not yet implemented')
353
353
@@ -388,7 +388,7 b' def createcommandresponseframesfrombytes'
388
388
389 def createbytesresponseframesfromgen(stream, requestid, gen,
389 def createbytesresponseframesfromgen(stream, requestid, gen,
390 maxframesize=DEFAULT_MAX_FRAME_SIZE):
390 maxframesize=DEFAULT_MAX_FRAME_SIZE):
391 overall = cbor.dumps({b'status': b'ok'}, canonical=True)
391 overall = b''.join(cborutil.streamencode({b'status': b'ok'}))
392
392
393 yield stream.makeframe(requestid=requestid,
393 yield stream.makeframe(requestid=requestid,
394 typeid=FRAME_TYPE_COMMAND_RESPONSE,
394 typeid=FRAME_TYPE_COMMAND_RESPONSE,
@@ -429,7 +429,7 b' def createcommanderrorresponse(stream, r'
429 if args:
429 if args:
430 m[b'error'][b'args'] = args
430 m[b'error'][b'args'] = args
431
431
432 overall = cbor.dumps(m, canonical=True)
432 overall = b''.join(cborutil.streamencode(m))
433
433
434 yield stream.makeframe(requestid=requestid,
434 yield stream.makeframe(requestid=requestid,
435 typeid=FRAME_TYPE_COMMAND_RESPONSE,
435 typeid=FRAME_TYPE_COMMAND_RESPONSE,
@@ -440,10 +440,10 b' def createerrorframe(stream, requestid, '
440 # TODO properly handle frame size limits.
440 # TODO properly handle frame size limits.
441 assert len(msg) <= DEFAULT_MAX_FRAME_SIZE
441 assert len(msg) <= DEFAULT_MAX_FRAME_SIZE
442
442
443 payload = cbor.dumps({
443 payload = b''.join(cborutil.streamencode({
444 b'type': errtype,
444 b'type': errtype,
445 b'message': [{b'msg': msg}],
445 b'message': [{b'msg': msg}],
446 }, canonical=True)
446 }))
447
447
448 yield stream.makeframe(requestid=requestid,
448 yield stream.makeframe(requestid=requestid,
449 typeid=FRAME_TYPE_ERROR_RESPONSE,
449 typeid=FRAME_TYPE_ERROR_RESPONSE,
@@ -493,7 +493,7 b' def createtextoutputframe(stream, reques'
493
493
494 atomdicts.append(atom)
494 atomdicts.append(atom)
495
495
496 payload = cbor.dumps(atomdicts, canonical=True)
496 payload = b''.join(cborutil.streamencode(atomdicts))
497
497
498 if len(payload) > maxframesize:
498 if len(payload) > maxframesize:
499 raise ValueError('cannot encode data in a single frame')
499 raise ValueError('cannot encode data in a single frame')
@@ -784,7 +784,7 b' class serverreactor(object):'
784
784
785 # Decode the payloads as CBOR.
785 # Decode the payloads as CBOR.
786 entry['payload'].seek(0)
786 entry['payload'].seek(0)
787 request = cbor.load(entry['payload'])
787 request = cborutil.decodeall(entry['payload'].getvalue())[0]
788
788
789 if b'name' not in request:
789 if b'name' not in request:
790 self._state = 'errored'
790 self._state = 'errored'
@@ -1158,7 +1158,7 b' class clientreactor(object):'
1158 del self._activerequests[request.requestid]
1158 del self._activerequests[request.requestid]
1159
1159
1160 # The payload should be a CBOR map.
1160 # The payload should be a CBOR map.
1161 m = cbor.loads(frame.payload)
1161 m = cborutil.decodeall(frame.payload)[0]
1162
1162
1163 return 'error', {
1163 return 'error', {
1164 'request': request,
1164 'request': request,
@@ -406,7 +406,7 b' Command frames can be reflected via debu'
406 s> content-length: 47\r\n
406 s> content-length: 47\r\n
407 s> host: $LOCALIP:$HGPORT\r\n (glob)
407 s> host: $LOCALIP:$HGPORT\r\n (glob)
408 s> \r\n
408 s> \r\n
409 s> \'\x00\x00\x01\x00\x01\x01\x11\xa2Dargs\xa2CfooDval1Dbar1CvalDnameHcommand1
409 s> \'\x00\x00\x01\x00\x01\x01\x11\xa2Dargs\xa2Dbar1CvalCfooDval1DnameHcommand1
410 s> makefile('rb', None)
410 s> makefile('rb', None)
411 s> HTTP/1.1 200 OK\r\n
411 s> HTTP/1.1 200 OK\r\n
412 s> Server: testing stub value\r\n
412 s> Server: testing stub value\r\n
@@ -414,7 +414,7 b' Command frames can be reflected via debu'
414 s> Content-Type: text/plain\r\n
414 s> Content-Type: text/plain\r\n
415 s> Content-Length: 205\r\n
415 s> Content-Length: 205\r\n
416 s> \r\n
416 s> \r\n
417 s> received: 1 1 1 \xa2Dargs\xa2CfooDval1Dbar1CvalDnameHcommand1\n
417 s> received: 1 1 1 \xa2Dargs\xa2Dbar1CvalCfooDval1DnameHcommand1\n
418 s> ["runcommand", {"args": {"bar1": "val", "foo": "val1"}, "command": "command1", "data": null, "requestid": 1}]\n
418 s> ["runcommand", {"args": {"bar1": "val", "foo": "val1"}, "command": "command1", "data": null, "requestid": 1}]\n
419 s> received: <no frame>\n
419 s> received: <no frame>\n
420 s> {"action": "noop"}
420 s> {"action": "noop"}
@@ -38,7 +38,7 b' pushkey for a bookmark works'
38 s> host: $LOCALIP:$HGPORT\r\n (glob)
38 s> host: $LOCALIP:$HGPORT\r\n (glob)
39 s> user-agent: Mercurial debugwireproto\r\n
39 s> user-agent: Mercurial debugwireproto\r\n
40 s> \r\n
40 s> \r\n
41 s> a\x00\x00\x01\x00\x01\x01\x11\xa2Dargs\xa4CkeyA@CnewX(426bada5c67598ca65036d57d9e4b64b0c1ce7a0Cold@InamespaceIbookmarksDnameGpushkey
41 s> a\x00\x00\x01\x00\x01\x01\x11\xa2Dargs\xa4CkeyA@InamespaceIbookmarksCnewX(426bada5c67598ca65036d57d9e4b64b0c1ce7a0Cold@DnameGpushkey
42 s> makefile('rb', None)
42 s> makefile('rb', None)
43 s> HTTP/1.1 200 OK\r\n
43 s> HTTP/1.1 200 OK\r\n
44 s> Server: testing stub value\r\n
44 s> Server: testing stub value\r\n
General Comments 0
You need to be logged in to leave comments. Login now