Преглед на файлове

[enh] plugin attribute type check

Adam Tauber преди 10 години
родител
ревизия
bf5d6f56c6
променени са 1 файла, в които са добавени 6 реда и са изтрити 5 реда
  1. 6
    5
      searx/plugins/__init__.py

+ 6
- 5
searx/plugins/__init__.py Целия файл

4
 
4
 
5
 logger = logger.getChild('plugins')
5
 logger = logger.getChild('plugins')
6
 
6
 
7
-required_attrs = ('name',
8
-                  'description',
9
-                  'default_on')
7
+required_attrs = (('name', str),
8
+                  ('description', str),
9
+                  ('default_on', bool))
10
 
10
 
11
 
11
 
12
 class Plugin():
12
 class Plugin():
13
     default_on = False
13
     default_on = False
14
     name = 'Default plugin'
14
     name = 'Default plugin'
15
+    description = 'Default plugin description'
15
 
16
 
16
 
17
 
17
 class PluginStore():
18
 class PluginStore():
25
 
26
 
26
     def register(self, *plugins):
27
     def register(self, *plugins):
27
         for plugin in plugins:
28
         for plugin in plugins:
28
-            for plugin_attr in required_attrs:
29
-                if not hasattr(plugin, plugin_attr):
29
+            for plugin_attr, plugin_attr_type in required_attrs:
30
+                if not hasattr(plugin, plugin_attr) or not isinstance(getattr(plugin, plugin_attr), plugin_attr_type):
30
                     logger.critical('missing attribute "{0}", cannot load plugin: {1}'.format(plugin_attr, plugin))
31
                     logger.critical('missing attribute "{0}", cannot load plugin: {1}'.format(plugin_attr, plugin))
31
                     exit(3)
32
                     exit(3)
32
             plugin.id = plugin.name.replace(' ', '_')
33
             plugin.id = plugin.name.replace(' ', '_')