当前位置: 首页>>代码示例>>Python>>正文


Python errors.userError函数代码示例

本文整理汇总了Python中typhon.errors.userError函数的典型用法代码示例。如果您正苦于以下问题:Python userError函数的具体用法?Python userError怎么用?Python userError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了userError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setTarget

 def setTarget(self, newTarget):
     if self.isSwitchable:
        self._target = newTarget.resolutionRef()
        if self is self._target:
            raise userError(u"Ref loop")
     else:
         raise userError(u"No longer switchable")
开发者ID:washort,项目名称:typhon,代码行数:7,代码来源:refs.py

示例2: callAtom

    def callAtom(self, atom, arguments, namedArgsMap):
        """
        This method is used to reuse atoms without having to rebuild them.
        """
        # Promote the atom, on the basis that atoms are generally reused.
        atom = promote(atom)
        # Log the atom to the JIT log. Don't do this if the atom's not
        # promoted; it'll be slow.
        jit_debug(atom.repr)

        try:
            return self.recvNamed(atom, arguments, namedArgsMap)
        except Refused as r:
            addTrail(r, self, atom, arguments)
            raise
        except UserException as ue:
            addTrail(ue, self, atom, arguments)
            raise
        except MemoryError:
            ue = userError(u"Memory corruption or exhausted heap")
            addTrail(ue, self, atom, arguments)
            raise ue
        except StackOverflow:
            check_stack_overflow()
            ue = userError(u"Stack overflow")
            addTrail(ue, self, atom, arguments)
            raise ue
开发者ID:dckc,项目名称:typhon,代码行数:27,代码来源:root.py

示例3: auditDeepFrozen

def auditDeepFrozen(audition):
    from typhon.nodes import FinalPattern, Obj
    from typhon.objects.user import Audition
    from typhon.objects.printers import toString
    if not isinstance(audition, Audition):
        raise userError(u"not invoked with an Audition")
    ast = audition.ast
    if not isinstance(ast, Obj):
        raise userError(u"audition not created with an object expr")
    n = ast._n
    if isinstance(n, FinalPattern):
        objName = ast._n._n
    else:
        objName = None
    ss = ast._script.getStaticScope()
    namesUsed = ss.read + ss.set
    errors = []
    for name in namesUsed:
        if name == objName:
            continue
        guard = audition.getGuard(name)
        if not deepFrozenSupersetOf(guard):
            errors.append(u'"%s" in the lexical scope of %s does not have a '
                          u'guard implying DeepFrozen, but %s' %
                          (name, audition.fqn, toString(guard)))
    if len(errors) > 0:
        raise userError(u'\n'.join(errors))
开发者ID:markrwilliams,项目名称:typhon,代码行数:27,代码来源:auditors.py

示例4: recv

    def recv(self, atom, args):
        if atom is RUN_1:
            return IntObject(int(unwrapStr(args[0]).encode('utf-8')))

        if atom is RUN_2:
            inp = unwrapStr(args[0])
            radix = unwrapInt(args[1])
            try:
                v = int(inp.encode("utf-8"), radix)
            except ValueError:
                raise userError(u"Invalid literal for base %d: %s" % (
                        radix, inp))
            return IntObject(v)

        if atom is FROMBYTES_1:
            return IntObject(int(unwrapBytes(args[0])))

        if atom is FROMBYTES_2:
            bs = unwrapBytes(args[0])
            radix = unwrapInt(args[1])
            try:
                v = int(bs, radix)
            except ValueError:
                raise userError(u"Invalid literal for base %d: %s" % (
                        radix, bytesToString(bs)))
            return IntObject(v)

        raise Refused(self, atom, args)
开发者ID:markrwilliams,项目名称:typhon,代码行数:28,代码来源:safe.py

