Browse Source

[#101] The Template package now contains "exceptions" and "api" subpackages

Roland Haroutiounian 9 years ago
parent
commit
d70ee58cd0

+ 13
- 1
Template/Loader.py View File

@@ -3,11 +3,14 @@
3 3
 import jinja2
4 4
 
5 5
 import settings
6
-from . import api_lodel_templates
6
+from .api import api_lodel_templates
7
+from .exceptions import NotAllowedCustomAPIKeyError
7 8
 
8 9
 
9 10
 class TemplateLoader(object):
10 11
 
12
+    __reserved_template_keys = ['lodel']
13
+
11 14
     ## @brief Initializes a template loader
12 15
     #
13 16
     # @param search_path str : the base path from which the templates are searched. To use absolute paths, you can set
@@ -39,6 +42,15 @@ class TemplateLoader(object):
39 42
         # Extra modules are loaded
40 43
         if template_extra is not None:
41 44
             for extra in template_extra:
45
+                if not self.__is_allowed_template_key(extra[0]):
46
+                    raise NotAllowedCustomAPIKeyError("The name 'lodel' is a reserved one for the loaded APIs in templates")
42 47
                 template.globals[extra[0]] = extra[1]
43 48
 
44 49
         return template.render(template_vars)
50
+
51
+    ## @brief Checks if the key used for the template is allowed
52
+    #
53
+    # @param key str
54
+    # @return bool
55
+    def __is_allowed_template_key(self, key):
56
+        return False if key in self.__class__.__reserved_template_keys else True

+ 0
- 1
Template/__init__.py View File

@@ -1 +0,0 @@
1
-

+ 0
- 0
Template/api/__init__.py View File


Template/api_lodel_templates.py → Template/api/api_lodel_templates.py View File


+ 7
- 0
Template/exceptions/NotAllowedCustomAPIKeyError.py View File

@@ -0,0 +1,7 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+
4
+class NotAllowedCustomAPIKeyError(Exception):
5
+
6
+    def __init__(self, message):
7
+        self.message = message

+ 1
- 0
Template/exceptions/__init__.py View File

@@ -0,0 +1 @@
1
+#from .NotAllowedCustomAPIKeyError import NotAllowedCustomAPIKeyError

Loading…
Cancel
Save