Exemplo n.º 1
0
    def list(self, base_url=None, **kwargs):
        """List the collection.

        :param base_url: if provided, the generated URL will be appended to it
        """
        kwargs = self._filter_kwargs(kwargs)

        return self._list(
            '%(base_url)s%(query)s' % {
                'base_url': self.build_url(base_url=base_url, **kwargs),
                'query': '?%s' % urlutils.urlencode(kwargs) if kwargs else '',
            },
            self.collection_key)
Exemplo n.º 2
0
    def __call__(self, target, creds, enforcer):
        """Check http: rules by calling to a remote server.

        This example implementation simply verifies that the response
        is exactly 'True'.
        """

        url = ('http:' + self.match) % target
        data = {'target': jsonutils.dumps(target),
                'credentials': jsonutils.dumps(creds)}
        post_data = urlutils.urlencode(data)
        f = urlutils.urlopen(url, post_data)
        return f.read() == "True"
Exemplo n.º 3
0
    def find(self, base_url=None, **kwargs):
        """Find a single item with attributes matching ``**kwargs``.

        :param base_url: if provided, the generated URL will be appended to it
        """
        kwargs = self._filter_kwargs(kwargs)

        rl = self._list(
            '%(base_url)s%(query)s' % {
                'base_url': self.build_url(base_url=base_url, **kwargs),
                'query': '?%s' % urlutils.urlencode(kwargs) if kwargs else '',
            },
            self.collection_key)
        num = len(rl)

        if num == 0:
            msg = "No %s matching %s." % (self.resource_class.__name__, kwargs)
            raise exceptions.NotFound(404, msg)
        elif num > 1:
            raise exceptions.NoUniqueMatch
        else:
            return rl[0]
Exemplo n.º 4
0
 def test_urlencode(self):
     fake = 'fake'
     result = urlutils.urlencode({'Fake': fake})
     self.assertEquals(result, 'Fake=fake')
Exemplo n.º 5
0
 def test_urlencode(self):
     fake = 'fake'
     result = urlutils.urlencode({'Fake': fake})
     self.assertEqual(result, 'Fake=fake')