[misc] Sort imports with isort

This commit is contained in:
Martin Rey 2020-10-13 10:35:20 +02:00 committed by Maike
parent ff822bb58a
commit 2954f3700b
33 changed files with 134 additions and 100 deletions

View file

@ -18,11 +18,11 @@ Example:
"""
from argparse import ArgumentParser
from sys import argv
from nacl.secret import SecretBox
from nacl.utils import random
from pytoml import load
from sys import argv
config = {
'database_connection': 'sqlite:////tmp/kibicara.sqlite',

View file

@ -6,13 +6,12 @@
""" E-Mail handling. """
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from logging import getLogger
from smtplib import SMTP
from socket import getfqdn
logger = getLogger(__name__)

View file

@ -7,17 +7,18 @@
""" Entrypoint of Kibicara. """
from asyncio import run as asyncio_run
from logging import DEBUG, INFO, WARNING, basicConfig, getLogger
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from hypercorn.config import Config
from hypercorn.asyncio import serve
from hypercorn.config import Config
from kibicara.config import args, config
from kibicara.model import Mapping
from kibicara.platformapi import Spawner
from kibicara.webapi import router
from logging import basicConfig, DEBUG, getLogger, INFO, WARNING
logger = getLogger(__name__)

View file

@ -7,9 +7,10 @@
""" ORM Models for core. """
from databases import Database
from ormantic import Boolean, ForeignKey, Integer, Model, Text
from sqlalchemy import MetaData, create_engine
from kibicara.config import config
from ormantic import Boolean, Integer, ForeignKey, Model, Text
from sqlalchemy import create_engine, MetaData
class Mapping:

View file

@ -6,12 +6,12 @@
""" API classes for implementing bots for platforms. """
from asyncio import create_task, Queue
from enum import auto, Enum
from kibicara.model import BadWord, Trigger
from asyncio import Queue, create_task
from enum import Enum, auto
from logging import getLogger
from re import search, IGNORECASE
from re import IGNORECASE, search
from kibicara.model import BadWord, Trigger
logger = getLogger(__name__)

View file

@ -5,15 +5,15 @@
#
# SPDX-License-Identifier: 0BSD
from logging import getLogger
from smtplib import SMTPException
from kibicara import email
from kibicara.config import config
from kibicara.model import Hood
from kibicara.platformapi import Censor, Spawner
from kibicara.platforms.email.model import Email, EmailSubscribers
from kibicara.webapi.admin import to_token
from logging import getLogger
from smtplib import SMTPException
logger = getLogger(__name__)

View file

@ -9,15 +9,16 @@ from asyncio import run as asyncio_run
from email.parser import BytesParser
from email.policy import default
from email.utils import parseaddr
from fastapi import status
from kibicara.config import args, config
from kibicara.platforms.email.model import Email, EmailSubscribers
from logging import getLogger
from ormantic import NoMatch
from re import sub
from requests import post
from sys import stdin
from fastapi import status
from ormantic import NoMatch
from requests import post
from kibicara.config import args, config
from kibicara.platforms.email.model import Email, EmailSubscribers
logger = getLogger(__name__)

View file

@ -5,8 +5,9 @@
#
# SPDX-License-Identifier: 0BSD
from ormantic import ForeignKey, Integer, Model, Text
from kibicara.model import Hood, Mapping
from ormantic import Integer, ForeignKey, Model, Text
class Email(Model):

View file

@ -5,22 +5,23 @@
#
# SPDX-License-Identifier: 0BSD
from fastapi import APIRouter, Depends, HTTPException, Response, status
from kibicara import email
from kibicara.platforms.email.bot import spawner
from kibicara.platforms.email.model import Email, EmailSubscribers
from kibicara.platformapi import Message
from kibicara.config import config
from kibicara.webapi.admin import from_token, to_token
from kibicara.webapi.hoods import get_hood, get_hood_unauthorized
from logging import getLogger
from nacl import exceptions
from ormantic.exceptions import NoMatch
from os import urandom
from pydantic import BaseModel, validator
from smtplib import SMTPException
from sqlite3 import IntegrityError
from fastapi import APIRouter, Depends, HTTPException, Response, status
from nacl import exceptions
from ormantic.exceptions import NoMatch
from pydantic import BaseModel, validator
from kibicara import email
from kibicara.config import config
from kibicara.platformapi import Message
from kibicara.platforms.email.bot import spawner
from kibicara.platforms.email.model import Email, EmailSubscribers
from kibicara.webapi.admin import from_token, to_token
from kibicara.webapi.hoods import get_hood, get_hood_unauthorized
logger = getLogger(__name__)

View file

@ -3,14 +3,15 @@
#
# SPDX-License-Identifier: 0BSD
from aiogram import Bot, Dispatcher, exceptions, types
from asyncio import gather, sleep, CancelledError
from kibicara.platformapi import Censor, Message, Spawner
from kibicara.platforms.telegram.model import Telegram, TelegramUser
from asyncio import CancelledError, gather, sleep
from logging import getLogger
from ormantic.exceptions import NoMatch
from sqlite3 import IntegrityError
from aiogram import Bot, Dispatcher, exceptions, types
from ormantic.exceptions import NoMatch
from kibicara.platformapi import Censor, Message, Spawner
from kibicara.platforms.telegram.model import Telegram, TelegramUser
logger = getLogger(__name__)

View file

@ -3,8 +3,9 @@
#
# SPDX-License-Identifier: 0BSD
from ormantic import Boolean, ForeignKey, Integer, Model, Text
from kibicara.model import Hood, Mapping
from ormantic import Boolean, Integer, ForeignKey, Model, Text
class Telegram(Model):

View file

@ -3,17 +3,18 @@
#
# SPDX-License-Identifier: 0BSD
from aiogram.bot.api import check_token
from aiogram import exceptions
from fastapi import APIRouter, Depends, HTTPException, Response, status
from kibicara.platforms.telegram.bot import spawner
from kibicara.platforms.telegram.model import Telegram, TelegramUser
from kibicara.webapi.hoods import get_hood, get_hood_unauthorized
from logging import getLogger
from sqlite3 import IntegrityError
from aiogram import exceptions
from aiogram.bot.api import check_token
from fastapi import APIRouter, Depends, HTTPException, Response, status
from ormantic.exceptions import NoMatch
from pydantic import BaseModel, validator
from kibicara.platforms.telegram.bot import spawner
from kibicara.platforms.telegram.model import Telegram, TelegramUser
from kibicara.webapi.hoods import get_hood, get_hood_unauthorized
logger = getLogger(__name__)

View file

@ -4,8 +4,8 @@
#
# SPDX-License-Identifier: 0BSD
from kibicara.platforms.test.model import Test
from kibicara.platformapi import Censor, Spawner
from kibicara.platforms.test.model import Test
class TestBot(Censor):

View file

@ -3,8 +3,9 @@
#
# SPDX-License-Identifier: 0BSD
from ormantic import ForeignKey, Integer, Model
from kibicara.model import Hood, Mapping
from ormantic import Integer, ForeignKey, Model
class Test(Model):

View file

@ -4,14 +4,16 @@
#
# SPDX-License-Identifier: 0BSD
from sqlite3 import IntegrityError
from fastapi import APIRouter, Depends, HTTPException, Response, status
from kibicara.platforms.test.bot import spawner
from kibicara.platforms.test.model import Test
from kibicara.platformapi import Message
from kibicara.webapi.hoods import get_hood
from ormantic.exceptions import NoMatch
from pydantic import BaseModel
from sqlite3 import IntegrityError
from kibicara.platformapi import Message
from kibicara.platforms.test.bot import spawner
from kibicara.platforms.test.model import Test
from kibicara.webapi.hoods import get_hood
class BodyMessage(BaseModel):

View file

@ -3,13 +3,14 @@
#
# SPDX-License-Identifier: 0BSD
from asyncio import gather, sleep, CancelledError
from asyncio import CancelledError, gather, sleep
from logging import getLogger
from peony import PeonyClient, exceptions
from kibicara.config import config
from kibicara.platformapi import Censor, Message, Spawner
from kibicara.platforms.twitter.model import Twitter
from logging import getLogger
from peony import PeonyClient, exceptions
logger = getLogger(__name__)

View file

@ -3,8 +3,9 @@
#
# SPDX-License-Identifier: 0BSD
from ormantic import Boolean, ForeignKey, Integer, Model, Text
from kibicara.model import Hood, Mapping
from ormantic import Boolean, Integer, ForeignKey, Model, Text
class Twitter(Model):

View file

@ -3,18 +3,19 @@
#
# SPDX-License-Identifier: 0BSD
from logging import getLogger
from sqlite3 import IntegrityError
from fastapi import APIRouter, Depends, HTTPException, Response, status
from ormantic.exceptions import NoMatch
from peony.exceptions import NotAuthenticated
from peony.oauth_dance import get_access_token, get_oauth_token
from pydantic import BaseModel
from kibicara.config import config
from kibicara.platforms.twitter.bot import spawner
from kibicara.platforms.twitter.model import Twitter
from kibicara.webapi.hoods import get_hood, get_hood_unauthorized
from logging import getLogger
from sqlite3 import IntegrityError
from ormantic.exceptions import NoMatch
from peony.oauth_dance import get_oauth_token, get_access_token
from peony.exceptions import NotAuthenticated
from pydantic import BaseModel
logger = getLogger(__name__)

View file

@ -11,17 +11,17 @@ file to get included into the main application.
"""
from fastapi import APIRouter
from kibicara.platforms.test.webapi import router as test_router
from kibicara.platforms.email.webapi import router as email_router
from kibicara.platforms.telegram.webapi import router as telegram_router
from kibicara.platforms.test.webapi import router as test_router
from kibicara.platforms.twitter.webapi import router as twitter_router
from kibicara.platforms.twitter.webapi import twitter_callback_router
from kibicara.platforms.email.webapi import router as email_router
from kibicara.webapi.admin import router as admin_router
from kibicara.webapi.hoods import router as hoods_router
from kibicara.webapi.hoods.badwords import router as badwords_router
from kibicara.webapi.hoods.triggers import router as triggers_router
router = APIRouter()
router.include_router(admin_router, prefix='/admin', tags=['admin'])
hoods_router.include_router(

View file

@ -8,23 +8,24 @@
""" REST API endpoints for hood admins. """
from datetime import datetime, timedelta
from logging import getLogger
from pickle import dumps, loads
from smtplib import SMTPException
from sqlite3 import IntegrityError
from fastapi import APIRouter, Depends, HTTPException, Response, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from nacl.encoding import URLSafeBase64Encoder
from nacl.exceptions import CryptoError
from nacl.secret import SecretBox
from ormantic.exceptions import NoMatch
from passlib.hash import argon2
from pydantic import BaseModel, validator
from kibicara import email
from kibicara.config import config
from kibicara.model import Admin, AdminHoodRelation, Hood
from kibicara.webapi.utils import delete_hood
from logging import getLogger
from nacl.encoding import URLSafeBase64Encoder
from nacl.exceptions import CryptoError
from nacl.secret import SecretBox
from passlib.hash import argon2
from ormantic.exceptions import NoMatch
from pickle import dumps, loads
from pydantic import BaseModel, validator
from smtplib import SMTPException
from sqlite3 import IntegrityError
logger = getLogger(__name__)

View file

@ -6,14 +6,16 @@
""" REST API Endpoints for managing hoods. """
from sqlite3 import IntegrityError
from fastapi import APIRouter, Depends, HTTPException, Response, status
from ormantic.exceptions import NoMatch
from pydantic import BaseModel
from kibicara.model import AdminHoodRelation, Hood, Trigger
from kibicara.platforms.email.bot import spawner
from kibicara.webapi.admin import get_admin
from kibicara.webapi.utils import delete_hood
from ormantic.exceptions import NoMatch
from pydantic import BaseModel
from sqlite3 import IntegrityError
class BodyHood(BaseModel):

View file

@ -11,13 +11,16 @@ received message to be dropped by a censor. This provides a message filter custo
by the hood admins.
"""
from re import compile as regex_compile
from re import error as RegexError
from sqlite3 import IntegrityError
from fastapi import APIRouter, Depends, HTTPException, Response, status
from kibicara.model import BadWord
from kibicara.webapi.hoods import get_hood
from ormantic.exceptions import NoMatch
from pydantic import BaseModel
from re import compile as regex_compile, error as RegexError
from sqlite3 import IntegrityError
from kibicara.model import BadWord
from kibicara.webapi.hoods import get_hood
class BodyBadWord(BaseModel):

View file

@ -12,13 +12,16 @@ regular expressions otherwise it gets dropped by the censor. This provides a mes
filter customizable by the hood admins.
"""
from re import compile as regex_compile
from re import error as RegexError
from sqlite3 import IntegrityError
from fastapi import APIRouter, Depends, HTTPException, Response, status
from kibicara.model import Trigger
from kibicara.webapi.hoods import get_hood
from ormantic.exceptions import NoMatch
from pydantic import BaseModel
from re import compile as regex_compile, error as RegexError
from sqlite3 import IntegrityError
from kibicara.model import Trigger
from kibicara.webapi.hoods import get_hood
class BodyTrigger(BaseModel):

View file

@ -4,13 +4,15 @@
#
# SPDX-License-Identifier: 0BSD
from urllib.parse import urlparse
from fastapi import FastAPI, status
from fastapi.testclient import TestClient
from pytest import fixture
from kibicara import email
from kibicara.model import Mapping
from kibicara.webapi import router
from pytest import fixture
from urllib.parse import urlparse
@fixture(scope='module')

View file

@ -3,13 +3,15 @@
#
# SPDX-License-Identifier: 0BSD
from fastapi import status
from kibicara.webapi.admin import to_token
import subprocess
from pytest import skip
from re import findall
from urllib.parse import urlparse
from fastapi import status
from pytest import skip
from kibicara.webapi.admin import to_token
def test_email_subscribe_unsubscribe(client, hood_id, receive_email):
response = client.post(

View file

@ -3,9 +3,10 @@
#
# SPDX-License-Identifier: 0BSD
from pytest import fixture
from kibicara.model import Hood
from kibicara.platforms.telegram.model import Telegram
from pytest import fixture
@fixture(scope='function')

View file

@ -4,9 +4,10 @@
# SPDX-License-Identifier: 0BSD
from fastapi import status
from pytest import fixture, mark
from kibicara.platforms import telegram
from kibicara.platforms.telegram.model import Telegram
from pytest import fixture, mark
@fixture(scope='function')

View file

@ -4,10 +4,11 @@
# SPDX-License-Identifier: 0BSD
from fastapi import status
from kibicara.platforms.telegram.model import Telegram, TelegramUser
from ormantic.exceptions import NoMatch
from pytest import mark, raises
from kibicara.platforms.telegram.model import Telegram, TelegramUser
@mark.parametrize('bot', [{'api_token': 'apitoken123', 'welcome_message': 'msg'}])
def test_telegram_delete_bot(client, event_loop, bot, telegram, auth_header):

View file

@ -4,6 +4,7 @@
# SPDX-License-Identifier: 0BSD
from fastapi import status
from kibicara.model import Hood
from kibicara.platforms.telegram.model import Telegram

View file

@ -3,9 +3,10 @@
#
# SPDX-License-Identifier: 0BSD
from pytest import fixture
from kibicara.model import Hood
from kibicara.platforms.twitter.model import Twitter
from pytest import fixture
@fixture(scope='function')

View file

@ -4,10 +4,11 @@
# SPDX-License-Identifier: 0BSD
from fastapi import status
from pytest import fixture, mark
from kibicara import config
from kibicara.platforms import twitter
from kibicara.platforms.twitter.model import Twitter
from pytest import fixture, mark
@fixture(scope='function')

View file

@ -4,10 +4,11 @@
# SPDX-License-Identifier: 0BSD
from fastapi import status
from kibicara.platforms.twitter.model import Twitter
from ormantic.exceptions import NoMatch
from pytest import raises
from kibicara.platforms.twitter.model import Twitter
def test_twitter_delete_bot(client, event_loop, twitter, auth_header):
response = client.delete(

View file

@ -4,6 +4,7 @@
# SPDX-License-Identifier: 0BSD
from fastapi import status
from kibicara.model import Hood
from kibicara.platforms.twitter.model import Twitter