Esempio n. 1
0
    def __init__(self, db=None, console=None, **kwa):
        """

        """
        super(Consoler, self).__init__(**kwa)
        self.db = db if db is not None else basing.Baser()
        self.console = console if console is not None else serialing.Console()
Esempio n. 2
0
def test_echo_console():
    """
    Test EchoConsoleDoer class

    Must run in WindIDE with Debug I/O configured as external console
    """
    port = os.ctermid()  # default to console

    try:  # check to see if running in external console
        fd = os.open(port, os.O_NONBLOCK | os.O_RDWR | os.O_NOCTTY)
    except OSError as ex:
        # maybe complain here
        return  # not in external console
    else:
        os.close(fd)  #  cleanup

    tock = 0.03125
    ticks = 16
    limit = 0.0
    # limit = ticks *  tock
    doist = doing.Doist(tock=tock, real=True, limit=limit)
    assert doist.tyme == 0.0  # on next cycle
    assert doist.tock == tock == 0.03125
    assert doist.real == True
    assert doist.limit == 0.0
    # assert doist.limit == limit == 0.5
    assert doist.doers == []

    console = serialing.Console()
    echoer = serialing.EchoConsoleDoer(console=console)

    doers = [echoer]
    doist.do(doers=doers)
    # assert doist.tyme == limit
    assert console.opened == False
Esempio n. 3
0
def test_console():
    """
    Tests Console class

    Must configure Debug I/O to use external console window.
    """
    console = serialing.Console()
    assert console.bs == 256
    assert console.fd == None
    assert not console.opened
    assert len(console.rxbs) == 0

    result = console.reopen()
    if not result:  # only works on external console window in wingide
        return

    assert result
    assert console.opened
    assert console.fd
    assert os.isatty(console.fd)

    cout = b"Enter 'hello' and hit return: "
    console.put(cout)
    cin = b''
    while not cin:
        cin = console.get()

    console.put(b"You typed: " + cin + b'\n')
    assert cin == b'hello'
    assert len(console.rxbs) == 0

    console.close()

    # test small buffer stiches together full line
    result = console.reopen()
    if not result:  # only works on external console window in wingide
        return

    assert result
    assert console.opened
    assert console.fd
    assert os.isatty(console.fd)

    cout = b"Enter 'the lazy fox' and hit return: "
    console.put(cout)
    cin = b''
    while not cin:
        cin = console.get(bs=8)

    console.put(b"You typed: " + cin + b'\n')
    assert len(cin) > 8
    assert cin == b'the lazy fox'
    assert len(console.rxbs) == 0
    console.close()
    """End Test"""
Esempio n. 4
0
def test_console_doer():
    """
    Test ConsoleDoer class

    Must run in WindIDE with Debug I/O configured as external console
    """
    tock = 0.03125
    ticks = 8
    limit = tock * ticks
    doist = doing.Doist(tock=tock, real=True, limit=limit)
    assert doist.tyme == 0.0  # on next cycle
    assert doist.tock == tock == 0.03125
    assert doist.real == True
    assert doist.limit == limit
    assert doist.doers == []

    console = serialing.Console()
    doer = serialing.ConsoleDoer(console=console)

    doers = [doer]
    doist.do(doers=doers)
    assert doist.tyme == limit
    assert console.opened == False