示例5: recv

    def recv(self, atom, args):
        if atom is RUN_1:
            pname = unwrapStr(args[0])
            for extension in [".ty", ".mast"]:
                path = pname.encode("utf-8") + extension
                for base in self.paths:
                    try:
                        with open(os.path.join(base, path), "rb") as handle:
                            source = handle.read()
                            with self.recorder.context("Deserialization"):
                                return loadMASTBytes(source)
                    except IOError:
                        continue
            raise userError(u"Could not locate " + pname)

        if atom is RUN_2:
            scope = unwrapMap(args[1])
            d = {}
            for k, v in scope.items():
                s = unwrapStr(k)
                if not s.startswith("&&"):
                    raise userError(u"evalMonteFile scope map must be of the "
                                    "form '[\"&&name\" => binding]'")
                d[s[2:]] = scope[k]

            code = obtainModule(self.paths, unwrapStr(args[0]).encode("utf-8"),
                                self.recorder)
            return evaluateRaise([code], d)[0]
        raise Refused(self, atom, args)
开发者ID:markrwilliams,项目名称:typhon,代码行数:29,代码来源:boot.py

示例6: _slice

 def _slice(self, start, stop):
     if start < 0:
         raise userError(u"slice/1: Negative start")
     if stop < 0:
         raise userError(u"slice/2: Negative stop")
     stop = min(stop, len(self.objs))
     start = min(start, stop)
     return self.objs[start:stop]
开发者ID:monte-language,项目名称:typhon,代码行数:8,代码来源:lists.py

示例7: get

    def get(self, index):
        # Lookup by index.
        if index < 0:
            raise userError(u"get/1: Index %d cannot be negative" % index)

        try:
            return self.objs[index]
        except IndexError:
            raise userError(u"get/1: Index %d is out of bounds" % index)
开发者ID:dckc,项目名称:typhon,代码行数:9,代码来源:lists.py

示例8: takeTurn

    def takeTurn(self):
        from typhon.objects.exceptions import sealException
        from typhon.objects.refs import Promise, resolution

        with self._pendingLock:
            resolver, target, atom, args, namedArgs = self._pending.pop(0)

        # Set up our Miranda FAIL.
        if namedArgs.extractStringKey(u"FAIL", None) is None:
            if resolver is not None:
                FAIL = resolver.makeSmasher()
            else:
                from typhon.objects.ejectors import theThrower
                FAIL = theThrower
            namedArgs = namedArgs.withStringKey(u"FAIL", FAIL)

        # If the target is a promise, then we should send to it instead of
        # calling. Try to resolve it as much as possible first, though.
        target = resolution(target)

        # self.log(u"Taking turn: %s<-%s(%s) (resolver: %s)" %
        #          (target.toQuote(), atom.verb,
        #           u", ".join([arg.toQuote() for arg in args]),
        #           u"yes" if resolver is not None else u"no"))
        try:
            if isinstance(target, Promise):
                if resolver is None:
                    target.sendOnly(atom, args, namedArgs)
                else:
                    result = target.send(atom, args, namedArgs)
                    # The resolver may have already been invoked, so we'll use
                    # .resolveRace/1 instead of .resolve/1. ~ C.
                    resolver.resolveRace(result)
            else:
                result = target.callAtom(atom, args, namedArgs)
                if resolver is not None:
                    # Same logic as above.
                    resolver.resolveRace(result)
        except UserException as ue:
            if resolver is not None:
                resolver.smash(sealException(ue))
            else:
                self.log(u"Uncaught user exception while taking turn"
                         u" (and no resolver): %s" %
                         ue.formatError().decode("utf-8"),
                         tags=["serious"])
        except VatCheckpointed:
            self.log(u"Ran out of checkpoints while taking turn",
                     tags=["serious"])
            if resolver is not None:
                resolver.smash(sealException(userError(u"Vat ran out of checkpoints")))
        except Ejecting:
            self.log(u"Ejector tried to escape vat turn boundary",
                     tags=["serious"])
            if resolver is not None:
                resolver.smash(sealException(userError(u"Ejector tried to escape from vat")))
