Beispiel #1
0
    def error(self, msg, *args, **kwargs):
        ...

    def critical(self, msg, *args, **kwargs):
        ...

    def exception(self, msg, *args, **kwargs):
        ...

    def log(self, level, msg, *args, **kwargs):
        ...


json: JSONModule = choice_in_order(["ujson", "hyperjson", "orjson"],
                                   do_import=True,
                                   default="json")
logging_module = choice_in_order(["loguru"], do_import=True, default="logging")

if logging_module.__name__ == "loguru":
    logger: Logger = getattr(logging_module, "logger")  # type: ignore

elif logging_module.__name__ == "logging":

    class LogMessage:
        def __init__(self, fmt, args):
            self.fmt = fmt
            self.args = args

        def __str__(self):
            return self.fmt.format(*self.args)
Beispiel #2
0
from choicelib import choice_in_order
import logging

json = choice_in_order(["ujson", "hyperjson", "orjson"],
                       do_import=True,
                       default="json")
logger = choice_in_order(["loguru"], do_import=True, default="logging")

if logger.__name__ == "logging":
    logger = logging.getLogger("vkbottle")
elif logger.__name__ == "loguru":
    logger = getattr(logger, "logger")
Beispiel #3
0
import pexpect as px
import typing
import re
import choicelib

from .syntax import SWI_PROMPT, SWI_ERROR, VAR, RES, SWI_MULTIPLE, MULTI_RES
from prolog.swipl.exception import (
    SWIExecutableNotFound,
    SWICompileError,
    SWIQueryError,
    SWIQueryTimeout,
)

json = choicelib.choice_in_order(["json", "ujson", "hyperjson", "orjson"],
                                 do_import=True)
QueryResponse = typing.Union[dict, bool]


class Swipl:
    """ Python interface to SWI Prolog (http://www.swi-prolog.org) """
    def __init__(self,
                 path_to_swipl: str = "/path/to/swipl",
                 args: typing.List[str] = None):
        """ Constructor method
        Usage: swipl( path, args )
        path - path to SWI executable (default: 'swipl')
        args - command line arguments (default: '-q +tty')
        self.engine becomes pexpect spawn instance of SWI Prolog shell
        Raises: SWIExecutableNotFound """
        if args is None:
            args = ["-q", "+tty"]