From a926838b9080c472fe86846d90a7cd39609372bb Mon Sep 17 00:00:00 2001 From: rr- Date: Wed, 20 Apr 2016 11:59:30 +0200 Subject: [PATCH] server/general: rename 'misc' to 'util' --- server/szurubooru/func/tag_categories.py | 6 +++--- server/szurubooru/func/tags.py | 10 +++++----- server/szurubooru/func/users.py | 8 ++++---- server/szurubooru/func/{misc.py => util.py} | 0 server/szurubooru/search/base_search_config.py | 14 +++++++------- .../tests/api/test_tag_category_creating.py | 4 ++-- .../tests/api/test_tag_category_deleting.py | 4 ++-- .../tests/api/test_tag_category_retrieving.py | 4 ++-- .../tests/api/test_tag_category_updating.py | 4 ++-- server/szurubooru/tests/api/test_tag_creating.py | 4 ++-- server/szurubooru/tests/api/test_tag_deleting.py | 4 ++-- server/szurubooru/tests/api/test_tag_retrieving.py | 4 ++-- server/szurubooru/tests/api/test_tag_updating.py | 4 ++-- server/szurubooru/tests/api/test_user_creating.py | 4 ++-- server/szurubooru/tests/api/test_user_deleting.py | 4 ++-- .../szurubooru/tests/api/test_user_retrieving.py | 4 ++-- server/szurubooru/tests/api/test_user_updating.py | 4 ++-- server/szurubooru/tests/conftest.py | 2 +- server/szurubooru/tests/func/test_misc.py | 8 ++++---- 19 files changed, 48 insertions(+), 48 deletions(-) rename server/szurubooru/func/{misc.py => util.py} (100%) diff --git a/server/szurubooru/func/tag_categories.py b/server/szurubooru/func/tag_categories.py index 40ef4e01..c4a55cd7 100644 --- a/server/szurubooru/func/tag_categories.py +++ b/server/szurubooru/func/tag_categories.py @@ -1,6 +1,6 @@ import re from szurubooru import config, db, errors -from szurubooru.func import misc +from szurubooru.func import util class TagCategoryNotFoundError(errors.NotFoundError): pass class TagCategoryAlreadyExistsError(errors.ValidationError): pass @@ -30,7 +30,7 @@ def update_name(category, name): if already_exists: raise TagCategoryAlreadyExistsError( 'A category with this name already exists.') - if misc.value_exceeds_column_size(name, db.TagCategory.name): + if util.value_exceeds_column_size(name, db.TagCategory.name): raise InvalidTagCategoryNameError('Name is too long.') _verify_name_validity(name) category.name = name @@ -38,7 +38,7 @@ def update_name(category, name): def update_color(category, color): if not color: raise InvalidTagCategoryNameError('Color cannot be empty.') - if misc.value_exceeds_column_size(color, db.TagCategory.color): + if util.value_exceeds_column_size(color, db.TagCategory.color): raise InvalidTagCategoryColorError('Color is too long.') category.color = color diff --git a/server/szurubooru/func/tags.py b/server/szurubooru/func/tags.py index 0c96203f..469ab705 100644 --- a/server/szurubooru/func/tags.py +++ b/server/szurubooru/func/tags.py @@ -4,7 +4,7 @@ import os import re import sqlalchemy from szurubooru import config, db, errors -from szurubooru.func import misc, tag_categories +from szurubooru.func import util, tag_categories class TagNotFoundError(errors.NotFoundError): pass class TagAlreadyExistsError(errors.ValidationError): pass @@ -68,7 +68,7 @@ def get_tag_by_name(name): .first() def get_tags_by_names(names): - names = misc.icase_unique(names) + names = util.icase_unique(names) if len(names) == 0: return [] expr = sqlalchemy.sql.false() @@ -77,7 +77,7 @@ def get_tags_by_names(names): return db.session.query(db.Tag).join(db.TagName).filter(expr).all() def get_or_create_tags_by_names(names): - names = misc.icase_unique(names) + names = util.icase_unique(names) for name in names: _verify_name_validity(name) related_tags = get_tags_by_names(names) @@ -120,14 +120,14 @@ def update_category_name(tag, category_name): tag.category = category def update_names(tag, names): - names = misc.icase_unique([name for name in names if name]) + names = util.icase_unique([name for name in names if name]) if not len(names): raise InvalidTagNameError('At least one name must be specified.') for name in names: _verify_name_validity(name) expr = sqlalchemy.sql.false() for name in names: - if misc.value_exceeds_column_size(name, db.TagName.name): + if util.value_exceeds_column_size(name, db.TagName.name): raise InvalidTagNameError('Name is too long.') expr = expr | db.TagName.name.ilike(name) if tag.tag_id: diff --git a/server/szurubooru/func/users.py b/server/szurubooru/func/users.py index 528bac70..0ef6716e 100644 --- a/server/szurubooru/func/users.py +++ b/server/szurubooru/func/users.py @@ -2,7 +2,7 @@ import datetime import re from sqlalchemy import func from szurubooru import config, db, errors -from szurubooru.func import auth, misc, files, images +from szurubooru.func import auth, util, files, images class UserNotFoundError(errors.NotFoundError): pass class UserAlreadyExistsError(errors.ValidationError): pass @@ -45,7 +45,7 @@ def create_user(name, password, email, auth_user): def update_name(user, name, auth_user): if not name: raise InvalidUserNameError('Name cannot be empty.') - if misc.value_exceeds_column_size(name, db.User.name): + if util.value_exceeds_column_size(name, db.User.name): raise InvalidUserNameError('User name is too long.') other_user = get_user_by_name(name) if other_user and other_user.user_id != auth_user.user_id: @@ -72,9 +72,9 @@ def update_email(user, email): email = email.strip() if not email: email = None - if email and misc.value_exceeds_column_size(email, db.User.email): + if email and util.value_exceeds_column_size(email, db.User.email): raise InvalidEmailError('Email is too long.') - if not misc.is_valid_email(email): + if not util.is_valid_email(email): raise InvalidEmailError('E-mail is invalid.') user.email = email diff --git a/server/szurubooru/func/misc.py b/server/szurubooru/func/util.py similarity index 100% rename from server/szurubooru/func/misc.py rename to server/szurubooru/func/util.py diff --git a/server/szurubooru/search/base_search_config.py b/server/szurubooru/search/base_search_config.py index e5583761..5a4c2ab7 100644 --- a/server/szurubooru/search/base_search_config.py +++ b/server/szurubooru/search/base_search_config.py @@ -1,6 +1,6 @@ import sqlalchemy import szurubooru.errors -from szurubooru.func import misc +from szurubooru.func import util from szurubooru.search import criteria class BaseSearchConfig(object): @@ -82,24 +82,24 @@ class BaseSearchConfig(object): Parse the datetime inside the criterion. ''' if isinstance(criterion, criteria.PlainSearchCriterion): - min_date, max_date = misc.parse_time_range(criterion.value) + min_date, max_date = util.parse_time_range(criterion.value) expr = column.between(min_date, max_date) elif isinstance(criterion, criteria.ArraySearchCriterion): expr = sqlalchemy.sql.false() for value in criterion.values: - min_date, max_date = misc.parse_time_range(value) + min_date, max_date = util.parse_time_range(value) expr = expr | column.between(min_date, max_date) elif isinstance(criterion, criteria.RangedSearchCriterion): assert criterion.min_value or criterion.max_value if criterion.min_value and criterion.max_value: - min_date = misc.parse_time_range(criterion.min_value)[0] - max_date = misc.parse_time_range(criterion.max_value)[1] + min_date = util.parse_time_range(criterion.min_value)[0] + max_date = util.parse_time_range(criterion.max_value)[1] expr = column.between(min_date, max_date) elif criterion.min_value: - min_date = misc.parse_time_range(criterion.min_value)[0] + min_date = util.parse_time_range(criterion.min_value)[0] expr = column >= min_date elif criterion.max_value: - max_date = misc.parse_time_range(criterion.max_value)[1] + max_date = util.parse_time_range(criterion.max_value)[1] expr = column <= max_date else: assert False diff --git a/server/szurubooru/tests/api/test_tag_category_creating.py b/server/szurubooru/tests/api/test_tag_category_creating.py index 7eac22b6..dcc0a7a7 100644 --- a/server/szurubooru/tests/api/test_tag_category_creating.py +++ b/server/szurubooru/tests/api/test_tag_category_creating.py @@ -1,7 +1,7 @@ import os import pytest from szurubooru import api, config, db, errors -from szurubooru.func import misc, tag_categories +from szurubooru.func import util, tag_categories @pytest.fixture def test_ctx(tmpdir, config_injector, context_factory, user_factory): @@ -11,7 +11,7 @@ def test_ctx(tmpdir, config_injector, context_factory, user_factory): 'ranks': ['anonymous', 'regular_user'], 'privileges': {'tag_categories:create': 'regular_user'}, }) - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.api = api.TagCategoryListApi() diff --git a/server/szurubooru/tests/api/test_tag_category_deleting.py b/server/szurubooru/tests/api/test_tag_category_deleting.py index a1b93af0..664198cb 100644 --- a/server/szurubooru/tests/api/test_tag_category_deleting.py +++ b/server/szurubooru/tests/api/test_tag_category_deleting.py @@ -2,7 +2,7 @@ import pytest import os from datetime import datetime from szurubooru import api, config, db, errors -from szurubooru.func import misc, tags, tag_categories +from szurubooru.func import util, tags, tag_categories @pytest.fixture def test_ctx( @@ -19,7 +19,7 @@ def test_ctx( }, 'ranks': ['anonymous', 'regular_user'], }) - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.tag_factory = tag_factory diff --git a/server/szurubooru/tests/api/test_tag_category_retrieving.py b/server/szurubooru/tests/api/test_tag_category_retrieving.py index 748ad4cf..737dd7ec 100644 --- a/server/szurubooru/tests/api/test_tag_category_retrieving.py +++ b/server/szurubooru/tests/api/test_tag_category_retrieving.py @@ -1,7 +1,7 @@ import datetime import pytest from szurubooru import api, db, errors -from szurubooru.func import misc, tag_categories +from szurubooru.func import util, tag_categories @pytest.fixture def test_ctx( @@ -15,7 +15,7 @@ def test_ctx( 'ranks': ['anonymous', 'regular_user', 'mod', 'admin'], 'rank_names': {'regular_user': 'Peasant'}, }) - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.tag_category_factory = tag_category_factory diff --git a/server/szurubooru/tests/api/test_tag_category_updating.py b/server/szurubooru/tests/api/test_tag_category_updating.py index 1e75bf4f..f1b0dec4 100644 --- a/server/szurubooru/tests/api/test_tag_category_updating.py +++ b/server/szurubooru/tests/api/test_tag_category_updating.py @@ -1,7 +1,7 @@ import os import pytest from szurubooru import api, config, db, errors -from szurubooru.func import misc, tag_categories +from szurubooru.func import util, tag_categories @pytest.fixture def test_ctx( @@ -19,7 +19,7 @@ def test_ctx( 'tag_categories:edit:color': 'regular_user', }, }) - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.tag_category_factory = tag_category_factory diff --git a/server/szurubooru/tests/api/test_tag_creating.py b/server/szurubooru/tests/api/test_tag_creating.py index 0b01ab2d..ef5de906 100644 --- a/server/szurubooru/tests/api/test_tag_creating.py +++ b/server/szurubooru/tests/api/test_tag_creating.py @@ -2,7 +2,7 @@ import datetime import os import pytest from szurubooru import api, config, db, errors -from szurubooru.func import misc, tags +from szurubooru.func import util, tags def get_tag(name): return db.session \ @@ -27,7 +27,7 @@ def test_ctx( db.session.add_all([ db.TagCategory(name) for name in ['meta', 'character', 'copyright']]) db.session.flush() - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.tag_factory = tag_factory diff --git a/server/szurubooru/tests/api/test_tag_deleting.py b/server/szurubooru/tests/api/test_tag_deleting.py index edcccfbc..9d9fa6d5 100644 --- a/server/szurubooru/tests/api/test_tag_deleting.py +++ b/server/szurubooru/tests/api/test_tag_deleting.py @@ -2,7 +2,7 @@ import pytest import os from datetime import datetime from szurubooru import api, config, db, errors -from szurubooru.func import misc, tags +from szurubooru.func import util, tags @pytest.fixture def test_ctx( @@ -14,7 +14,7 @@ def test_ctx( }, 'ranks': ['anonymous', 'regular_user'], }) - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.tag_factory = tag_factory diff --git a/server/szurubooru/tests/api/test_tag_retrieving.py b/server/szurubooru/tests/api/test_tag_retrieving.py index db7bb154..9cfa8f08 100644 --- a/server/szurubooru/tests/api/test_tag_retrieving.py +++ b/server/szurubooru/tests/api/test_tag_retrieving.py @@ -1,7 +1,7 @@ import datetime import pytest from szurubooru import api, db, errors -from szurubooru.func import misc, tags +from szurubooru.func import util, tags @pytest.fixture def test_ctx(context_factory, config_injector, user_factory, tag_factory): @@ -14,7 +14,7 @@ def test_ctx(context_factory, config_injector, user_factory, tag_factory): 'ranks': ['anonymous', 'regular_user', 'mod', 'admin'], 'rank_names': {'regular_user': 'Peasant'}, }) - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.tag_factory = tag_factory diff --git a/server/szurubooru/tests/api/test_tag_updating.py b/server/szurubooru/tests/api/test_tag_updating.py index b1c8febc..def7335b 100644 --- a/server/szurubooru/tests/api/test_tag_updating.py +++ b/server/szurubooru/tests/api/test_tag_updating.py @@ -2,7 +2,7 @@ import datetime import os import pytest from szurubooru import api, config, db, errors -from szurubooru.func import misc, tags +from szurubooru.func import util, tags def get_tag(name): return db.session \ @@ -32,7 +32,7 @@ def test_ctx( db.session.add_all([ db.TagCategory(name) for name in ['meta', 'character', 'copyright']]) db.session.flush() - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.tag_factory = tag_factory diff --git a/server/szurubooru/tests/api/test_user_creating.py b/server/szurubooru/tests/api/test_user_creating.py index 56f35cf4..274f0f40 100644 --- a/server/szurubooru/tests/api/test_user_creating.py +++ b/server/szurubooru/tests/api/test_user_creating.py @@ -1,7 +1,7 @@ import datetime import pytest from szurubooru import api, config, db, errors -from szurubooru.func import auth, misc, users +from szurubooru.func import auth, util, users EMPTY_PIXEL = \ b'\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x01\x00\x00\x00\x00' \ @@ -23,7 +23,7 @@ def test_ctx(config_injector, context_factory, user_factory): 'rank_names': {}, 'privileges': {'users:create': 'anonymous'}, }) - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.api = api.UserListApi() diff --git a/server/szurubooru/tests/api/test_user_deleting.py b/server/szurubooru/tests/api/test_user_deleting.py index 95d2c44f..89b11e5e 100644 --- a/server/szurubooru/tests/api/test_user_deleting.py +++ b/server/szurubooru/tests/api/test_user_deleting.py @@ -1,7 +1,7 @@ import pytest from datetime import datetime from szurubooru import api, db, errors -from szurubooru.func import misc, users +from szurubooru.func import util, users @pytest.fixture def test_ctx(config_injector, context_factory, user_factory): @@ -12,7 +12,7 @@ def test_ctx(config_injector, context_factory, user_factory): }, 'ranks': ['anonymous', 'regular_user', 'mod', 'admin'], }) - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.api = api.UserDetailApi() diff --git a/server/szurubooru/tests/api/test_user_retrieving.py b/server/szurubooru/tests/api/test_user_retrieving.py index af4c59bc..bcb1df85 100644 --- a/server/szurubooru/tests/api/test_user_retrieving.py +++ b/server/szurubooru/tests/api/test_user_retrieving.py @@ -1,7 +1,7 @@ import datetime import pytest from szurubooru import api, db, errors -from szurubooru.func import misc, users +from szurubooru.func import util, users @pytest.fixture def test_ctx(context_factory, config_injector, user_factory): @@ -14,7 +14,7 @@ def test_ctx(context_factory, config_injector, user_factory): 'ranks': ['anonymous', 'regular_user', 'mod', 'admin'], 'rank_names': {'regular_user': 'Peasant'}, }) - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.list_api = api.UserListApi() diff --git a/server/szurubooru/tests/api/test_user_updating.py b/server/szurubooru/tests/api/test_user_updating.py index 47d54e88..e069c24e 100644 --- a/server/szurubooru/tests/api/test_user_updating.py +++ b/server/szurubooru/tests/api/test_user_updating.py @@ -1,7 +1,7 @@ import datetime import pytest from szurubooru import api, config, db, errors -from szurubooru.func import auth, misc, users +from szurubooru.func import auth, util, users EMPTY_PIXEL = \ b'\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x01\x00\x00\x00\x00' \ @@ -33,7 +33,7 @@ def test_ctx(config_injector, context_factory, user_factory): 'users:edit:any:avatar': 'admin', }, }) - ret = misc.dotdict() + ret = util.dotdict() ret.context_factory = context_factory ret.user_factory = user_factory ret.api = api.UserDetailApi() diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py index e6c0d43d..57841c18 100644 --- a/server/szurubooru/tests/conftest.py +++ b/server/szurubooru/tests/conftest.py @@ -5,7 +5,7 @@ import pytest import freezegun import sqlalchemy from szurubooru import api, config, db -from szurubooru.func import misc +from szurubooru.func import util class QueryCounter(object): def __init__(self): diff --git a/server/szurubooru/tests/func/test_misc.py b/server/szurubooru/tests/func/test_misc.py index fc04bdb8..69255ad2 100644 --- a/server/szurubooru/tests/func/test_misc.py +++ b/server/szurubooru/tests/func/test_misc.py @@ -1,13 +1,13 @@ import pytest from szurubooru import errors -from szurubooru.func import misc +from szurubooru.func import util from datetime import datetime dt = datetime def test_parsing_empty_date_time(): with pytest.raises(errors.ValidationError): - misc.parse_time_range('') + util.parse_time_range('') @pytest.mark.parametrize('input,output', [ ('today', (dt(1997, 1, 2, 0, 0, 0), dt(1997, 1, 2, 23, 59, 59))), @@ -22,7 +22,7 @@ def test_parsing_empty_date_time(): ]) def test_parsing_date_time(fake_datetime, input, output): with fake_datetime('1997-01-02 03:04:05'): - assert misc.parse_time_range(input) == output + assert util.parse_time_range(input) == output @pytest.mark.parametrize('input,output', [ ([], []), @@ -33,4 +33,4 @@ def test_parsing_date_time(fake_datetime, input, output): (['a', 'A', 'b', 'B'], ['a', 'b']), ]) def test_icase_unique(input, output): - assert misc.icase_unique(input) == output + assert util.icase_unique(input) == output