# HG changeset patch # User neko259 # Date 2017-12-11 16:14:23 # Node ID a3d63355f5874b71327214c803d375e2c6b80d0c # Parent 6d66389f99ac3972977a66ed032fca457a87e0ef Extracted some magic strings diff --git a/boards/settings.py b/boards/settings.py --- a/boards/settings.py +++ b/boards/settings.py @@ -5,6 +5,14 @@ CONFIG_DEFAULT_SETTINGS = 'boards/config CONFIG_SETTINGS = 'boards/config/settings.ini' +SECTION_FORMS = 'Forms' + +VALUE_TRUE = 'true' + +LIST_DELIMITER = ',' +DICT_DELIMITER = ':' + + config = configparser.ConfigParser() config.read(CONFIG_DEFAULT_SETTINGS) config.read(CONFIG_SETTINGS) @@ -19,15 +27,15 @@ def get_int(section, name): def get_bool(section, name): - return get(section, name) == 'true' + return get(section, name) == VALUE_TRUE def get_list_dict(section, name): str_dict = get(section, name) - return [item.split(':') for item in str_dict.split(',')] + return [item.split(DICT_DELIMITER) for item in str_dict.split(LIST_DELIMITER)] def get_list(section, name): str_list = get(section, name) - return str_list.split(',') + return str_list.split(LIST_DELIMITER) diff --git a/boards/utils.py b/boards/utils.py --- a/boards/utils.py +++ b/boards/utils.py @@ -30,6 +30,10 @@ SETTING_ANON_MODE = 'AnonymousMode' ANON_IP = '127.0.0.1' FILE_EXTENSION_DELIMITER = '.' +URL_DELIMITER = '/' +CACHE_KEY_DELIMITER = ':' + +DEFAULT_MIMETYPE = 'application/octet-stream' def is_anonymous_mode(): @@ -67,7 +71,7 @@ def cached_result(key_method=None): cache_key_params += args for key, value in kwargs: - cache_key_params.append(key + ':' + value) + cache_key_params.append(key + CACHE_KEY_DELIMITER + value) if isinstance(obj, Model): cache_key_params.append(str(obj.id)) @@ -129,7 +133,7 @@ def get_file_mimetype(file) -> str: file_type = magic.from_buffer(buf, mime=True) if file_type is None: - file_type = 'application/octet-stream' + file_type = DEFAULT_MIMETYPE elif type(file_type) == bytes: file_type = file_type.decode() return file_type @@ -139,7 +143,7 @@ def get_domain(url: str) -> str: """ Gets domain from an URL with random number of domain levels. """ - domain_parts = url.split('/') + domain_parts = url.split(URL_DELIMITER) if len(domain_parts) >= 2: full_domain = domain_parts[2] else: