Beispiel #1
0
 def getEnvironment(self):
     # XXX monteMap()
     d = monteMap()
     for key, value in os.environ.items():
         k = BytesObject(key)
         v = BytesObject(value)
         d[k] = v
     return d
Beispiel #2
0
    def recv(self, atom, args):
        if atom is FROMSTRING_1:
            return BytesObject("".join(
                [chr(ord(c)) for c in unwrapStr(args[0])]))

        if atom is FROMINTS_1:
            data = unwrapList(args[0])
            return BytesObject("".join([chr(unwrapInt(i)) for i in data]))

        raise Refused(self, atom, args)
Beispiel #3
0
    def succeed(self):
        # Clean up libuv stuff.
        ruv.fsClose(self.vat.uv_loop, self.fs, self.fd, ruv.fsDiscard)

        # Finally, resolve.
        buf = "".join(self.pieces)
        self.resolver.resolve(BytesObject(buf))
Beispiel #4
0
 def receive(self, data):
     from typhon.objects.collections.maps import EMPTY_MAP
     # Advance the file pointer.
     self.pos += len(data)
     self.vat.sendOnly(self.drain, RECEIVE_1, [BytesObject(data)],
                       EMPTY_MAP)
     self.queueRead()
Beispiel #5
0
    def recv(self, atom, args):
        if atom is SEAL_1:
            message = unwrapBytes(args[0])
            nonce = rsodium.freshNonce()
            cipher = rsodium.boxSeal(message, nonce, self.publicKey,
                                     self.secretKey)
            return ConstList([BytesObject(cipher), BytesObject(nonce)])

        if atom is UNSEAL_2:
            cipher = unwrapBytes(args[0])
            nonce = unwrapBytes(args[1])
            try:
                message = rsodium.boxUnseal(cipher, nonce, self.publicKey,
                                            self.secretKey)
            except rsodium.SodiumError:
                raise userError(u"unseal/2: Couldn't open this box")
            return BytesObject(message)

        raise Refused(self, atom, args)
Beispiel #6
0
    def recv(self, atom, args):
        if atom is ASBYTES_0:
            return BytesObject(self.publicKey)

        if atom is PAIRWITH_1:
            secret = args[0]
            if not isinstance(secret, SecretKey):
                raise WrongType(u"Not a secret key!")
            return KeyPair(self.publicKey, secret.secretKey)

        raise Refused(self, atom, args)
Beispiel #7
0
    def recv(self, atom, args):
        if atom is GETADDRESS_0:
            return BytesObject(self.addr)

        if atom is GETFAMILY_0:
            return StrObject(self.family)

        if atom is GETSOCKETTYPE_0:
            return StrObject(self.socktype)

        raise Refused(self, atom, args)
Beispiel #8
0
 def flush(self):
     # We are running in vat scope.
     for i, buf in enumerate(self.bufs):
         # During this loop, the drain might pause us, which we'll respect.
         if self.pauses or self._drain is None:
             # Keep any non-flushed bufs.
             self.bufs = self.bufs[i:]
             break
         rv = BytesObject(buf)
         self._drain.call(u"receive", [rv])
     else:
         # We wrote out everything successfully!
         self.bufs = []
Beispiel #9
0
    def recv(self, atom, args):
        if atom is GETARGUMENTS_0:
            return ConstList([BytesObject(arg) for arg in self.argv])

        if atom is GETENVIRONMENT_0:
            # XXX monteMap()
            d = monteMap()
            for key, value in self.env.items():
                k = BytesObject(key)
                v = BytesObject(value)
                d[k] = v
            return ConstMap(d)

        if atom is GETPID_0:
            return IntObject(self.pid)

        if atom is INTERRUPT_0:
            os.kill(self.pid, signal.SIGINT)
            return NullObject

        if atom is WAIT_0:
            return self.makeWaiter()

        raise Refused(self, atom, args)
Beispiel #10
0
    def recv(self, atom, args):
        if atom is ASBYTES_0:
            # XXX should figure this out
            log.log(["sodium"], u"asBytes/0: Revealing secret key")
            return BytesObject(self.secretKey)

        if atom is PAIRWITH_1:
            public = args[0]
            if not isinstance(public, PublicKey):
                raise WrongType(u"Not a public key!")
            return KeyPair(public.publicKey, self.secretKey)

        if atom is PUBLICKEY_0:
            publicKey = rsodium.regenerateKey(self.secretKey)
            return PublicKey(publicKey)

        raise Refused(self, atom, args)
Beispiel #11
0
 def deliver(self, data):
     from typhon.objects.collections.maps import EMPTY_MAP
     r, sink = self._nextSink()
     p = self._vat.send(sink, RUN_1, [BytesObject(data)], EMPTY_MAP)
     r.resolve(p)
Beispiel #12
0
 def testFromBigBytes(self):
     bs = BytesObject("1180591620717411303424")
     bi = rbigint.fromint(128).pow(rbigint.fromint(10))
     result = theMakeInt.call(u"fromBytes", [bs])
     self.assertEqual(result.bi, bi)
Beispiel #13
0
 def test_fromBytesRadix(self):
     makeInt = MakeInt()
     result = makeInt.call(u"fromBytes", [BytesObject("42"), IntObject(16)])
     self.assertEqual(result.getInt(), 66)
Beispiel #14
0
 def seal(self, message):
     nonce = rsodium.freshNonce()
     cipher = rsodium.boxSeal(message, nonce, self.publicKey,
                              self.secretKey)
     return [BytesObject(cipher), BytesObject(nonce)]
Beispiel #15
0
 def test_fromBytes(self):
     result = theMakeInt.call(u"fromBytes", [BytesObject("42")])
     self.assertEqual(result.getInt(), 42)
Beispiel #16
0
 def getArguments(self):
     return [BytesObject(arg) for arg in self.argv]
Beispiel #17
0
 def test_fromBytesRadix(self):
     withRadix = theMakeInt.call(u"withRadix", [IntObject(16)])
     result = withRadix.call(u"fromBytes", [BytesObject("42")])
     self.assertEqual(result.getInt(), 66)
Beispiel #18
0
def unboxUnconnectedRef(value):
    assert isinstance(value, UnconnectedRef), "Implementation detail"
    return value._problem


unboxedStrategies = [
    makeUnboxedListStrategy(cls, box, unbox, exemplar)
    for (cls, box, unbox, exemplar) in [
        # Chars.
        (CharObject, CharObject, unwrapChar, CharObject(u'▲')),
        # Small ints.
        (IntObject, IntObject, unwrapInt, IntObject(42)),
        # Unicode strings.
        (StrObject, StrObject, unwrapStr, StrObject(u"▲")),
        # Bytestrings.
        (BytesObject, BytesObject, unwrapBytes, BytesObject("M")),
        # _booleanFlow-generated lists of unconnected refs.
        (UnconnectedRef, UnconnectedRef, unboxUnconnectedRef,
         UnconnectedRef(StrObject(u"Implementation detail leaked"))),
    ]
]


@rstrategies.strategy(generalize=[NullListStrategy] + unboxedStrategies +
                      [GenericListStrategy])
class EmptyListStrategy(Strategy):
    """
    A list with no elements.
    """

    import_from_mixin(rstrategies.EmptyStrategy)