From 9806bcf82ef8f59a881f47c3b7027b4571cabf0c Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 23 Aug 2019 21:48:26 +0100 Subject: [PATCH] Move all enums and constants into their own module --- bootstrap.py | 4 +--- config.sample.py | 2 +- houdini/__init__.py | 38 +++++++----------------------- houdini/commands.py | 3 ++- houdini/constants.py | 33 ++++++++++++++++++++++++++ houdini/handlers/__init__.py | 6 +---- houdini/handlers/login/__init__.py | 3 ++- houdini/handlers/login/login.py | 8 +++---- houdini/handlers/login/world.py | 3 ++- houdini/handlers/play/buddy.py | 2 +- houdini/handlers/play/player.py | 3 ++- houdini/handlers/play/toy.py | 3 ++- 12 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 houdini/constants.py diff --git a/bootstrap.py b/bootstrap.py index 1ddc015..40b28b3 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -4,9 +4,7 @@ import argparse import config from houdini.houdini import Houdini -from houdini import ConflictResolution -from houdini import Language -from houdini import ClientType +from houdini.constants import ConflictResolution, Language, ClientType if __name__ == '__main__': logger = logging.getLogger('houdini') diff --git a/config.sample.py b/config.sample.py index 08fc4da..6f36321 100644 --- a/config.sample.py +++ b/config.sample.py @@ -1,4 +1,4 @@ -from houdini import ConflictResolution, Language, ClientType +from houdini.constants import ConflictResolution, Language, ClientType database = { 'Address': 'localhost', diff --git a/houdini/__init__.py b/houdini/__init__.py index 0d7e380..7549eba 100644 --- a/houdini/__init__.py +++ b/houdini/__init__.py @@ -3,42 +3,22 @@ from types import FunctionType from abc import abstractmethod import asyncio -import enum import logging import importlib import pkgutil -class StatusField(enum.IntEnum): - OpenedIglooViewer = 1 - ActiveIglooLayoutOpenFlag = 2 - PuffleTreasureInfographic = 512 - PlayerOptInAbTestDayZero = 1024 - PlayerSwapPuffle = 2048 - MoreThanTenPufflesBackyardMessage = 4096 - VisitBackyardFirstTime = 8192 - HasWalkedPuffleFirstTime = 65536 - HasWalkedPuffleSecondTime = 131072 +def get_package_modules(package): + package_modules = [] + for importer, module_name, is_package in pkgutil.iter_modules(package.__path__): + full_module_name = f'{package.__name__}.{module_name}' + subpackage_object = importlib.import_module(full_module_name, package=package.__path__) + if is_package: + sub_package_modules = get_package_modules(subpackage_object) package_modules = package_modules + sub_package_modules -class ConflictResolution(enum.Enum): - Silent = 0 - Append = 1 - Exception = 2 - - -class Language(enum.IntEnum): - En = 1 - Pt = 2 - Fr = 4 - Es = 8 - De = 32 - Ru = 64 - - -class ClientType(enum.Enum): - Legacy = 'legacy' - Vanilla = 'vanilla' + package_modules.append(subpackage_object) + return package_modules class _AbstractManager(dict): diff --git a/houdini/commands.py b/houdini/commands.py index 5718ea0..9504ea8 100644 --- a/houdini/commands.py +++ b/houdini/commands.py @@ -3,7 +3,8 @@ import config from houdini import handlers from houdini import plugins -from houdini import ConflictResolution, _AbstractManager +from houdini import _AbstractManager +from houdini.constants import ConflictResolution from houdini.converters import _ArgumentDeserializer, _listener diff --git a/houdini/constants.py b/houdini/constants.py new file mode 100644 index 0000000..519a10b --- /dev/null +++ b/houdini/constants.py @@ -0,0 +1,33 @@ +import enum + + +class StatusField(enum.IntEnum): + OpenedIglooViewer = 1 + ActiveIglooLayoutOpenFlag = 2 + PuffleTreasureInfographic = 512 + PlayerOptInAbTestDayZero = 1024 + PlayerSwapPuffle = 2048 + MoreThanTenPufflesBackyardMessage = 4096 + VisitBackyardFirstTime = 8192 + HasWalkedPuffleFirstTime = 65536 + HasWalkedPuffleSecondTime = 131072 + + +class ConflictResolution(enum.Enum): + Silent = 0 + Append = 1 + Exception = 2 + + +class Language(enum.IntEnum): + En = 1 + Pt = 2 + Fr = 4 + Es = 8 + De = 32 + Ru = 64 + + +class ClientType(enum.Enum): + Legacy = 'legacy' + Vanilla = 'vanilla' diff --git a/houdini/handlers/__init__.py b/houdini/handlers/__init__.py index 4ce805a..482300a 100644 --- a/houdini/handlers/__init__.py +++ b/houdini/handlers/__init__.py @@ -1,15 +1,11 @@ import inspect import enum import itertools -import importlib -import sys -import config from types import FunctionType from houdini.converters import _listener, _ArgumentDeserializer, get_converter, do_conversion, _ConverterContext - from houdini.cooldown import _Cooldown, _CooldownMapping, BucketType -from houdini import plugins, _AbstractManager +from houdini import plugins, _AbstractManager, get_package_modules class AuthorityError(Exception): diff --git a/houdini/handlers/login/__init__.py b/houdini/handlers/login/__init__.py index 59cd2d4..6bf746a 100644 --- a/houdini/handlers/login/__init__.py +++ b/houdini/handlers/login/__init__.py @@ -1,8 +1,9 @@ import config -from houdini import handlers, ClientType +from houdini import handlers from houdini.handlers import XMLPacket from houdini.converters import VersionChkConverter +from houdini.constants import ClientType from houdini.data.buddy import BuddyList diff --git a/houdini/handlers/login/login.py b/houdini/handlers/login/login.py index 99f982e..e8cb060 100644 --- a/houdini/handlers/login/login.py +++ b/houdini/handlers/login/login.py @@ -1,10 +1,11 @@ -from houdini import handlers, ClientType -from houdini.handlers import XMLPacket, login +from houdini import handlers +from houdini.handlers import XMLPacket from houdini.handlers.login import get_server_presence from houdini.converters import Credentials from houdini.data.penguin import Penguin from houdini.data.moderator import Ban from houdini.crypto import Crypto +from houdini.constants import ClientType import asyncio import bcrypt @@ -97,6 +98,3 @@ async def handle_login(p, credentials: Credentials): data.email) else: await p.send_xt('l', data.id, login_key, world_populations, buddy_presence) - -handle_version_check = login.handle_version_check -handle_random_key = login.handle_random_key diff --git a/houdini/handlers/login/world.py b/houdini/handlers/login/world.py index 445a379..0daee82 100644 --- a/houdini/handlers/login/world.py +++ b/houdini/handlers/login/world.py @@ -1,11 +1,12 @@ import config -from houdini import handlers, ClientType +from houdini import handlers from houdini.handlers import XMLPacket, login from houdini.converters import WorldCredentials, Credentials from houdini.data.penguin import Penguin from houdini.data.moderator import Ban from houdini.crypto import Crypto +from houdini.constants import ClientType from datetime import datetime diff --git a/houdini/handlers/play/buddy.py b/houdini/handlers/play/buddy.py index a512f39..050afe9 100644 --- a/houdini/handlers/play/buddy.py +++ b/houdini/handlers/play/buddy.py @@ -4,7 +4,7 @@ from houdini.handlers.play.navigation import handle_join_room from houdini.data.penguin import Penguin from houdini.data.buddy import BuddyList, BuddyRequest -from houdini import ClientType +from houdini.constants import ClientType async def update_player_presence(p): diff --git a/houdini/handlers/play/player.py b/houdini/handlers/play/player.py index 9e95ea9..f8b16dd 100644 --- a/houdini/handlers/play/player.py +++ b/houdini/handlers/play/player.py @@ -1,6 +1,7 @@ -from houdini import handlers, ClientType +from houdini import handlers from houdini.handlers import XTPacket from houdini.data.penguin import Penguin +from houdini.constants import ClientType from aiocache import cached import random diff --git a/houdini/handlers/play/toy.py b/houdini/handlers/play/toy.py index 388414a..ce1bd3f 100644 --- a/houdini/handlers/play/toy.py +++ b/houdini/handlers/play/toy.py @@ -1,5 +1,6 @@ -from houdini import handlers, ClientType +from houdini import handlers from houdini.handlers import XTPacket +from houdini.constants import ClientType @handlers.handler(XTPacket('t', 'at'))