Пример #1
0
    def plugin_builder(the_plugin):
        """
        Enhanced plugin_builder created by L{create_enhanced_plugin_builder}.

        :param plugin: the code of the module as just read from package.
        :return: the plugin in the form of a map.
        """
        plugin_name = the_plugin.__name__
        plugin = {}

        if compulsory_objects:
            for object_name, object_signature in \
                    iteritems(compulsory_objects):
                the_object = getattr(the_plugin, object_name, None)
                if the_object is None:
                    raise AutodiscoveryError(
                        'Plugin "%s" does not '
                        'contain compulsory object "%s"' %
                        (plugin_name, object_name))
                try:
                    check_signature(object_name, the_object, object_signature)
                except AutodiscoveryError as err:
                    raise AutodiscoveryError(
                        'Plugin "%s" contains '
                        'object "%s" with a wrong signature: %s' %
                        (plugin_name, object_name, err))
                plugin[object_name] = the_object

        if optional_objects:
            for object_name, object_signature in iteritems(optional_objects):
                the_object = getattr(the_plugin, object_name, None)
                if the_object is not None:
                    try:
                        check_signature(
                            object_name,
                            the_object,
                            object_signature)
                    except AutodiscoveryError as err:
                        raise AutodiscoveryError(
                            'Plugin "%s" '
                            'contains object "%s" with a wrong signature: %s' %
                            (plugin_name, object_name, err))
                    plugin[object_name] = the_object

        if other_data:
            the_other_data = {}
            for data_name, (dummy, data_default) in iteritems(other_data):
                the_other_data[data_name] = getattr(the_plugin, data_name,
                                                    data_default)

            try:
                the_other_data = wash_urlargd(the_other_data, other_data)
            except Exception as err:
                raise AutodiscoveryError(
                    'Plugin "%s" contains other '
                    'data with problems: %s' %
                    (plugin_name, err))

            plugin.update(the_other_data)
        return plugin
Пример #2
0
    def test_wash_urlargd(self):
        """
        Test invenio_utils wash_urlargd function.

        It should deal properly with boolean values.
        """
        from invenio_utils.washers import wash_urlargd
        form = CombinedMultiDict(
            [ImmutableMultiDict([('approved', u'False'), ('objectid', u'85')]),
                ImmutableMultiDict([])]
        )
        content = {
            'ticket': (bool, False),
            'approved': (bool, False),
            'objectid': (int, 0)
        }
        expected_dict = {'approved': False, 'objectid': 85, 'ticket': False}
        self.assertEqual(wash_urlargd(form, content), expected_dict)
Пример #3
0
        def decorator(*args, **kwargs):
            from invenio_utils.washers import wash_urlargd

            argd = wash_urlargd(request.values, config)
            argd.update(kwargs)
            return f(*args, **argd)
Пример #4
0
 def decorator(*args, **kwargs):
     from invenio_utils.washers import wash_urlargd
     argd = wash_urlargd(request.values, config)
     argd.update(kwargs)
     return f(*args, **argd)