use relative imports
This commit is contained in:
parent
be98e94355
commit
d1357bc195
|
@ -5,7 +5,7 @@ from collections import OrderedDict
|
|||
from functools import update_wrapper
|
||||
from hashlib import sha1
|
||||
|
||||
from . import DotDict
|
||||
from .dotdict import DotDict
|
||||
|
||||
|
||||
def parse_ttl(ttl):
|
||||
|
|
|
@ -5,14 +5,18 @@ from dasbus.error import DBusError
|
|||
from dasbus.identifier import DBusServiceIdentifier
|
||||
from dasbus.loop import EventLoop
|
||||
from functools import partial
|
||||
from izzylib import DotDict, Path, logging
|
||||
from pathlib import Path as Pathlib
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from . import izzylog
|
||||
from .dotdict import DotDict
|
||||
from .exceptions import DBusClientError, DBusServerError
|
||||
from .path import Path
|
||||
|
||||
try:
|
||||
from .template import Template
|
||||
except ImportError:
|
||||
logging.verbose('Failed to import IzzyLib.template.Template. HAML templates will not be available')
|
||||
izzylog.verbose('Failed to import IzzyLib.template.Template. HAML templates will not be available')
|
||||
Template = None
|
||||
|
||||
|
||||
|
@ -80,7 +84,7 @@ class DBusClientBase(DBusBase):
|
|||
if not self.proxy:
|
||||
raise ConnectionError('Not connected')
|
||||
|
||||
logging.debug(f'Running dbus command: {command}, {args}, {kwargs}')
|
||||
izzylog.debug(f'Running dbus command: {command}, {args}, {kwargs}')
|
||||
|
||||
func = getattr(self.proxy, command)
|
||||
return func(*args, **kwargs)
|
||||
|
@ -112,7 +116,7 @@ class DBusClientBase(DBusBase):
|
|||
name = e.attrib['name']
|
||||
|
||||
if getattr(self, name, None):
|
||||
logging.verbose('Tried to add an existing method or signal:', name)
|
||||
izzylog.verbose('Tried to add an existing method or signal:', name)
|
||||
continue
|
||||
|
||||
if e.tag == 'method':
|
||||
|
@ -131,7 +135,7 @@ class DBusServerBase(DBusBase):
|
|||
|
||||
if type(xmlfile) in [Path, Pathlib]:
|
||||
if not Template:
|
||||
raise ServerError('Cannot use Template class since it failed to import')
|
||||
raise DBusServerError('Cannot use Template class since it failed to import')
|
||||
|
||||
xmlpath = Path(xmlfile)
|
||||
self.filename = xmlpath.name
|
||||
|
@ -183,7 +187,7 @@ class DBusJsonClientBase(DBusClientBase):
|
|||
message = data.get('message')
|
||||
|
||||
if error:
|
||||
raise ServerError(error)
|
||||
raise DBusServerError(error)
|
||||
|
||||
return message
|
||||
|
||||
|
@ -207,7 +211,7 @@ class DBusJsonClientBase(DBusClientBase):
|
|||
setattr(self, name, lambda *args, **kwargs: self.cmd(name, *args, **kwargs))
|
||||
|
||||
else:
|
||||
logging.warning('Tried to add an existing method:', name)
|
||||
izzylog.warning('Tried to add an existing method:', name)
|
||||
|
||||
|
||||
def Introspect(self):
|
||||
|
@ -298,11 +302,3 @@ class DBusSessionJsonServer(DBusJsonServerBase):
|
|||
class DBusSystemJsonServer(DBusJsonServerBase):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(SystemMessageBus, *args, **kwargs)
|
||||
|
||||
|
||||
class ClientError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ServerError(Exception):
|
||||
pass
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
|
||||
from . import Path
|
||||
from .path import Path
|
||||
|
||||
|
||||
class DotDict(dict):
|
||||
|
|
|
@ -1,2 +1,10 @@
|
|||
class DBusClientError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class DBusServerError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class HttpFileDownloadedError(Exception):
|
||||
'raise when a download failed for any reason'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import argon2, os
|
||||
|
||||
from izzylib import time_function_pprint
|
||||
from .misc import time_function_pprint
|
||||
|
||||
|
||||
class PasswordHasher:
|
||||
|
|
|
@ -7,10 +7,13 @@ from functools import cached_property
|
|||
from io import BytesIO
|
||||
from ssl import SSLCertVerificationError
|
||||
from urllib.error import HTTPError
|
||||
from urllib.parse import urlparse
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
from . import DefaultDotDict, DotDict, Path, exceptions, izzylog, __version__
|
||||
from . import izzylog, __version__
|
||||
from .dotdict import DefaultDotDict, DotDict
|
||||
from .exceptions import HttpFileDownloadedError
|
||||
from .misc import Url
|
||||
from .path import Path
|
||||
|
||||
try:
|
||||
from PIL import Image
|
||||
|
@ -92,10 +95,10 @@ class HttpClient:
|
|||
resp = self.request(url, *args, stream=True, **kwargs)
|
||||
|
||||
if not resp.headers.get('content-length'):
|
||||
raise exceptions.HttpFileDownloadedError('File already downloaded fully')
|
||||
raise HttpFileDownloadedError('File already downloaded fully')
|
||||
|
||||
if resp.status != 200:
|
||||
raise exceptions.HttpFileDownloadedError(f'Failed to download {url}: {resp.status}, body: {resp.body}')
|
||||
raise HttpFileDownloadedError(f'Failed to download {url}: {resp.status}, body: {resp.body}')
|
||||
|
||||
with filepath.open('ab') as fd:
|
||||
for chunk in resp.chunks(size):
|
||||
|
@ -119,7 +122,7 @@ class HttpClient:
|
|||
resp = self.request(url, *args, **kwargs)
|
||||
|
||||
if resp.status != 200:
|
||||
raise exceptions.HttpFileDownloadedError(f'Failed to download {url}: {resp.status}, body: {resp.body}')
|
||||
raise HttpFileDownloadedError(f'Failed to download {url}: {resp.status}, body: {resp.body}')
|
||||
|
||||
if not filename:
|
||||
filename = Path(url).stem
|
||||
|
@ -146,7 +149,7 @@ class HttpResponse(object):
|
|||
self.body = response.read()
|
||||
self.headers = DefaultDotDict({k.lower(): v.lower() for k,v in response.headers.items()})
|
||||
self.status = response.status
|
||||
self.url = response.url
|
||||
self.url = Url(response.url)
|
||||
|
||||
|
||||
@cached_property
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
from datetime import datetime
|
||||
|
||||
start_time = datetime.now()
|
||||
|
||||
from .application import Application
|
||||
from .config import Config, UserLevel
|
||||
from .middleware import MiddlewareBase, Headers, AccessLog
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import multiprocessing, sanic, signal, traceback
|
||||
import logging as pylog
|
||||
import logging,multiprocessing, sanic, signal, traceback
|
||||
|
||||
|
||||
from multidict import CIMultiDict
|
||||
from multiprocessing import cpu_count, current_process
|
||||
from urllib.parse import parse_qsl, urlparse
|
||||
|
||||
from izzylib import DotDict, Path, izzylog as logging
|
||||
from izzylib.template import Template
|
||||
from urllib.parse import parse_qsl
|
||||
|
||||
from .config import Config, UserLevel
|
||||
from .error_handlers import GenericError, MissingTemplateError
|
||||
from .middleware import AccessLog, Headers
|
||||
from .view import Manifest, Robots, Style
|
||||
|
||||
from .. import izzylog
|
||||
from ..dotdict import DotDict
|
||||
from ..path import Path
|
||||
from ..template import Template
|
||||
|
||||
|
||||
log_path_ignore = [
|
||||
'/media',
|
||||
|
@ -39,7 +40,7 @@ class Application(sanic.Sanic):
|
|||
super().__init__(self.cfg.name, request_class=self.cfg.request_class)
|
||||
|
||||
for log in ['sanic.root', 'sanic.access']:
|
||||
pylog.getLogger(log).setLevel(pylog.WARNING)
|
||||
logging.getLogger(log).setLevel(logging.WARNING)
|
||||
|
||||
self.template = Template(
|
||||
self.cfg.tpl_search,
|
||||
|
@ -153,7 +154,7 @@ class Application(sanic.Sanic):
|
|||
if self.cfg.workers > 1:
|
||||
msg += f' with {self.cfg.workers} workers'
|
||||
|
||||
logging.info(msg)
|
||||
izzylog.info(msg)
|
||||
super().run(
|
||||
host = self.cfg.listen,
|
||||
port = self.cfg.port,
|
||||
|
@ -168,7 +169,7 @@ class Application(sanic.Sanic):
|
|||
self.cfg.sig_handler(*self.cfg.sig_handler_args, **self.cfg.sig_handler_kwargs)
|
||||
|
||||
self.stop()
|
||||
logging.info('Bye! :3')
|
||||
izzylog.info('Bye! :3')
|
||||
|
||||
|
||||
def parse_level(level):
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
from enum import IntEnum
|
||||
from izzylib import DotDict
|
||||
from multiprocessing import cpu_count
|
||||
|
||||
from .request import Request
|
||||
from .response import Response
|
||||
|
||||
from ..dotdict import DotDict
|
||||
|
||||
|
||||
class UserLevel(IntEnum):
|
||||
GUEST = 0
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import traceback
|
||||
|
||||
from izzylib import izzylog as logging
|
||||
from jinja2.exceptions import TemplateNotFound
|
||||
|
||||
from .response import Response
|
||||
|
||||
from .. import izzylog
|
||||
|
||||
|
||||
class GenericError:
|
||||
error = Exception
|
||||
|
@ -45,5 +46,5 @@ class MissingTemplateError(GenericError):
|
|||
|
||||
|
||||
def handler(self, request, response, exception):
|
||||
logging.error('TEMPLATE_ERROR:', f'{exception.__class__.__name__}: {str(exception)}')
|
||||
izzylog.error('TEMPLATE_ERROR:', f'{exception.__class__.__name__}: {str(exception)}')
|
||||
return response.error('I\'m a dingleberry and forgot to create a template for this page', 500)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import multiprocessing
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from izzylib import izzylog as logging, logging as applog
|
||||
|
||||
from . import start_time
|
||||
from .response import Response
|
||||
|
||||
from .. import logging
|
||||
|
||||
|
||||
cache_types = [
|
||||
'text/css',
|
||||
|
@ -79,4 +79,4 @@ class AccessLog(MiddlewareBase):
|
|||
async def handler(self, request, response):
|
||||
uagent = request.headers.get('user-agent', 'None')
|
||||
|
||||
applog.info(f'({multiprocessing.current_process().name}) {request.address} {request.method} {request.path} {response.status} "{uagent}"')
|
||||
logging.info(f'({multiprocessing.current_process().name}) {request.address} {request.method} {request.path} {response.status} "{uagent}"')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
|
||||
from izzylib import LowerDotDict
|
||||
from ..dotdict import LowerDotDict
|
||||
|
||||
|
||||
def ReplaceHeader(headers, key, value):
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import sanic
|
||||
|
||||
from functools import cached_property
|
||||
from izzylib import DotDict
|
||||
from urllib.parse import parse_qsl
|
||||
|
||||
from .misc import Headers
|
||||
|
||||
from ..dotdict import DotDict
|
||||
|
||||
|
||||
class Request(sanic.request.Request):
|
||||
_extra = DotDict()
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import json, sanic
|
||||
|
||||
from datetime import datetime
|
||||
from izzylib import DotDict, izzylog
|
||||
from izzylib.template import Color
|
||||
from sanic.compat import Header
|
||||
from sanic.cookies import CookieJar
|
||||
from sanic.response import text as Raw
|
||||
|
||||
from .. import izzylog
|
||||
from ..dotdict import DotDict
|
||||
from ..template import Color
|
||||
|
||||
|
||||
class Response:
|
||||
content_types = DotDict({
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
from izzylib.template import Color
|
||||
from sanic.views import HTTPMethodView
|
||||
|
||||
from .response import Response
|
||||
|
||||
from ..template import Color
|
||||
|
||||
|
||||
class View(HTTPMethodView):
|
||||
routes = []
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import json, requests, sys
|
||||
|
||||
from PIL import Image
|
||||
import json, sys
|
||||
|
||||
from Crypto.Hash import SHA256
|
||||
from Crypto.PublicKey import RSA
|
||||
|
@ -8,10 +6,11 @@ from Crypto.Signature import PKCS1_v1_5
|
|||
from base64 import b64decode, b64encode
|
||||
from datetime import datetime
|
||||
from functools import lru_cache
|
||||
from izzylib import DefaultDotDict, DotDict
|
||||
from izzylib import izzylog
|
||||
from tldextract import extract
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from . import izzylog
|
||||
from .dotdict import DefaultDotDict, DotDict
|
||||
from .misc import Url
|
||||
|
||||
|
||||
def generate_rsa_key():
|
||||
|
@ -36,7 +35,7 @@ def parse_signature(signature: str):
|
|||
sig[key.lower()] = value.replace('"', '')
|
||||
|
||||
sig.headers = sig.headers.split()
|
||||
sig.domain = urlparse(sig.keyid).netloc
|
||||
sig.domain = Url(sig.keyid).host
|
||||
sig.top_domain = '.'.join(extract(sig.domain)[1:])
|
||||
sig.actor = sig.keyid.split('#')[0]
|
||||
|
||||
|
|
|
@ -6,14 +6,17 @@ from base64 import b64encode
|
|||
from datetime import datetime
|
||||
from functools import cached_property, lru_cache
|
||||
from io import BytesIO
|
||||
from izzylib import DefaultDotDict, DotDict, LowerDotDict, Path, izzylog as logging, __version__
|
||||
from izzylib.exceptions import HttpFileDownloadedError
|
||||
from ssl import SSLCertVerificationError
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from .request import HttpUrllibRequest
|
||||
from .response import HttpUrllibResponse
|
||||
|
||||
from .. import __version__
|
||||
from ..dotdict import DefaultDotDict, DotDict, LowerDotDict
|
||||
from ..exceptions import HttpFileDownloadedError
|
||||
from ..misc import Url
|
||||
from ..path import Path
|
||||
|
||||
|
||||
Client = None
|
||||
|
||||
|
@ -145,7 +148,7 @@ def fetch_actor(url):
|
|||
izzylog.debug(f'HTTP {resp.status}: {resp.body}')
|
||||
raise e from None
|
||||
|
||||
actor.web_domain = urlparse(url).netloc
|
||||
actor.web_domain = Url(url).host
|
||||
actor.shared_inbox = actor.inbox
|
||||
actor.pubkey = None
|
||||
actor.handle = actor.preferredUsername
|
||||
|
|
|
@ -2,7 +2,6 @@ import json, pkgutil, sys, threading, time
|
|||
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime
|
||||
from izzylib import LruCache, DotDict, Path, nfs_check, izzylog
|
||||
from sqlalchemy import Table, create_engine
|
||||
from sqlalchemy.exc import OperationalError, ProgrammingError
|
||||
from sqlalchemy.engine import URL
|
||||
|
@ -11,6 +10,11 @@ from sqlalchemy.schema import MetaData
|
|||
from .rows import RowClasses
|
||||
from .session import Session
|
||||
|
||||
from .. import izzylog
|
||||
from ..cache import LruCache
|
||||
from ..dotdict import DotDict
|
||||
from ..misc import nfs_check
|
||||
|
||||
|
||||
modules = dict(
|
||||
postgresql = ['pygresql', 'pg8000', 'psycopg2', 'psycopg3']
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
from izzylib import DotDict, random_gen, izzylog
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.orm.session import Session as sqlalchemy_session
|
||||
|
||||
from .. import izzylog
|
||||
from ..dotdict import DotDict
|
||||
from ..misc import random_gen
|
||||
|
||||
|
||||
class Session(sqlalchemy_session):
|
||||
def __init__(self, db, trans=False):
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import asyncio, json, socket, sqlite3, ssl, time, traceback
|
||||
|
||||
from izzylib import DotDict, JsonEncoder, Path, izzylog
|
||||
from .database import Database
|
||||
from .rows import RowClasses
|
||||
|
||||
from . import CustomRows, SqlDatabase
|
||||
from .. import izzylib
|
||||
from ..dotdict import DotDict, JsonEncoder
|
||||
from ..path import Path
|
||||
|
||||
|
||||
commands = [
|
||||
|
@ -22,7 +25,7 @@ class SqliteClient(object):
|
|||
})
|
||||
|
||||
self.session_class = session_class or SqliteSession
|
||||
self.classes = CustomRows()
|
||||
self.classes = RowClasses()
|
||||
|
||||
self._setup()
|
||||
|
||||
|
@ -183,7 +186,7 @@ class SqliteServer(DotDict):
|
|||
|
||||
|
||||
def open(self, database, new=False):
|
||||
db = SqlDatabase(dbtype='sqlite', database=self.path.join(database + '.sqlite3'))
|
||||
db = Database(dbtype='sqlite', database=self.path.join(database + '.sqlite3'))
|
||||
|
||||
if database != 'metadata' and not new:
|
||||
with self.get_database('metadata').session() as s:
|
||||
|
|
|
@ -3,12 +3,15 @@ import codecs, traceback, os, json, xml
|
|||
from colour import Color as Colour
|
||||
from functools import partial
|
||||
from hamlish_jinja import HamlishExtension
|
||||
from izzylib import izzylog, DotDict, Path
|
||||
from jinja2 import Environment, FileSystemLoader, ChoiceLoader, select_autoescape, Markup
|
||||
from os import listdir, makedirs
|
||||
from os.path import isfile, isdir, getmtime, abspath
|
||||
from xml.dom import minidom
|
||||
|
||||
from . import izzylog
|
||||
from .dotdict import DotDict
|
||||
from .path import Path
|
||||
|
||||
try:
|
||||
from sanic import response as Response
|
||||
|
||||
|
|
Loading…
Reference in a new issue