Ejemplo n.º 1
0
from attr import attrib, dataclass

from gd.colors import Color
from gd.logging import get_logger
from gd.typing import Any, Dict, Iterator, List, Sequence, Tuple, Union, ref
from gd.utils.enums import IconType
from gd.utils.text_tools import JSDict

log = get_logger(__name__)

try:
    from PIL import Image, ImageOps
    from PIL.Image import Image as ImageType
except ImportError:
    ImageType = ref("PIL.Image.Image")
    log.warning(
        "Failed to load Pillow/PIL. Icon Factory will not be supported.")

ALPHA = (0, 0, 0, 0)
COLOR_1 = Color(0x00FF00)
COLOR_2 = Color(0x00FFFF)
DARK = Color(0x808080)

ASSETS = Path(__file__).parent / "assets"

ROB_NAMES = {
    IconType.CUBE: "player",
    IconType.SHIP: "ship",
    IconType.BALL: "player_ball",
    IconType.UFO: "bird",
Ejemplo n.º 2
0
import io

from gd.typing import Sequence, ref

try:
    from PIL import Image
    from PIL.Image import Image as ImageType

except ImportError:
    ImageType = ref("PIL.Image.Image")
    print("Failed to load Pillow/PIL. Image creating will not be supported.")

DEFAULT_SIZE = 200


def to_image(data: bytes) -> ImageType:
    return Image.open(io.BytesIO(data))


def resize(image: ImageType,
           mode: str = "RGBA",
           size: int = DEFAULT_SIZE) -> ImageType:
    result = Image.new(mode=mode, size=(size, size))
    w, h = image.size
    # up-left corner
    x, y = size // 2 - w // 2, size // 2 - h // 2

    result.alpha_composite(image, (x, y))

    return result
Ejemplo n.º 3
0
import re

from attr import attrib, dataclass

from gd.typing import Generator, Union, ref
from gd.utils.text_tools import make_repr

__all__ = (
    "ENTRY_PATTERN",
    "Entry",
    "EntryArray",
    "iter_entries",
    "list_entries",
)

EntryType = ref("gd.api.verification_str.Entry")
Match = type(re.match("", ""))
Number = Union[float, int]


def number_from_str(string: str) -> Number:
    number = float(string)
    return int(number) if number.is_integer() else number


# [1;]n[.m];[1];[;]
ENTRY_PATTERN = re.compile(r"(?:(?P<prev>1);)?"  # [1;]
                           r"(?P<time>[0-9]+(?:\.[0-9]*)?);"  # n[.m];
                           r"(?P<next>1)?;"  # [1];
                           r"(?P<dual>;)?"  # [;]
                           )
Ejemplo n.º 4
0
    Tuple,
    Type,
    Union,
    ref,
)
import gd

AUTH_RE = re.compile(r"(?:Token )?(?P<token>[A-Fa-z0-9]+)")
CHUNK_SIZE = 64 * 1024
CLIENT = gd.Client()
JSON_PREFIX = "json_"

ROOT_PATH = Path(".gd")

Function = Callable[[Any], Any]
Error = ref("gd.server.Error")
Cooldown = ref("gd.server.Cooldown")
CooldownMapping = ref("gd.server.CooldownMapping")

routes = web.RouteTableDef()


class ErrorType(gd.Enum):
    DEFAULT = 13000
    INVALID_TYPE = 13001
    MISSING_PARAMETER = 13002
    ACCESS_RESTRICTED = 13003
    NOT_FOUND = 13004
    FAILED = 13005
    LOGIN_FAILED = 13006
    RATE_LIMIT_EXCEEDED = 13007
Ejemplo n.º 5
0
import functools
import platform

from aiohttp import web
import aiohttp
from gd.typing import Any, Callable, Dict, Iterable, List, Optional, Type, ref
import gd

DEFAULT_MIDDLEWARES = [
    web.normalize_path_middleware(append_slash=False, remove_slash=True)
]
CLIENT = gd.Client()

Function = Callable[[Any], Any]
Error = ref("gd.server.Error")

routes = web.RouteTableDef()


class Error:
    def __init__(self, resp_code: int, message: str, **additional) -> None:
        self.data = {
            "status": resp_code,
            "data": {
                "message": message,
                "exc": None,
                "exc_message": None,
                **additional
            },
        }