Browse Source

[enh] plugin attribute type check

Adam Tauber 10 years ago
parent
commit
bf5d6f56c6
1 changed files with 6 additions and 5 deletions
  1. 6
    5
      searx/plugins/__init__.py

+ 6
- 5
searx/plugins/__init__.py View File

@@ -4,14 +4,15 @@ from sys import exit
4 4
 
5 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 12
 class Plugin():
13 13
     default_on = False
14 14
     name = 'Default plugin'
15
+    description = 'Default plugin description'
15 16
 
16 17
 
17 18
 class PluginStore():
@@ -25,8 +26,8 @@ class PluginStore():
25 26
 
26 27
     def register(self, *plugins):
27 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 31
                     logger.critical('missing attribute "{0}", cannot load plugin: {1}'.format(plugin_attr, plugin))
31 32
                     exit(3)
32 33
             plugin.id = plugin.name.replace(' ', '_')