Show More
@@ -5,6 +5,14 b" CONFIG_DEFAULT_SETTINGS = 'boards/config" | |||
|
5 | 5 | CONFIG_SETTINGS = 'boards/config/settings.ini' |
|
6 | 6 | |
|
7 | 7 | |
|
8 | SECTION_FORMS = 'Forms' | |
|
9 | ||
|
10 | VALUE_TRUE = 'true' | |
|
11 | ||
|
12 | LIST_DELIMITER = ',' | |
|
13 | DICT_DELIMITER = ':' | |
|
14 | ||
|
15 | ||
|
8 | 16 | config = configparser.ConfigParser() |
|
9 | 17 | config.read(CONFIG_DEFAULT_SETTINGS) |
|
10 | 18 | config.read(CONFIG_SETTINGS) |
@@ -19,15 +27,15 b' def get_int(section, name):' | |||
|
19 | 27 | |
|
20 | 28 | |
|
21 | 29 | def get_bool(section, name): |
|
22 |
return get(section, name) == |
|
|
30 | return get(section, name) == VALUE_TRUE | |
|
23 | 31 | |
|
24 | 32 | |
|
25 | 33 | def get_list_dict(section, name): |
|
26 | 34 | str_dict = get(section, name) |
|
27 |
return [item.split( |
|
|
35 | return [item.split(DICT_DELIMITER) for item in str_dict.split(LIST_DELIMITER)] | |
|
28 | 36 | |
|
29 | 37 | |
|
30 | 38 | def get_list(section, name): |
|
31 | 39 | str_list = get(section, name) |
|
32 |
return str_list.split( |
|
|
40 | return str_list.split(LIST_DELIMITER) | |
|
33 | 41 |
@@ -30,6 +30,10 b" SETTING_ANON_MODE = 'AnonymousMode'" | |||
|
30 | 30 | ANON_IP = '127.0.0.1' |
|
31 | 31 | |
|
32 | 32 | FILE_EXTENSION_DELIMITER = '.' |
|
33 | URL_DELIMITER = '/' | |
|
34 | CACHE_KEY_DELIMITER = ':' | |
|
35 | ||
|
36 | DEFAULT_MIMETYPE = 'application/octet-stream' | |
|
33 | 37 | |
|
34 | 38 | |
|
35 | 39 | def is_anonymous_mode(): |
@@ -67,7 +71,7 b' def cached_result(key_method=None):' | |||
|
67 | 71 | |
|
68 | 72 | cache_key_params += args |
|
69 | 73 | for key, value in kwargs: |
|
70 |
cache_key_params.append(key + |
|
|
74 | cache_key_params.append(key + CACHE_KEY_DELIMITER + value) | |
|
71 | 75 | |
|
72 | 76 | if isinstance(obj, Model): |
|
73 | 77 | cache_key_params.append(str(obj.id)) |
@@ -129,7 +133,7 b' def get_file_mimetype(file) -> str:' | |||
|
129 | 133 | |
|
130 | 134 | file_type = magic.from_buffer(buf, mime=True) |
|
131 | 135 | if file_type is None: |
|
132 | file_type = 'application/octet-stream' | |
|
136 | file_type = DEFAULT_MIMETYPE | |
|
133 | 137 | elif type(file_type) == bytes: |
|
134 | 138 | file_type = file_type.decode() |
|
135 | 139 | return file_type |
@@ -139,7 +143,7 b' def get_domain(url: str) -> str:' | |||
|
139 | 143 | """ |
|
140 | 144 | Gets domain from an URL with random number of domain levels. |
|
141 | 145 | """ |
|
142 |
domain_parts = url.split( |
|
|
146 | domain_parts = url.split(URL_DELIMITER) | |
|
143 | 147 | if len(domain_parts) >= 2: |
|
144 | 148 | full_domain = domain_parts[2] |
|
145 | 149 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now