Ejemplo n.º 1
0
 def _printOn(self, printer):
     printer.call(u"print", [StrObject(u"[")])
     for i, obj in enumerate(self.objs):
         printer.call(u"quote", [obj])
         if i + 1 < len(self.objs):
             printer.call(u"print", [StrObject(u", ")])
     printer.call(u"print", [StrObject(u"]")])
Ejemplo n.º 2
0
 def printOn(self, printer):
     printer.call(u"print", [StrObject(u"[")])
     for i, obj in enumerate(self.objectSet.keys()):
         printer.call(u"quote", [obj])
         if i + 1 < len(self.objectSet):
             printer.call(u"print", [StrObject(u", ")])
     printer.call(u"print", [StrObject(u"].asSet()")])
Ejemplo n.º 3
0
 def printOn(self, out):
     out.call(u"print", [StrObject(u"Any[")])
     for i, subguard in enumerate(self.subguards):
         out.call(u"print", [subguard])
         if i < (len(self.subguards) - 1):
             out.call(u"print", [StrObject(u", ")])
     out.call(u"print", [StrObject(u"]")])
Ejemplo n.º 4
0
def connectCB(connect, status):
    status = intmask(status)
    stream = connect.c_handle

    try:
        vat, resolvers = ruv.unstashStream(stream)
        fountResolver, drainResolver = unwrapList(resolvers)
        assert isinstance(fountResolver, LocalResolver)
        assert isinstance(drainResolver, LocalResolver)

        with scopedVat(vat):
            if status >= 0:
                debug_print("Made connection!")
                fountResolver.resolve(StreamFount(stream, vat))
                drainResolver.resolve(StreamDrain(stream, vat))
            else:
                error = "Connection failed: " + ruv.formatError(status)
                debug_print(error)
                fountResolver.smash(StrObject(error.decode("utf-8")))
                drainResolver.smash(StrObject(error.decode("utf-8")))
                # Done with stream.
                ruv.closeAndFree(stream)
    except:
        if not we_are_translated():
            raise
Ejemplo n.º 5
0
 def uncall(self):
     return wrapList([
         StrObject(self._d if self._d else u""),
         StrObject(self._verb),
         wrapList(self._ps),
         wrapList(self._namedParams),
         self._g if self._g is not None else NullObject, self._b
     ])
Ejemplo n.º 6
0
 def printOn(self, printer):
     printer.call(u"print", [StrObject(u"[")])
     items = self.strategy.fetch_all(self)
     for i, obj in enumerate(items):
         printer.call(u"quote", [obj])
         if i + 1 < len(items):
             printer.call(u"print", [StrObject(u", ")])
     printer.call(u"print", [StrObject(u"].diverge()")])
Ejemplo n.º 7
0
    def testContainsTrue(self):
        """
        String containment tests have true positives.
        """

        haystack = StrObject(u"needle in a haystack")
        needle = StrObject(u"needle")
        result = haystack.call(u"contains", [needle])
        self.assertTrue(result.isTrue())
Ejemplo n.º 8
0
    def testContainsTrue(self):
        """
        String containment tests have true positives.
        """

        haystack = StrObject(u"needle in a haystack")
        needle = StrObject(u"needle")
        result = haystack.call(u"contains", [needle])
        self.assertTrue(result.isTrue())
Ejemplo n.º 9
0
    def testSplit(self):
        """
        Strings can be split.
        """

        s = StrObject(u"first second")
        result = s.call(u"split", [StrObject(u" ")])
        pieces = [obj._s for obj in unwrapList(result)]
        self.assertEqual(pieces, [u"first", u"second"])
Ejemplo n.º 10
0
    def testSplit(self):
        """
        Strings can be split.
        """

        s = StrObject(u"first second")
        result = s.call(u"split", [StrObject(u" ")])
        pieces = [obj._s for obj in unwrapList(result)]
        self.assertEqual(pieces, [u"first", u"second"])
Ejemplo n.º 11
0
def unsealException(specimen, ej):
    """
    Unseal a specimen.
    """

    if isinstance(specimen, SealedException):
        trail = ConstList([StrObject(s) for s in specimen.trail])
        return ConstList([specimen.value, trail])
    throw(ej, StrObject(u"Cannot unseal non-thrown object"))
