D4468: wireprotov2server: use our CBOR encoder

2018-09-05 Thread indygreg (Gregory Szorc)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG660879e49b46: wireprotov2server: use our CBOR encoder 
(authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4468?vs=10765=10785

REVISION DETAIL
  https://phab.mercurial-scm.org/D4468

AFFECTED FILES
  mercurial/wireprotov2server.py
  tests/test-http-api-httpv2.t
  tests/test-wireproto-command-capabilities.t
  tests/test-wireproto-command-listkeys.t

CHANGE DETAILS

diff --git a/tests/test-wireproto-command-listkeys.t 
b/tests/test-wireproto-command-listkeys.t
--- a/tests/test-wireproto-command-listkeys.t
+++ b/tests/test-wireproto-command-listkeys.t
@@ -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
diff --git a/tests/test-wireproto-command-capabilities.t 
b/tests/test-wireproto-command-capabilities.t
--- a/tests/test-wireproto-command-capabilities.t
+++ b/tests/test-wireproto-command-capabilities.t
@@ -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/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/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
diff --git a/tests/test-http-api-httpv2.t b/tests/test-http-api-httpv2.t
--- a/tests/test-http-api-httpv2.t
+++ b/tests/test-http-api-httpv2.t
@@ -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
diff --git a/mercurial/wireprotov2server.py b/mercurial/wireprotov2server.py
--- a/mercurial/wireprotov2server.py
+++ b/mercurial/wireprotov2server.py
@@ -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)



To: indygreg, #hg-reviewers, pulkit
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4468: wireprotov2server: use our CBOR encoder

2018-09-04 Thread indygreg (Gregory Szorc)
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4468

AFFECTED FILES
  mercurial/wireprotov2server.py
  tests/test-http-api-httpv2.t
  tests/test-wireproto-command-capabilities.t
  tests/test-wireproto-command-listkeys.t

CHANGE DETAILS

diff --git a/tests/test-wireproto-command-listkeys.t 
b/tests/test-wireproto-command-listkeys.t
--- a/tests/test-wireproto-command-listkeys.t
+++ b/tests/test-wireproto-command-listkeys.t
@@ -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
diff --git a/tests/test-wireproto-command-capabilities.t 
b/tests/test-wireproto-command-capabilities.t
--- a/tests/test-wireproto-command-capabilities.t
+++ b/tests/test-wireproto-command-capabilities.t
@@ -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/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/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
diff --git a/tests/test-http-api-httpv2.t b/tests/test-http-api-httpv2.t
--- a/tests/test-http-api-httpv2.t
+++ b/tests/test-http-api-httpv2.t
@@ -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
diff --git a/mercurial/wireprotov2server.py b/mercurial/wireprotov2server.py
--- a/mercurial/wireprotov2server.py
+++ b/mercurial/wireprotov2server.py
@@ -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)



To: indygreg, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel