Ejemplo n.º 1
0
 def _reflectindexupdate(self):
     self._refreshindex()
     self._svfs.write(self._indexpath, cbor.dumps(self._indexdata))
Ejemplo n.º 2
0
 def testrange(self):
     for i in range(-70000, 70000, 10):
         self.assertEqual(b''.join(cborutil.streamencode(i)), cbor.dumps(i))
Ejemplo n.º 3
0
import unittest

from mercurial.thirdparty import (
    cbor, )
from mercurial import (
    ui as uimod,
    util,
    wireprotoframing as framing,
)
from mercurial.utils import (
    cborutil, )

ffs = framing.makeframefromhumanstring

OK = cbor.dumps({b'status': b'ok'})


def makereactor(deferoutput=False):
    ui = uimod.ui()
    return framing.serverreactor(ui, deferoutput=deferoutput)


def sendframes(reactor, gen):
    """Send a generator of frame bytearray to a reactor.

    Emits a generator of results from ``onframerecv()`` calls.
    """
    for frame in gen:
        header = framing.parseheader(frame)
        payload = frame[framing.FRAME_HEADER_SIZE:]
Ejemplo n.º 4
0
    def testinterleavedcommands(self):
        cbor1 = cbor.dumps(
            {
                b'name': b'command1',
                b'args': {
                    b'foo': b'bar',
                    b'key1': b'val',
                }
            },
            canonical=True)
        cbor3 = cbor.dumps(
            {
                b'name': b'command3',
                b'args': {
                    b'biz': b'baz',
                    b'key': b'val',
                },
            },
            canonical=True)

        results = list(
            sendframes(makereactor(), [
                ffs(b'1 1 stream-begin command-request new|more %s' %
                    cbor1[0:6]),
                ffs(b'3 1 0 command-request new|more %s' % cbor3[0:10]),
                ffs(b'1 1 0 command-request continuation|more %s' %
                    cbor1[6:9]),
                ffs(b'3 1 0 command-request continuation|more %s' %
                    cbor3[10:13]),
                ffs(b'3 1 0 command-request continuation %s' % cbor3[13:]),
                ffs(b'1 1 0 command-request continuation %s' % cbor1[9:]),
            ]))

        self.assertEqual([t[0] for t in results], [
            b'wantframe',
            b'wantframe',
            b'wantframe',
            b'wantframe',
            b'runcommand',
            b'runcommand',
        ])

        self.assertEqual(
            results[4][1], {
                b'requestid': 3,
                b'command': b'command3',
                b'args': {
                    b'biz': b'baz',
                    b'key': b'val'
                },
                b'redirect': None,
                b'data': None,
            })
        self.assertEqual(
            results[5][1], {
                b'requestid': 1,
                b'command': b'command1',
                b'args': {
                    b'foo': b'bar',
                    b'key1': b'val'
                },
                b'redirect': None,
                b'data': None,
            })
Ejemplo n.º 5
0
    def testrange(self):
        for i in range(-70000, 70000, 10):
            encoded = b''.join(cborutil.streamencode(i))

            self.assertEqual(encoded, cbor.dumps(i))
            self.assertEqual(cborutil.decodeall(encoded), [i])