Ejemplo n.º 12
0
def checkDeepFrozen(specimen, seen, ej, root):
    from typhon.objects.collections.lists import ConstList
    from typhon.objects.collections.maps import ConstMap
    from typhon.objects.data import StrObject
    from typhon.objects.equality import TraversalKey
    from typhon.objects.refs import Promise, isBroken
    key = TraversalKey(specimen)
    if key in seen:
        return
    seen[key] = None
    if isinstance(specimen, Promise):
        specimen = specimen.resolution()
    if specimen.auditedBy(deepFrozenStamp):
        return
    elif isBroken(specimen):
        checkDeepFrozen(specimen.optProblem(), seen, ej, root)
        return
    elif (specimen.auditedBy(selfless)
          and specimen.auditedBy(transparentStamp)):
        portrayal = specimen.call(u"_uncall", [])
        if not (isinstance(portrayal, ConstList) and portrayal.size() == 4):
            ej.call(u"run", [
                StrObject(u"can't happen: transparent object "
                          "gave bad portrayal")
            ])
            return
        checkDeepFrozen(portrayal.strategy.fetch(portrayal, 0), seen, ej, root)
        checkDeepFrozen(portrayal.strategy.fetch(portrayal, 1), seen, ej, root)
        args = portrayal.strategy.fetch(portrayal, 2)
        if not isinstance(args, ConstList):
            ej.call(u"run", [
                StrObject(u"can't happen: transparent object "
                          "gave bad portrayal")
            ])
            return
        for item in args.strategy.fetch_all(args):
            checkDeepFrozen(item, seen, ej, root)
        namedArgs = portrayal.strategy.fetch(portrayal, 3)
        if not isinstance(namedArgs, ConstMap):
            ej.call(u"run", [
                StrObject(u"can't happen: transparent object "
                          "gave bad portrayal")
            ])
            return
        for k, v in namedArgs.objectMap.iteritems():
            checkDeepFrozen(k, seen, ej, root)
            checkDeepFrozen(v, seen, ej, root)
    else:
        if specimen is root:
            ej.call(u"run",
                    [StrObject(root.toQuote() + u" is not DeepFrozen")])
        else:
            ej.call(u"run", [
                StrObject(root.toQuote() + u" is not DeepFrozen because " +
                          specimen.toQuote() + u"is not")
            ])
Ejemplo n.º 13
0
 def _uncall(self):
     from typhon.objects.collections.lists import wrapList
     from typhon.objects.collections.maps import EMPTY_MAP
     # [1,2,3].asSet().diverge() -> [[[1,2,3], "asSet"], "diverge"]
     rv = wrapList(self.objectSet.keys())
     return [
         wrapList([rv, StrObject(u"asSet"),
                   wrapList([]), EMPTY_MAP]),
         StrObject(u"diverge"),
         wrapList([]), EMPTY_MAP
     ]
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
 def _uncall(self):
     from typhon.objects.collections.maps import EMPTY_MAP
     from typhon.scopes.safe import theSlotBinder
     return [
         wrapList(
             [theSlotBinder,
              StrObject(u"run"),
              wrapList([self.guard])]),
         StrObject(u"run"),
         wrapList([self.slot, NullObject]), EMPTY_MAP
     ]
Ejemplo n.º 16
0
    def recv(self, atom, args):
        if atom is GETARITY_0:
            return IntObject(self.arity)

        if atom is GETDOCSTRING_0:
            if self.docstring is not None:
                return StrObject(self.docstring)
            return NullObject

        if atom is GETVERB_0:
            return StrObject(self.verb)

        raise Refused(self, atom, args)
Ejemplo n.º 17
0
 def _printOn(self, printer):
     printer.call(u"print", [StrObject(u"[")])
     i = 0
     for k, v in self.objectMap.iteritems():
         printer.call(u"quote", [k])
         printer.call(u"print", [StrObject(u" => ")])
         printer.call(u"quote", [v])
         if i + 1 < len(self.objectMap):
             printer.call(u"print", [StrObject(u", ")])
         i += 1
     printer.call(u"print", [StrObject(u"]")])
     if len(self.objectMap) == 0:
         printer.call(u"print", [StrObject(u".asMap()")])
