示例#1
0
 def test_is_ssl(self):
     # false
     url = URL('amqp://localhost')
     self.assertFalse(url.is_ssl())
     # true
     url = URL('amqps://localhost')
     self.assertTrue(url.is_ssl())
示例#2
0
文件: model.py 项目: pombreda/gofer
 def __init__(self, url=None):
     """
     :param url: The connector url:
         <adapter>+<scheme>://<userid:password@<host>:<port>/<virtual-host>.
     :type url: str
     """
     self.url = URL(url or DEFAULT_URL)
     self.ssl = SSL()
示例#3
0
 def __call__(self, test):
     url = URL(self.url)
     test.assertEqual(url.adapter, self.adapter)
     test.assertEqual(url.scheme, self.scheme)
     test.assertEqual(url.host, self.host)
     test.assertEqual(url.port, self.port)
     test.assertEqual(url.userid, self.userid)
     test.assertEqual(url.password, self.password)
     test.assertEqual(url.path, self.path)
示例#4
0
    def test_bind(self, _load):
        name = 'qpid'
        adapter = Mock()
        url = URL('redhat.com')
        _load.return_value = [adapter], {name: adapter}

        Adapter.bind(str(url), name)

        _load.assert_called_with()
        self.assertEqual(Adapter.bindings, {url.canonical: adapter})
示例#5
0
 def test_canonical(self):
     urls = [
         'qpid+amqp://elmer:fudd@test-host:5000/all',
         'amqp://*****:*****@test-host:5000/all',
         'amqp://test-host:5000/all', 'amqp://test-host:5000'
     ]
     for _url in urls:
         url = URL(_url)
         self.assertEqual(url.canonical,
                          _url.split('+')[-1].rsplit('/all')[0])
示例#6
0
 def test_str(self):
     urls = [
         'qpid+amqp://elmer:fudd@test-host:5000/all',
         'amqp://*****:*****@test-host:5000/all',
         'amqp://test-host:5000/all',
         'amqp://test-host:5000',
         'amqp://test-host',
     ]
     for _url in urls:
         url = URL(_url)
         self.assertEqual(str(url), url.canonical)
示例#7
0
 def test_is_ssl(self):
     # false
     url = URL('amqp://localhost')
     self.assertFalse(url.is_ssl())
     # true
     url = URL('amqps://localhost')
     self.assertTrue(url.is_ssl())
示例#8
0
文件: model.py 项目: stbenjam/gofer
 def find(url):
     """
     Find a broker by URL.
     :param url: A broker URL.
     :type url: str
     :return: The broker.
     :rtype: Broker
     """
     domain_id = URL(url).canonical
     try:
         return Domain.connector.find(domain_id)
     except NotFound:
         return Connector(url)
示例#9
0
 def test_init(self):
     url = TEST_URL
     b = Connector(url)
     self.assertEqual(b.url, URL(url))
     self.assertEqual(b.adapter, URL(url).adapter)
     self.assertEqual(b.scheme, URL(url).scheme)
     self.assertEqual(b.host, URL(url).host)
     self.assertEqual(b.port, URL(url).port)
     self.assertEqual(b.userid, URL(url).userid)
     self.assertEqual(b.password, URL(url).password)
     self.assertEqual(b.virtual_host, URL(url).path)
     self.assertEqual(b.ssl.ca_certificate, None)
     self.assertEqual(b.ssl.client_key, None)
     self.assertEqual(b.ssl.client_certificate, None)
     self.assertFalse(b.ssl.host_validation)
示例#10
0
 def bind(url, name):
     """
     Bind (associate) a URL to an adapter.
     :param url: A broker URL.
     :type url: str
     :param name: An adapter name or capability.
     :type name: str
     :raises: KeyError
     """
     _list, catalog = Adapter.loader.load()
     if not _list:
         raise NoAdaptersLoaded()
     try:
         url = URL(url)
         Adapter.bindings[url.canonical] = catalog[name]
     except KeyError:
         raise AdapterNotFound(name)
示例#11
0
 def find(url=None):
     """
     Find an adapter by URL.
     :param url: A broker URL.
     :type url: str
     :return: The requested adapter or the adapter with the
         highest *priority*.
     :raise: AdapterNotFound
     """
     _list, catalog = Adapter.loader.load()
     if not _list:
         raise NoAdaptersLoaded()
     if not url:
         return _list[0]
     try:
         url = URL(url)
         if url.adapter:
             return catalog[url.adapter]
         else:
             return Adapter.bindings[url.canonical]
     except KeyError:
         raise AdapterNotFound(url.adapter)
示例#12
0
文件: model.py 项目: stbenjam/gofer
class Connector(Model):
    """
    Represents an AMQP connector.
    :ivar url: The URL.
    :type url: URL
    :ivar heartbeat: The connection heartbeat in seconds.
    :type heartbeat: int|None
    :ivar ssl: The SSL configuration.
    :type ssl: SSL
    """

    @staticmethod
    def find(url):
        """
        Find a broker by URL.
        :param url: A broker URL.
        :type url: str
        :return: The broker.
        :rtype: Broker
        """
        domain_id = URL(url).canonical
        try:
            return Domain.connector.find(domain_id)
        except NotFound:
            return Connector(url)

    def __init__(self, url=None):
        """
        :param url: The connector url:
            <adapter>+<scheme>://<userid:password@<host>:<port>/<virtual-host>.
        :type url: str
        """
        self.url = URL(url or DEFAULT_URL)
        self.heartbeat = None
        self.ssl = SSL()

    @property
    def domain_id(self):
        """
        Get the domain ID.
        :return: The domain id.
        :rtype: str
        """
        return self.url.canonical

    @property
    def adapter(self):
        """
        Get the (gofer) adapter component of the url.
        :return: The adapter component.
        :rtype: str
        """
        return self.url.adapter

    @property
    def scheme(self):
        """
        Get the scheme component of the url.
        :return: The scheme component.
        :rtype: str
        """
        return self.url.scheme

    @property
    def host(self):
        """
        Get the host component of the url.
        :return: The host component.
        :rtype: str
        """
        return self.url.host

    @property
    def port(self):
        """
        Get the port component of the url.
        :return: The port component.
        :rtype: str
        """
        return self.url.port

    @property
    def userid(self):
        """
        Get the userid component of the url.
        :return: The userid component.
        :rtype: str
        """
        return self.url.userid

    @property
    def password(self):
        """
        Get the password component of the url.
        :return: The password component.
        :rtype: str
        """
        return self.url.password

    @property
    def virtual_host(self):
        """
        Get the virtual_host component of the url.
        :return: The virtual_host component.
        :rtype: str
        """
        return self.url.path

    def add(self):
        """
        Add this broker to the domain.
        """
        Domain.connector.add(self)

    def use_ssl(self):
        """
        Get whether SSL should be used.
        :return: True if SSL should be used.
        :rtype: bool
        """
        return self.url.is_ssl()

    def __unicode__(self):
        s = list()
        s.append('URL: %s' % self.url)
        s.append('SSL: %s' % self.ssl)
        return '|'.join(s)

    def __str__(self):
        return utf8(self)
示例#13
0
 def test_find(self, find):
     url = 'amqp://localhost'
     found = Connector.find(url)
     find.assert_called_once_with(URL(url).canonical)
     self.assertEqual(found, find.return_value)
示例#14
0
 def test_hash(self):
     url = URL('test')
     self.assertEqual(hash(url), hash(url.canonical))