core, CLI (base), tools (common/data_format): typing/core readability
This commit is contained in:
parent
84e6d9ceb2
commit
a74f9327f2
3 changed files with 37 additions and 29 deletions
|
|
@ -16,61 +16,67 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import time
|
||||
import asyncio
|
||||
from asyncio.subprocess import PIPE
|
||||
import copy
|
||||
from datetime import datetime
|
||||
from asyncio.subprocess import PIPE
|
||||
from pathlib import Path
|
||||
from typing import Union, Dict, List, Tuple, Iterable, Any, Callable, Optional
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, AsyncEngine, create_async_engine
|
||||
from sqlalchemy.exc import IntegrityError, NoResultFound
|
||||
from sqlalchemy.orm import (
|
||||
sessionmaker, subqueryload, joinedload, selectinload, contains_eager
|
||||
)
|
||||
from sqlalchemy.orm.decl_api import DeclarativeMeta
|
||||
from sqlalchemy.orm.attributes import Mapped
|
||||
from sqlalchemy.future import select
|
||||
from sqlalchemy.engine import Engine, Connection
|
||||
from sqlalchemy import update, delete, and_, or_, event, func
|
||||
from sqlalchemy.sql.functions import coalesce, sum as sum_, now, count
|
||||
from sqlalchemy.dialects.sqlite import insert
|
||||
from sqlalchemy import text, literal_column, Integer
|
||||
from alembic import script as al_script, config as al_config
|
||||
import sys
|
||||
import time
|
||||
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
|
||||
|
||||
from alembic import config as al_config, script as al_script
|
||||
from alembic.runtime import migration as al_migration
|
||||
from sqlalchemy import and_, delete, event, func, or_, update
|
||||
from sqlalchemy import Integer, literal_column, text
|
||||
from sqlalchemy.dialects.sqlite import insert
|
||||
from sqlalchemy.engine import Connection, Engine
|
||||
from sqlalchemy.exc import IntegrityError, NoResultFound
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, create_async_engine
|
||||
from sqlalchemy.future import select
|
||||
from sqlalchemy.orm import (
|
||||
contains_eager,
|
||||
joinedload,
|
||||
selectinload,
|
||||
sessionmaker,
|
||||
subqueryload,
|
||||
)
|
||||
from sqlalchemy.orm.attributes import Mapped
|
||||
from sqlalchemy.orm.decl_api import DeclarativeMeta
|
||||
from sqlalchemy.sql.functions import coalesce, count, now, sum as sum_
|
||||
from twisted.internet import defer
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.words.xish import domish
|
||||
from sat.core.i18n import _
|
||||
|
||||
from sat.core import exceptions
|
||||
from sat.core.log import getLogger
|
||||
from sat.core.constants import Const as C
|
||||
from sat.core.core_types import SatXMPPEntity
|
||||
from sat.tools.utils import aio, as_future
|
||||
from sat.tools.common import uri
|
||||
from sat.core.i18n import _
|
||||
from sat.core.log import getLogger
|
||||
from sat.memory import migration
|
||||
from sat.memory import sqla_config
|
||||
from sat.memory.sqla_mapping import (
|
||||
NOT_IN_EXTRA,
|
||||
SyncState,
|
||||
Base,
|
||||
Profile,
|
||||
Component,
|
||||
File,
|
||||
History,
|
||||
Message,
|
||||
Subject,
|
||||
Thread,
|
||||
NOT_IN_EXTRA,
|
||||
ParamGen,
|
||||
ParamInd,
|
||||
PrivateGen,
|
||||
PrivateInd,
|
||||
PrivateGenBin,
|
||||
PrivateInd,
|
||||
PrivateIndBin,
|
||||
File,
|
||||
PubsubNode,
|
||||
Profile,
|
||||
PubsubItem,
|
||||
PubsubNode,
|
||||
Subject,
|
||||
SyncState,
|
||||
Thread,
|
||||
)
|
||||
from sat.tools.common import uri
|
||||
from sat.tools.utils import aio, as_future
|
||||
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
""" tools common to backend and frontends """
|
||||
# FIXME: json may be more appropriate than manual serialising like done here
|
||||
|
||||
from typing import Any
|
||||
|
||||
from sat.core import exceptions
|
||||
import json
|
||||
|
||||
|
|
@ -133,7 +135,7 @@ def serialise(data):
|
|||
"""
|
||||
return json.dumps(data, ensure_ascii=False, default=str)
|
||||
|
||||
def deserialise(serialised_data, default=None, type_check=dict):
|
||||
def deserialise(serialised_data: str, default: Any = None, type_check: type = dict):
|
||||
"""Deserialize data from bridge
|
||||
|
||||
@param serialised_data(unicode): data to deserialise
|
||||
|
|
|
|||
|
|
@ -1255,7 +1255,7 @@ class CommandBase(object):
|
|||
"""Helper method to compute extra data from pubsub arguments
|
||||
|
||||
@param extra: base extra dict, or None to generate a new one
|
||||
@return: dict which can be used directly in the bridge for pubsub
|
||||
@return: serialised dict which can be used directly in the bridge for pubsub
|
||||
"""
|
||||
if extra is None:
|
||||
extra = {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue