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