开发者ID:monte-language,项目名称:typhon,代码行数:56,代码来源:vats.py

示例9: _slice

 def _slice(self, start, stop):
     if start < 0:
         raise userError(u"slice/2: Negative start")
     if stop < 0:
         raise userError(u"slice/2: Negative stop")
     keys = self.objectSet.keys()[start:stop]
     rv = monteSet()
     for k in keys:
         rv[k] = None
     return rv
开发者ID:dckc,项目名称:typhon,代码行数:10,代码来源:sets.py

示例10: _slice

 def _slice(self, start, stop):
     if start < 0:
         raise userError(u"slice/1: Negative start")
     if stop < 0:
         raise userError(u"slice/1: Negative stop")
     items = self.objectMap.items()[start:stop]
     rv = monteMap()
     for k, v in items:
         rv[k] = v
     return rv
开发者ID:dckc,项目名称:typhon,代码行数:10,代码来源:maps.py

示例11: recv

    def recv(self, atom, args):
        from typhon.nodes import Noun, Method, Obj
        from typhon.objects.equality import optSame, EQUAL
        from typhon.objects.user import Audition

        if atom is _UNCALL_0:
            from typhon.objects.collections.maps import EMPTY_MAP

            return ConstList([subrangeGuardMaker, StrObject(u"get"), ConstList([self.superGuard]), EMPTY_MAP])

        if atom is AUDIT_1:
            audition = args[0]
            if not isinstance(audition, Audition):
                raise userError(u"not invoked with an Audition")
            ast = audition.ast
            if not isinstance(ast, Obj):
                raise userError(u"audition not created with an object expr")
            methods = ast._script._methods
            for m in methods:
                if isinstance(m, Method) and m._verb == u"coerce":
                    mguard = m._g
                    if isinstance(mguard, Noun):
                        rGSG = audition.getGuard(mguard.name)
                        if isinstance(rGSG, FinalSlotGuard):
                            rGSG0 = rGSG.valueGuard
                            if isinstance(rGSG0, SameGuard):
                                resultGuard = rGSG0.value

                                if optSame(resultGuard, self.superGuard) is EQUAL or (
                                    SUPERSETOF_1 in self.superGuard.respondingAtoms()
                                    and self.superGuard.call(u"supersetOf", [resultGuard]) is wrapBool(True)
                                ):
                                    return wrapBool(True)
                                raise userError(
                                    u"%s does not have a result guard implying "
                                    u"%s, but %s" % (audition.fqn, self.superGuard.toQuote(), resultGuard.toQuote())
                                )
                            raise userError(
                                u"%s does not have a determinable "
                                u"result guard, but <& %s> :%s" % (audition.fqn, mguard.name, rGSG.toQuote())
                            )
                    break
            return self
        if atom is PASSES_1:
            return wrapBool(args[0].auditedBy(self))
        if atom is COERCE_2:
            specimen, ej = args[0], args[1]
            if specimen.auditedBy(self):
                return specimen
            c = specimen.call(u"_conformTo", [self])
            if c.auditedBy(self):
                return c
            throw(ej, StrObject(u"%s does not conform to %s" % (specimen.toQuote(), self.toQuote())))

        raise Refused(self, atom, args)
开发者ID:markrwilliams,项目名称:typhon,代码行数:55,代码来源:guards.py

