Cleanup func imports, and small formatting changes.
This commit is contained in:
parent
a526a56767
commit
796563f772
18 changed files with 147 additions and 145 deletions
|
@ -1,13 +1,13 @@
|
|||
import uuid
|
||||
|
||||
import hashlib
|
||||
import random
|
||||
from collections import OrderedDict
|
||||
from nacl.exceptions import InvalidkeyError
|
||||
from nacl.pwhash import argon2id, verify
|
||||
|
||||
from szurubooru import config, model, errors, db
|
||||
from szurubooru.func import util
|
||||
from nacl.pwhash import argon2id, verify
|
||||
import uuid
|
||||
|
||||
|
||||
RANK_MAP = OrderedDict([
|
||||
(model.User.RANK_ANONYMOUS, 'anonymous'),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from typing import Any, List, Dict
|
||||
from datetime import datetime
|
||||
from typing import Any, List, Dict
|
||||
|
||||
|
||||
class LruCacheItem:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from datetime import datetime
|
||||
from typing import Any, Optional, List, Dict, Callable
|
||||
|
||||
from szurubooru import db, model, errors, rest
|
||||
from szurubooru.func import users, scores, serialization
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from typing import Any, Optional, Callable, Tuple
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional, Callable, Tuple
|
||||
|
||||
from szurubooru import db, model, errors
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Optional
|
||||
from datetime import datetime, timedelta
|
||||
from szurubooru.func import files, util
|
||||
from typing import Optional
|
||||
|
||||
from szurubooru.func import files, util
|
||||
|
||||
MAX_MINUTES = 60
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
from typing import Any, Optional, List
|
||||
|
||||
import os
|
||||
|
||||
from szurubooru import config
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import logging
|
||||
from io import BytesIO
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional, Tuple, Set, List, Callable
|
||||
|
||||
import elasticsearch
|
||||
import elasticsearch_dsl
|
||||
import numpy as np
|
||||
from skimage.color import rgb2gray
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
from skimage.color import rgb2gray
|
||||
|
||||
from szurubooru import config, errors
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
|
@ -207,7 +209,7 @@ def _get_words(array: NpMatrix, k: int, n: int) -> NpMatrix:
|
|||
|
||||
def _words_to_int(word_array: NpMatrix) -> NpMatrix:
|
||||
width = word_array.shape[1]
|
||||
coding_vector = 3**np.arange(width)
|
||||
coding_vector = 3 ** np.arange(width)
|
||||
return np.dot(word_array + 1, coding_vector)
|
||||
|
||||
|
||||
|
@ -247,7 +249,9 @@ def _safety_blanket(default_param_factory: Callable[[], Any]) -> Callable:
|
|||
raise errors.ProcessingError('Not an image.')
|
||||
except Exception as ex:
|
||||
raise errors.ThirdPartyError('Unknown error (%s).' % ex)
|
||||
|
||||
return wrapper_inner
|
||||
|
||||
return wrapper_outer
|
||||
|
||||
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
from typing import List
|
||||
import logging
|
||||
import json
|
||||
import logging
|
||||
import math
|
||||
import shlex
|
||||
import subprocess
|
||||
import math
|
||||
from typing import List
|
||||
|
||||
from szurubooru import errors
|
||||
from szurubooru.func import mime, util
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
_SCALE_FIT_FMT = (
|
||||
r'scale=iw*max({width}/iw\,{height}/ih):ih*max({width}/iw\,{height}/ih)')
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import smtplib
|
||||
import email.mime.text
|
||||
import smtplib
|
||||
|
||||
from szurubooru import config
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import re
|
||||
from typing import Optional
|
||||
|
||||
import re
|
||||
|
||||
APPLICATION_SWF = 'application/x-shockwave-flash'
|
||||
IMAGE_JPEG = 'image/jpeg'
|
||||
IMAGE_PNG = 'image/png'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import urllib.request
|
||||
from szurubooru import config
|
||||
from szurubooru import errors
|
||||
|
||||
from szurubooru import config, errors
|
||||
|
||||
|
||||
def download(url: str) -> bytes:
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import hmac
|
||||
from typing import Any, Optional, Tuple, List, Dict, Callable
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional, Tuple, List, Dict, Callable
|
||||
|
||||
import hmac
|
||||
import sqlalchemy as sa
|
||||
|
||||
from szurubooru import config, db, model, errors, rest
|
||||
from szurubooru.func import (
|
||||
users, scores, comments, tags, util,
|
||||
mime, images, files, image_hash, serialization, snapshots)
|
||||
|
||||
|
||||
EMPTY_PIXEL = (
|
||||
b'\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x01\x00\x00\x00\x00'
|
||||
b'\xff\xff\xff\x21\xf9\x04\x01\x00\x00\x01\x00\x2c\x00\x00\x00\x00'
|
||||
|
@ -658,9 +659,7 @@ def merge_posts(
|
|||
|
||||
if anti_dup_func is not None:
|
||||
update_stmt = (
|
||||
update_stmt
|
||||
.where(
|
||||
~sa.exists()
|
||||
update_stmt.where(~sa.exists()
|
||||
.where(anti_dup_func(alias1, alias2))
|
||||
.where(alias2.post_id == target_post_id)))
|
||||
|
||||
|
@ -734,8 +733,7 @@ def merge_posts(
|
|||
def search_by_image_exact(image_content: bytes) -> Optional[model.Post]:
|
||||
checksum = util.get_sha1(image_content)
|
||||
return (
|
||||
db.session
|
||||
.query(model.Post)
|
||||
db.session.query(model.Post)
|
||||
.filter(model.Post.checksum == checksum)
|
||||
.one_or_none())
|
||||
|
||||
|
@ -756,8 +754,7 @@ def populate_reverse_search() -> None:
|
|||
excluded_post_ids = image_hash.get_all_paths()
|
||||
|
||||
post_ids_to_hash = (
|
||||
db.session
|
||||
.query(model.Post.post_id)
|
||||
db.session.query(model.Post.post_id)
|
||||
.filter(
|
||||
(model.Post.type == model.Post.TYPE_IMAGE) |
|
||||
(model.Post.type == model.Post.TYPE_ANIMATION))
|
||||
|
@ -767,8 +764,7 @@ def populate_reverse_search() -> None:
|
|||
|
||||
for post_ids_chunk in util.chunks(post_ids_to_hash, 100):
|
||||
posts_chunk = (
|
||||
db.session
|
||||
.query(model.Post)
|
||||
db.session.query(model.Post)
|
||||
.filter(model.Post.post_id.in_(post_ids_chunk))
|
||||
.all())
|
||||
for post in posts_chunk:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import datetime
|
||||
from typing import Any, Tuple, Callable
|
||||
|
||||
from szurubooru import db, model, errors
|
||||
|
||||
|
||||
|
@ -40,8 +41,7 @@ def get_score(entity: model.Base, user: model.User) -> int:
|
|||
assert user
|
||||
table, get_column = _get_table_info(entity)
|
||||
row = (
|
||||
db.session
|
||||
.query(table.score)
|
||||
db.session.query(table.score)
|
||||
.filter(get_column(table) == get_column(entity))
|
||||
.filter(table.user_id == user.user_id)
|
||||
.one_or_none())
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from typing import Any, List, Dict, Callable
|
||||
|
||||
from szurubooru import model, rest, errors
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from typing import Any, Optional, Dict, Callable
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional, Dict, Callable
|
||||
|
||||
from szurubooru import db, model
|
||||
from szurubooru.func import diff, users
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import re
|
||||
from typing import Any, Optional, Dict, List, Callable
|
||||
|
||||
import re
|
||||
import sqlalchemy as sa
|
||||
|
||||
from szurubooru import config, db, model, errors, rest
|
||||
from szurubooru.func import util, serialization, cache
|
||||
|
||||
|
||||
DEFAULT_CATEGORY_NAME_CACHE_KEY = 'default-tag-category'
|
||||
|
||||
|
||||
|
@ -115,8 +116,7 @@ def update_category_color(category: model.TagCategory, color: str) -> None:
|
|||
def try_get_category_by_name(
|
||||
name: str, lock: bool = False) -> Optional[model.TagCategory]:
|
||||
query = (
|
||||
db.session
|
||||
.query(model.TagCategory)
|
||||
db.session.query(model.TagCategory)
|
||||
.filter(sa.func.lower(model.TagCategory.name) == name.lower()))
|
||||
if lock:
|
||||
query = query.with_lockmode('update')
|
||||
|
@ -141,8 +141,7 @@ def get_all_categories() -> List[model.TagCategory]:
|
|||
def try_get_default_category(
|
||||
lock: bool = False) -> Optional[model.TagCategory]:
|
||||
query = (
|
||||
db.session
|
||||
.query(model.TagCategory)
|
||||
db.session.query(model.TagCategory)
|
||||
.filter(model.TagCategory.default))
|
||||
if lock:
|
||||
query = query.with_lockmode('update')
|
||||
|
@ -151,8 +150,7 @@ def try_get_default_category(
|
|||
# category, get the first record available.
|
||||
if not category:
|
||||
query = (
|
||||
db.session
|
||||
.query(model.TagCategory)
|
||||
db.session.query(model.TagCategory)
|
||||
.order_by(model.TagCategory.tag_category_id.asc()))
|
||||
if lock:
|
||||
query = query.with_lockmode('update')
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import json
|
||||
import os
|
||||
import re
|
||||
from typing import Any, Optional, Tuple, List, Dict, Callable
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional, Tuple, List, Dict, Callable
|
||||
|
||||
import re
|
||||
import sqlalchemy as sa
|
||||
|
||||
from szurubooru import config, db, model, errors, rest
|
||||
from szurubooru.func import util, tag_categories, serialization
|
||||
|
||||
|
@ -138,8 +138,7 @@ def serialize_tag(
|
|||
|
||||
def try_get_tag_by_name(name: str) -> Optional[model.Tag]:
|
||||
return (
|
||||
db.session
|
||||
.query(model.Tag)
|
||||
db.session.query(model.Tag)
|
||||
.join(model.TagName)
|
||||
.filter(sa.func.lower(model.TagName.name) == name.lower())
|
||||
.one_or_none())
|
||||
|
@ -196,8 +195,7 @@ def get_tag_siblings(tag: model.Tag) -> List[model.Tag]:
|
|||
pt_alias1 = sa.orm.aliased(model.PostTag)
|
||||
pt_alias2 = sa.orm.aliased(model.PostTag)
|
||||
result = (
|
||||
db.session
|
||||
.query(tag_alias, sa.func.count(pt_alias2.post_id))
|
||||
db.session.query(tag_alias, sa.func.count(pt_alias2.post_id))
|
||||
.join(pt_alias1, pt_alias1.tag_id == tag_alias.tag_id)
|
||||
.join(pt_alias2, pt_alias2.post_id == pt_alias1.post_id)
|
||||
.filter(pt_alias2.tag_id == tag.tag_id)
|
||||
|
@ -234,8 +232,7 @@ def merge_tags(source_tag: model.Tag, target_tag: model.Tag) -> None:
|
|||
.where(alias1.tag_id == source_tag_id))
|
||||
update_stmt = (
|
||||
update_stmt
|
||||
.where(
|
||||
~sa.exists()
|
||||
.where(~sa.exists()
|
||||
.where(alias1.post_id == alias2.post_id)
|
||||
.where(alias2.tag_id == target_tag_id)))
|
||||
update_stmt = update_stmt.values(tag_id=target_tag_id)
|
||||
|
@ -249,8 +246,7 @@ def merge_tags(source_tag: model.Tag, target_tag: model.Tag) -> None:
|
|||
sa.sql.expression.update(alias1)
|
||||
.where(alias1.parent_id == source_tag_id)
|
||||
.where(alias1.child_id != target_tag_id)
|
||||
.where(
|
||||
~sa.exists()
|
||||
.where(~sa.exists()
|
||||
.where(alias2.child_id == alias1.child_id)
|
||||
.where(alias2.parent_id == target_tag_id))
|
||||
.values(parent_id=target_tag_id))
|
||||
|
@ -260,8 +256,7 @@ def merge_tags(source_tag: model.Tag, target_tag: model.Tag) -> None:
|
|||
sa.sql.expression.update(alias1)
|
||||
.where(alias1.child_id == source_tag_id)
|
||||
.where(alias1.parent_id != target_tag_id)
|
||||
.where(
|
||||
~sa.exists()
|
||||
.where(~sa.exists()
|
||||
.where(alias2.parent_id == alias1.parent_id)
|
||||
.where(alias2.child_id == target_tag_id))
|
||||
.values(child_id=target_tag_id))
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import os
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, Optional, Union, Tuple, List, Dict, Generator, TypeVar
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
import tempfile
|
||||
from typing import Any, Optional, Union, Tuple, List, Dict, Generator, TypeVar
|
||||
from datetime import datetime, timedelta
|
||||
from contextlib import contextmanager
|
||||
from szurubooru import errors
|
||||
|
||||
from szurubooru import errors
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
|
@ -86,6 +87,7 @@ def is_valid_email(email: Optional[str]) -> bool:
|
|||
|
||||
class dotdict(dict): # pylint: disable=invalid-name
|
||||
''' dot.notation access to dictionary attributes. '''
|
||||
|
||||
def __getattr__(self, attr: str) -> Any:
|
||||
return self.get(attr)
|
||||
|
||||
|
|
Loading…
Reference in a new issue