How to use the foolscap.referenceable.SturdyRef function in foolscap

To help you get started, we’ve selected a few foolscap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github warner / foolscap / src / foolscap / pb.py View on Github external
        @return: the URL which points to this object. This URL can be passed
        to Tub.getReference() in any Tub on any host which can reach this
        one.
        """

        if not self.locationHints:
            raise NoLocationError("you must setLocation() before "
                                  "you can registerReference()")
        oldfurl = None
        if furlFile:
            try:
                oldfurl = open(furlFile, "r").read().strip()
            except EnvironmentError:
                pass
        if oldfurl:
            sr = SturdyRef(oldfurl)
            if name is None:
                name = sr.name
            if self.tubID != sr.tubID:
                raise WrongTubIdError("I cannot keep using the old FURL from %s"
                                      " because it does not have the same"
                                      " TubID as I do (%s)" %
                                      (furlFile, self.tubID))
            if name != sr.name:
                raise WrongNameError("I cannot keep using the old FURL from %s"
                                     " because you called registerReference"
                                     " with a new name (%s)" %
                                     (furlFile, name))
        name = self._assignName(ref, name)
        assert name
        if ref not in self.strongReferences:
            self.strongReferences.append(ref)
github warner / foolscap / src / foolscap / pb.py View on Github external
def unregisterReference(self, ref):
        name = self.referenceToName[ref]
        url = self.buildURL(name)
        sturdy = SturdyRef(url)
        name = sturdy.name
        del self.nameToReference[name]
        del self.referenceToName[ref]
        if ref in self.strongReferences:
            self.strongReferences.remove(ref)
        self.revokeReference(ref)
github warner / foolscap / src / foolscap / pb.py View on Github external
def getReferenceForURL(self, url):
        # TODO: who should this be used by?
        sturdy = SturdyRef(url)
        assert sturdy.tubID == self.tubID
        return self.getReferenceForName(sturdy.name)
github warner / foolscap / foolscap / api.py View on Github external
from foolscap.copyable import registerCopier, registerRemoteCopyFactory
from foolscap.ipb import DeadReferenceError
from foolscap.tokens import BananaError
from foolscap.schema import StringConstraint, IntegerConstraint, \
    ListOf, TupleOf, SetOf, DictOf, ChoiceOf, Any
from foolscap.storage import serialize, unserialize
from foolscap.tokens import Violation, RemoteException
from foolscap.eventual import eventually, fireEventually, flushEventualQueue
from foolscap.logging import app_versions

# hush pyflakes
_unused = [
    __version__,
    Tub,
    RemoteInterface,
    Referenceable, SturdyRef,
    Copyable, RemoteCopy, registerRemoteCopy,
    registerCopier, registerRemoteCopyFactory,
    DeadReferenceError,
    BananaError,
    StringConstraint, IntegerConstraint,
    ListOf, TupleOf, SetOf, DictOf, ChoiceOf, Any,
    serialize, unserialize,
    Violation, RemoteException,
    eventually, fireEventually, flushEventualQueue,
    app_versions,
    ]
del _unused
github warner / foolscap / src / foolscap / pb.py View on Github external
def getConnectionInfoForFURL(self, furl):
        try:
            tubref = SturdyRef(furl).getTubRef()
        except (ValueError, BadFURLError):
            return None # unparseable FURL
        return self._getConnectionInfoForTubRef(tubref)
github warner / foolscap / foolscap / deprecated.py View on Github external
def __init__(self, *args, **kwargs):
        if self.__class__ is _DeprecatedReferenceable:
            # this occurs upon instantiation of Referenceable(). Subclasses
            # do not get a warning here; they were noted at subclassing time.
            warnings.warn("Importing class Referenceable directly from "
                          "'foolscap' is deprecated since Foolscap 0.4.3. "
                          "Please import foolscap.api.Referenceable instead",
                          DeprecationWarning, 2)
        referenceable.Referenceable.__init__(self, *args, **kwargs)

Referenceable = _DeprecatedReferenceable

# Some symbols are too hard to wrap: SturdyRef (being a Copyable), Copyable
# itself. Leave them alone, and assume that users will see the warnings for
# Tub and Referenceable and the more common symols.
SturdyRef = referenceable.SturdyRef

from foolscap import copyable
Copyable = copyable.Copyable
RemoteCopy = copyable.RemoteCopy
registerRemoteCopy = _wrap_function(copyable.registerRemoteCopy,
                                    "registerRemoteCopy")
registerCopier = _wrap_function(copyable.registerCopier,
                                "registerCopier")
registerRemoteCopyFactory = _wrap_function(copyable.registerRemoteCopyFactory,
                                           "registerRemoteCopyFactory")

import foolscap.ipb
DeadReferenceError = _wrap_class(foolscap.ipb.DeadReferenceError, "DeadReferenceError")
import foolscap.tokens
BananaError = _wrap_class(foolscap.tokens.BananaError, "BananaError")
import foolscap.schema