server/general: rename 'misc' to 'util'
This commit is contained in:
parent
57b18c6461
commit
a926838b90
19 changed files with 48 additions and 48 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue