changeset 39448:660879e49b46

wireprotov2server: use our CBOR encoder Again, test output changed slightly because of map key ordering differences. This shouldn't matter. I could have called oncommandresponsereadygen() with the raw output from the stream encoder. However, this changed test output further. I left a TODO to follow up on that later. Differential Revision: https://phab.mercurial-scm.org/D4468
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 28 Aug 2018 18:12:04 -0700
parents 5f4a9ada5ab5
children e5eb67dea6e8
files mercurial/wireprotov2server.py tests/test-http-api-httpv2.t tests/test-wireproto-command-capabilities.t tests/test-wireproto-command-listkeys.t
diffstat 4 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/wireprotov2server.py	Tue Aug 28 18:05:48 2018 -0700
+++ b/mercurial/wireprotov2server.py	Tue Aug 28 18:12:04 2018 -0700
@@ -9,9 +9,6 @@
 import contextlib
 
 from .i18n import _
-from .thirdparty import (
-    cbor,
-)
 from . import (
     encoding,
     error,
@@ -22,6 +19,7 @@
     wireprototypes,
 )
 from .utils import (
+    cborutil,
     interfaceutil,
 )
 
@@ -302,8 +300,11 @@
     res.status = b'200 OK'
     res.headers[b'Content-Type'] = FRAMINGTYPE
 
+    # TODO consider adding a type to represent an iterable of values to
+    # be CBOR encoded.
     if isinstance(rsp, wireprototypes.cborresponse):
-        encoded = cbor.dumps(rsp.value, canonical=True)
+        # TODO consider calling oncommandresponsereadygen().
+        encoded = b''.join(cborutil.streamencode(rsp.value))
         action, meta = reactor.oncommandresponseready(outstream,
                                                       command['requestid'],
                                                       encoded)
--- a/tests/test-http-api-httpv2.t	Tue Aug 28 18:05:48 2018 -0700
+++ b/tests/test-http-api-httpv2.t	Tue Aug 28 18:12:04 2018 -0700
@@ -517,7 +517,7 @@
   s>     Transfer-Encoding: chunked\r\n
   s>     \r\n
   s>     33\r\n
-  s>     +\x00\x00\x03\x00\x02\x012\xa1FstatusBok\xa3Fphases@Ibookmarks@Jnamespaces@
+  s>     +\x00\x00\x03\x00\x02\x012\xa1FstatusBok\xa3Ibookmarks@Jnamespaces@Fphases@
   s>     \r\n
   s>     14\r\n
   s>     \x0c\x00\x00\x01\x00\x02\x002\xa1FstatusBok\xa0
--- a/tests/test-wireproto-command-capabilities.t	Tue Aug 28 18:05:48 2018 -0700
+++ b/tests/test-wireproto-command-capabilities.t	Tue Aug 28 18:12:04 2018 -0700
@@ -335,7 +335,7 @@
   s>     \r\n
   s>     1d7\r\n
   s>     \xcf\x01\x00\x01\x00\x02\x012
-  s>     \xa1FstatusBok\xa4Hcommands\xa7Eheads\xa2Dargs\xa1Jpubliconly\xf4Kpermissions\x81DpullEknown\xa2Dargs\xa1Enodes\x81HdeadbeefKpermissions\x81DpullFlookup\xa2Dargs\xa1CkeyCfooKpermissions\x81DpullGpushkey\xa2Dargs\xa4CkeyCkeyCnewCnewColdColdInamespaceBnsKpermissions\x81DpushHlistkeys\xa2Dargs\xa1InamespaceBnsKpermissions\x81DpullIbranchmap\xa2Dargs\xa0Kpermissions\x81DpullLcapabilities\xa2Dargs\xa0Kpermissions\x81DpullKcompression\x81\xa1DnameDzlibNrawrepoformats\x82LgeneraldeltaHrevlogv1Qframingmediatypes\x81X&application/mercurial-exp-framing-0005
+  s>     \xa1FstatusBok\xa4Hcommands\xa7Ibranchmap\xa2Dargs\xa0Kpermissions\x81DpullLcapabilities\xa2Dargs\xa0Kpermissions\x81DpullEheads\xa2Dargs\xa1Jpubliconly\xf4Kpermissions\x81DpullEknown\xa2Dargs\xa1Enodes\x81HdeadbeefKpermissions\x81DpullHlistkeys\xa2Dargs\xa1InamespaceBnsKpermissions\x81DpullFlookup\xa2Dargs\xa1CkeyCfooKpermissions\x81DpullGpushkey\xa2Dargs\xa4CkeyCkeyInamespaceBnsCnewCnewColdColdKpermissions\x81DpushKcompression\x81\xa1DnameDzlibQframingmediatypes\x81X&application/mercurial-exp-framing-0005Nrawrepoformats\x82LgeneraldeltaHrevlogv1
   s>     \r\n
   received frame(size=463; request=1; stream=2; streamflags=stream-begin; type=command-response; flags=eos)
   s>     0\r\n
--- a/tests/test-wireproto-command-listkeys.t	Tue Aug 28 18:05:48 2018 -0700
+++ b/tests/test-wireproto-command-listkeys.t	Tue Aug 28 18:12:04 2018 -0700
@@ -49,7 +49,7 @@
   s>     \r\n
   s>     33\r\n
   s>     +\x00\x00\x01\x00\x02\x012
-  s>     \xa1FstatusBok\xa3Fphases@Ibookmarks@Jnamespaces@
+  s>     \xa1FstatusBok\xa3Ibookmarks@Jnamespaces@Fphases@
   s>     \r\n
   received frame(size=43; request=1; stream=2; streamflags=stream-begin; type=command-response; flags=eos)
   s>     0\r\n
@@ -86,7 +86,7 @@
   s>     \r\n
   s>     50\r\n
   s>     H\x00\x00\x01\x00\x02\x012
-  s>     \xa1FstatusBok\xa2JpublishingDTrueX(be0ef73c17ade3fc89dc41701eb9fc3a91b58282A1
+  s>     \xa1FstatusBok\xa2X(be0ef73c17ade3fc89dc41701eb9fc3a91b58282A1JpublishingDTrue
   s>     \r\n
   received frame(size=72; request=1; stream=2; streamflags=stream-begin; type=command-response; flags=eos)
   s>     0\r\n