# Path: src/foolscap/furl.py
# class BadFURLError(Exception):
#     pass


import os.path, weakref, binascii, re
import six
from warnings import warn
from zope.interface import implementer
from twisted.internet import (reactor, defer, protocol, error, interfaces,
                              endpoints)
from twisted.application import service
from twisted.python.failure import Failure
from twisted.python.deprecate import deprecated
from twisted.python.versions import Version
from foolscap import ipb, base32, negotiate, broker, eventual, storage
from foolscap import connection, util, info
from foolscap.connections import tcp
from foolscap.referenceable import SturdyRef
from .furl import BadFURLError
from foolscap.tokens import PBError, BananaError, WrongTubIdError, \
     WrongNameError, NoLocationError
from foolscap.reconnector import Reconnector
from foolscap.logging import log as flog
from foolscap.logging import log
from foolscap.logging import publish as flog_publish
from foolscap.logging.log import UNUSUAL
from foolscap import crypto
        return self.tubID[:4]

    def getConnectionInfoForFURL(self, furl):
        try:
            tubref = SturdyRef(furl).getTubRef()
        except (ValueError, BadFURLError):
            return None # unparseable FURL
        return self._getConnectionInfoForTubRef(tubref)

    def _getConnectionInfoForTubRef(self, tubref):
        if tubref in self.brokers:
            return self.brokers[tubref].getConnectionInfo()
        if tubref in self.tubConnectors:
            return self.tubConnectors[tubref].getConnectionInfo()
        return None # currently have no established or in-progress connection

    def connectorStarted(self, c):
        assert self.running
        # TODO: why a list? shouldn't there only ever be one TubConnector?
        self._activeConnectors.append(c)
    def connectorFinished(self, c):
        if c in self._activeConnectors:
            self._activeConnectors.remove(c)

    def startService(self):
        service.MultiService.startService(self)
        for d,sturdy in self._pending_getReferences:
            d1 = eventual.fireEventually(sturdy)
            d1.addCallback(self.getReference)
            d1.addBoth(lambda res, d=d: d.callback(res))

# Path: src/foolscap/furl.py
# class BadFURLError(Exception):
#     pass


# Path: src/foolscap/pb.py
import os.path, weakref, binascii, re
import six
from warnings import warn
from zope.interface import implementer
from twisted.internet import (reactor, defer, protocol, error, interfaces,
                              endpoints)
from twisted.application import service
from twisted.python.failure import Failure
from twisted.python.deprecate import deprecated
from twisted.python.versions import Version
from foolscap import ipb, base32, negotiate, broker, eventual, storage
from foolscap import connection, util, info
from foolscap.connections import tcp
from foolscap.referenceable import SturdyRef
from .furl import BadFURLError
from foolscap.tokens import PBError, BananaError, WrongTubIdError, \
     WrongNameError, NoLocationError
from foolscap.reconnector import Reconnector
from foolscap.logging import log as flog
from foolscap.logging import log
from foolscap.logging import publish as flog_publish
from foolscap.logging.log import UNUSUAL
from foolscap import crypto

        return self.tubID[:4]

    def getConnectionInfoForFURL(self, furl):
        try:
            tubref = SturdyRef(furl).getTubRef()
        except (ValueError, BadFURLError):
            return None # unparseable FURL
        return self._getConnectionInfoForTubRef(tubref)

    def _getConnectionInfoForTubRef(self, tubref):
        if tubref in self.brokers:
            return self.brokers[tubref].getConnectionInfo()
        if tubref in self.tubConnectors:
            return self.tubConnectors[tubref].getConnectionInfo()
        return None # currently have no established or in-progress connection

    def connectorStarted(self, c):
        assert self.running
        # TODO: why a list? shouldn't there only ever be one TubConnector?
        self._activeConnectors.append(c)
    def connectorFinished(self, c):
        if c in self._activeConnectors:
            self._activeConnectors.remove(c)

    def startService(self):
        service.MultiService.startService(self)
        for d,sturdy in self._pending_getReferences:
            d1 = eventual.fireEventually(sturdy)
            d1.addCallback(self.getReference)
            d1.addBoth(lambda res, d=d: d.callback(res))

        del self._pending_getReferences