示例12: recv

    def recv(self, atom, args):
        if atom is GETCONTENTS_0:
            return self.open(openGetContentsCB, flags=os.O_RDONLY, mode=0000)

        if atom is SETCONTENTS_1:
            data = unwrapBytes(args[0])
            sibling = self.temporarySibling(".setContents")

            p, r = makePromise()
            vat = currentVat.get()
            uv_loop = vat.uv_loop
            fs = ruv.alloc_fs()

            path = sibling.asBytes()
            # Use CREAT | EXCL to cause a failure if the temporary file
            # already exists.
            flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
            sc = SetContents(vat, data, r, sibling, self)
            ruv.stashFS(fs, (vat, sc))
            ruv.fsOpen(uv_loop, fs, path, flags, 0777, openSetContentsCB)
            return p

        if atom is OPENFOUNT_0:
            return self.open(openFountCB, flags=os.O_RDONLY, mode=0000)

        if atom is OPENDRAIN_0:
            # Create the file if it doesn't yet exist, and truncate it if it
            # does. Trust the umask to be reasonable for now.
            flags = os.O_CREAT | os.O_WRONLY
            # XXX this behavior should be configurable via namedarg?
            flags |= os.O_TRUNC
            return self.open(openDrainCB, flags=flags, mode=0777)

        if atom is RENAME_1:
            fr = args[0]
            if not isinstance(fr, FileResource):
                raise userError(u"rename/1: Must be file resource")
            return self.rename(fr.asBytes())

        if atom is SIBLING_1:
            name = unwrapStr(args[0])
            if u'/' in name:
                raise userError(u"sibling/1: Illegal file name '%s'" % name)
            return self.sibling(name.encode("utf-8"))

        if atom is TEMPORARYSIBLING_0:
            return self.temporarySibling(".new")

        raise Refused(self, atom, args)
开发者ID:markrwilliams,项目名称:typhon,代码行数:49,代码来源:files.py

示例13: samenessFringe

def samenessFringe(original, path, fringe, sofar=None):
    """
    Walk an object graph, building up the fringe.

    Returns whether the graph is settled.
    """

    # Resolve the object.
    o = resolution(original)
    # Handle primitive cases first.
    if o in (NullObject, TrueObject, FalseObject):
        return True

    if (isinstance(o, CharObject) or isinstance(o, DoubleObject) or
        isinstance(o, IntObject) or isinstance(o, BigInt) or
        isinstance(o, StrObject) or isinstance(o, BytesObject) or
        isinstance(o, TraversalKey)):
        return True

    if isinstance(o, ConstMap) and o.empty():
        return True

    if sofar is None:
        sofar = {}
    elif o in sofar:
        return True

    if isinstance(o, ConstList):
        sofar[o] = None
        return listFringe(o, fringe, path, sofar)

    if selfless in o.auditorStamps():
        if transparentStamp in o.auditorStamps():
            sofar[o] = None
            return samenessFringe(o.call(u"_uncall", []), path, fringe, sofar)
        if semitransparentStamp in o.auditorStamps():
            sofar[o] = None
            p = o.call(u"_uncall", [])
            if not isinstance(p, SealedPortrayal):
                userError(u'Semitransparent portrayal was not a SealedPortrayal!')
            return samenessFringe(p, path, fringe, sofar)

    if isResolved(o):
        return True

    # Welp, it's unsettled.
    if fringe is not None:
        fringe.append(FringeNode(o, path))
    return False
开发者ID:monte-language,项目名称:typhon,代码行数:49,代码来源:equality.py

示例14: fromPublicBytes

 def fromPublicBytes(self, publicKey):
     expectedSize = intmask(rsodium.cryptoBoxPublickeybytes())
     if len(publicKey) != expectedSize:
         message = u"Expected key length of %d bytes, not %d" % (
             expectedSize, len(publicKey))
         raise userError(message)
     return PublicKey(publicKey)
开发者ID:dckc,项目名称:typhon,代码行数:7,代码来源:crypt.py

示例15: fromSecretBytes

 def fromSecretBytes(self, secretKey):
     expectedSize = intmask(rsodium.cryptoBoxSecretkeybytes())
     if len(secretKey) != expectedSize:
         message = u"Expected key length of %d bytes, not %d" % (
             expectedSize, len(secretKey))
         raise userError(message)
     return SecretKey(secretKey)
开发者ID:dckc,项目名称:typhon,代码行数:7,代码来源:crypt.py


注:本文中的typhon.errors.userError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。