Ejemplo n.º 18
0
 def _uncall(self):
     from typhon.objects.collections.maps import EMPTY_MAP
     return [
         wrapList(self.snapshot()),
         StrObject(u"diverge"),
         wrapList([]), EMPTY_MAP
     ]
Ejemplo n.º 19
0
 def _uncall(self):
     from typhon.objects.collections.lists import wrapList
     return [
         ConstMap(self.objectMap.copy()),
         StrObject(u"diverge"),
         wrapList([]), EMPTY_MAP
     ]
Ejemplo n.º 20
0
 def _uncall(self):
     span = wrapList([NullObject])
     return [
         self.nodeMaker,
         StrObject(u"run"),
         self.uncall().call(u"add", [span]), EMPTY_MAP
     ]
Ejemplo n.º 21
0
 def __init__(self, ub=None, newline=StrObject(u"\n"), context=None):
     self.ub = ub or UnicodeBuilder()
     self.newline = newline
     if context is None:
         self.context = {}
     else:
         self.context = context
Ejemplo n.º 22
0
def wrapNameList(names):
    # unroll_safe justified by inputs always being immutable. ~ C.
    # XXX monteMap()
    d = monteMap()
    for name in names:
        d[StrObject(name)] = None
    return d
Ejemplo n.º 23
0
 def uncall(self):
     return wrapList([
         self._target,
         StrObject(self._verb),
         wrapList(self._args),
         wrapList(self._namedArgs)
     ])
Ejemplo n.º 24
0
 def _uncall(self):
     from typhon.scopes.safe import theFinalSlotMaker
     from typhon.objects.collections.maps import EMPTY_MAP
     return [
         theFinalSlotMaker,
         StrObject(u"run"),
         wrapList([self._obj, self._guard, NullObject]), EMPTY_MAP
     ]
Ejemplo n.º 25
0
    def testMakeIterator(self):
        """
        Strings are iterable.
        """

        s = StrObject(u"cs")
        iterator = s.call(u"_makeIterator", [])
        with Ejector() as ej:
            result = iterator.call(u"next", [ej])
            objs = unwrapList(result)
            self.assertEqual(objs[0].getInt(), 0)
            self.assertEqual(objs[1]._c, u'c')
            result = iterator.call(u"next", [ej])
            objs = unwrapList(result)
            self.assertEqual(objs[0].getInt(), 1)
            self.assertEqual(objs[1]._c, u's')
            self.assertRaises(Ejecting, iterator.call, u"next", [ej])
Ejemplo n.º 26
0
 def sendAll(self, atom, args, namedArgs):
     if self.checkSlot():
         ref = self.resolutionBox.get()
         return send(ref, atom, args, namedArgs)
     else:
         return send(self.handler, HANDLESEND_3,
                     [StrObject(atom.verb),
                      ConstList(args), namedArgs], EMPTY_MAP)
Ejemplo n.º 27
0
    def testMakeIterator(self):
        """
        Strings are iterable.
        """

        s = StrObject(u"cs")
        iterator = s.call(u"_makeIterator", [])
        with Ejector() as ej:
            result = iterator.call(u"next", [ej])
            objs = unwrapList(result)
            self.assertEqual(objs[0].getInt(), 0)
            self.assertEqual(objs[1]._c, u'c')
            result = iterator.call(u"next", [ej])
            objs = unwrapList(result)
            self.assertEqual(objs[0].getInt(), 1)
            self.assertEqual(objs[1]._c, u's')
            self.assertRaises(Ejecting, iterator.call, u"next", [ej])
Ejemplo n.º 28
0
 def run(self, pname):
     for extension in [".ty", ".mast"]:
         path = pname.encode("utf-8") + extension
         for base in self.paths:
             fullpath = os.path.join(base, path)
             if os.path.exists(fullpath):
                 return StrObject(fullpath.decode("utf-8"))
     return NullObject
Ejemplo n.º 29
0
def unwrapList(o, ej=None):
    from typhon.objects.refs import resolution
    l = resolution(o)
    if isinstance(l, ConstList):
        return l.strategy.fetch_all(l)
    if isinstance(l, FlexList):
        return l.strategy.fetch_all(l)
    throw(ej, StrObject(u"Not a list!"))