Esempio n. 5
0
    def do(self, tymth=None, tock=0.0, **opts):
        """
        Generator method to run this doer
        Calling this method returns generator
        """
        try:
            # enter context
            self.wind(tymth)  # change tymist and dependencies
            self.tock = tock

            # recur context
            tyme = (yield self.tock)  # yields tock then waits

            while not self.client.connected:
                logger.info("%s:\n waiting for connection to remote %s.\n\n",
                            self.hab.pre, self.client.ha)
                tyme = (yield self.tock)

            while not self.peerClient.connected:
                logger.info("%s:\n waiting for connection to remote %s.\n\n",
                            self.hab.pre, self.peerClient.ha)
                tyme = (yield self.tock)

            logger.info("%s:\n connected to %s.\n\n", self.hab.pre, self.client.ha)

            self.sendOwnInception()  # Inception Event
            tyme = (yield self.tock)

            msg = self.issuer.ianchor
            # send to connected remote
            self.client.tx(msg)
            logger.info("%s: %s sent event:\n%s\n\n", self.hab.name, self.hab.pre, bytes(msg))
            tyme = (yield self.tock)

            tevt = self.issuer.incept
            self.client.tx(tevt)
            logger.info("%s: %s sent event:\n%s\n\n", self.hab.name, self.hab.pre, bytes(tevt))
            tyme = (yield self.tock)

            msg = self.hab.interact()  # Interaction Event
            self.client.tx(msg)  # send to connected remote
            logger.info("%s sent event:\n%s\n\n", self.hab.pre, bytes(msg))
            tyme = (yield self.tock)

            msg = self.hab.rotate()  # Rotation Event
            self.client.tx(msg)  # send to connected remote
            logger.info("%s sent event:\n%s\n\n", self.hab.pre, bytes(msg))
            tyme = (yield self.tock)

            msg = self.hab.rotate()  # Rotation Event
            self.client.tx(msg)  # send to connected remote
            logger.info("%s sent event:\n%s\n\n", self.hab.pre, bytes(msg))
            tyme = (yield self.tock)

            now = helping.nowIso8601()
            jsonSchema = scheming.JSONSchema(resolver=scheming.jsonSchemaCache)
            ref = scheming.jsonSchemaCache.resolve("EeCCZi1R5xHUlhsyQNm_7NrUQTEKZH5P9vBomnc9AihY")
            schemer = scheming.Schemer(raw=ref)

            # Build the credential subject and then the Credentialer for the full credential
            credSubject = dict(
                id=self.recipientIdentifier,  # this needs to be generated from a KEL
                lei=self.lei
            )

            creder = proving.credential(issuer=self.hab.pre,
                                        schema=schemer.said,
                                        subject=credSubject,
                                        issuance=now,
                                        regk=self.issuer.regk,
                                        typ=jsonSchema)

            msg = self.hab.endorse(serder=creder)

            tevt, kevt = self.issuer.issue(vcdig=creder.said)
            self.client.tx(kevt)  # send to connected remote
            logger.info("%s sent event:\n%s\n\n", self.hab.pre, bytes(kevt))
            tyme = (yield self.tock)

            self.client.tx(tevt)  # send to connected remote
            logger.info("%s sent event:\n%s\n\n", self.hab.pre, bytes(tevt))
            tyme = (yield self.tock)

            pl = dict(
                vc=[handling.envelope(msg, typ=jsonSchema)]
            )


            cloner = self.hab.db.clonePreIter(pre=self.hab.pre, fn=0)  # create iterator at 0
            msgs = bytearray()  # outgoing messages
            for msg in cloner:
                msgs.extend(msg)

            # send to connected peer remote
            self.peerClient.tx(msgs)
            logger.info("%s: %s sent event:\n%s\n\n", self.hab.name, self.hab.pre, bytes(msgs))
            tyme = (yield self.tock)

            excSrdr = exchanging.exchange(route="/credential/issue", payload=pl)
            excMsg = self.hab.sanction(excSrdr)

            self.peerClient.tx(excMsg)
            logger.info("%s: %s sent event:\n%s\n\n", self.hab.name, self.hab.pre, bytes(excMsg))
            tyme = (yield self.tock)

            logger.info("%s:\n\n\n Sent Verifiable Credential for LEI: %s to %s.\n\n",
                        self.hab.pre, self.lei, self.recipientIdentifier)

            console = serialing.Console()
            console.reopen()
            while console.get().decode('utf-8') != "r":
                (yield self.tock)

            tevt, kevt = self.issuer.revoke(vcdig=creder.said)
            logger.info("%s:\n\n\n Revoked Verifiable Credential for LEI: %s.\n\n",
                        self.hab.pre, self.lei)
            (yield self.tock)

            self.client.tx(kevt)  # send to connected remote
            logger.info("%s sent event:\n%s\n\n", self.hab.pre, bytes(kevt))
            (yield self.tock)

            self.client.tx(tevt)  # send to connected remote
            logger.info("%s sent event:\n%s\n\n", self.hab.pre, bytes(tevt))
            (yield self.tock)

        except GeneratorExit:  # close context, forced exit due to .close
            pass

        except Exception:  # abort context, forced exit due to uncaught exception
            raise

        finally:  # exit context,  unforced exit due to normal exit of try
            pass

        return True  # return value of yield from, or yield ex.value of StopIteration