Ejemplo n.º 30
0
    def withStringKey(self, k, v):
        """
        Add a key-value pair to this map.

        Like Monte m`self.with(k :Str, v)`.
        """

        return ConstMap(self._with(StrObject(k), v))
Ejemplo n.º 31
0
 def sendAllOnly(self, atom, args, namedArgs):
     if self.checkSlot():
         ref = self.resolutionBox.get()
         sendOnly(ref, atom, args, namedArgs)
     else:
         sendOnly(self.handler, HANDLESENDONLY_3, [StrObject(atom.verb),
                                                   wrapList(args),
                                                   namedArgs], EMPTY_MAP)
     return NullObject
Ejemplo n.º 32
0
def makeMirandaArgs():
    from typhon.objects.collections.maps import monteMap
    from typhon.objects.data import StrObject
    from typhon.objects.ejectors import theThrower

    # XXX monteMap()
    mirandaArgs = monteMap()
    mirandaArgs[StrObject(u"FAIL")] = theThrower
    return mirandaArgs
Ejemplo n.º 33
0
def unsealException(specimen, ej):
    """
    Unseal a specimen.
    """

    if isinstance(specimen, SealedException):
        ue = specimen.ue
        trail = wrapList([StrObject(s) for s in ue.formatTrail()])
        return wrapList([ue.getPayload(), trail])
    throwStr(ej, u"Cannot unseal non-thrown object")
Ejemplo n.º 34
0
 def testLastIndexOfFail(self):
     s = StrObject(u"needle")
     result = s.call(u"lastIndexOf", [StrObject(u"x")])
     self.assertEqual(result.getInt(), -1)
Ejemplo n.º 35
0
 def testHashInequal(self):
     a = StrObject(u"acerbic")
     b = StrObject(u"bitter")
     self.assertNotEqual(a.hash(), b.hash())
Ejemplo n.º 36
0
 def testJoin(self):
     s = StrObject(u"|")
     result = s.call(u"join",
             [ConstList([StrObject(u"5"), StrObject(u"42")])])
     self.assertEqual(result._s, u"5|42")
Ejemplo n.º 37
0
 def testTrimSpaces(self):
     s = StrObject(u"    ")
     result = s.call(u"trim", [])
     self.assertEqual(result._s, u"")
Ejemplo n.º 38
0
 def testSliceStart(self):
     s = StrObject(u"slice of lemon")
     result = s.call(u"slice", [IntObject(9)])
     self.assertEqual(result._s, u"lemon")
Ejemplo n.º 39
0
 def testTrimWord(self):
     s = StrObject(u"  testing  ")
     result = s.call(u"trim", [])
     self.assertEqual(result._s, u"testing")
Ejemplo n.º 40
0
 def testHashEqual(self):
     a = StrObject(u"acidic")
     b = StrObject(u"acidic")
     self.assertEqual(a.hash(), b.hash())
Ejemplo n.º 41
0
 def testSliceStartStop(self):
     s = StrObject(u"the lime in the coconut")
     result = s.call(u"slice", [IntObject(4), IntObject(8)])
     self.assertEqual(result._s, u"lime")
Ejemplo n.º 42
0
 def testToLowerCaseUnicode(self):
     s = StrObject(u"Α And Ω")
     result = s.call(u"toLowerCase", [])
     self.assertEqual(result._s, u"α and ω")
Ejemplo n.º 43
0
 def testToUpperCase(self):
     s = StrObject(u"lower")
     result = s.call(u"toUpperCase", [])
     self.assertEqual(result._s, u"LOWER")
Ejemplo n.º 44
0
 def testIndexOf(self):
     s = StrObject(u"needle")
     result = s.call(u"indexOf", [StrObject(u"e")])
     self.assertEqual(result.getInt(), 1)
Ejemplo n.º 45
0
 def testGet(self):
     s = StrObject(u"index")
     result = s.call(u"get", [IntObject(2)])
     self.assertEqual(result._c, u'd')
Ejemplo n.º 46
0
 def testToUpperCaseUnicode(self):
     s = StrObject(u"¡Holá!")
     result = s.call(u"toUpperCase", [])
     self.assertEqual(result._s, u"¡HOLÁ!")