From 37de0904bc502358cada1be923b5bf2470e4cb94 Mon Sep 17 00:00:00 2001 From: romangraef Date: Sat, 18 Aug 2018 21:14:13 +0200 Subject: pylint stuff --- discord_ban_list/__init__.py | 8 ++++++-- discord_ban_list/api.py | 23 ++++++++++++++++++++++ discord_ban_list/result.py | 45 ++++++++++++++++++++++++++++++++++++++------ discord_ban_list/version.py | 2 +- setup.py | 2 +- tests/test_login.py | 4 ++-- 6 files changed, 72 insertions(+), 12 deletions(-) diff --git a/discord_ban_list/__init__.py b/discord_ban_list/__init__.py index 56976b2..a0fbd5c 100644 --- a/discord_ban_list/__init__.py +++ b/discord_ban_list/__init__.py @@ -1,9 +1,13 @@ +""" +Module for looking up entries/users on the bans.discord.id +""" + from .api import DiscordBanList from .result import BanABC, NoBan, Ban -from .version import VersionInfo, version +from .version import VersionInfo, VERSION __all__ = ( - 'VersionInfo', 'version', + 'VersionInfo', 'VERSION', 'DiscordBanList', 'BanABC', 'Ban', 'NoBan', ) diff --git a/discord_ban_list/api.py b/discord_ban_list/api.py index a9aec10..35e8c8a 100644 --- a/discord_ban_list/api.py +++ b/discord_ban_list/api.py @@ -1,3 +1,7 @@ +""" +Central API module. Most action taskes place here +""" + from asyncio import Lock from typing import Union @@ -9,17 +13,36 @@ CHECK_URL = 'https://bans.discord.id/api/check.php' class DiscordBanList(object): + """ + API wrapper for the ban list with a given token. + """ + __slots__ = ('token', '_client', '_client_lock') def __init__(self, token: str, _client: ClientSession = None): + """ + + :param token: the generated token for the ban list. see http://bans.discord.id/ + :param _client: pass a value here if you want to use a shared client. + Leave empty to autoinitialize + """ self.token = token self._client = _client self._client_lock = Lock() async def login(self): + """ + Login the client in. E.g. check the client session is loaded. + """ await self._guarantee_client() async def check(self, user_id: Union[int, str]) -> BanABC: + """ + Check if a user is banned on DBans + + :param user_id: id of the user to be checked + :return: a :class:`BanABC` + """ resp = await self._get('{base}?user_id={user_id}'.format(base=CHECK_URL, user_id=user_id)) if resp['banned'] == "0": return NoBan(user_id) diff --git a/discord_ban_list/result.py b/discord_ban_list/result.py index bde3e2b..9d1a685 100644 --- a/discord_ban_list/result.py +++ b/discord_ban_list/result.py @@ -1,28 +1,54 @@ +""" +Data classes for DBans +""" from abc import ABC, abstractproperty, abstractmethod from typing import Union, Optional class BanABC(ABC): + """ + Base class for bans. Don't use this. Use :class:`Ban` or :class:`NoBan`. + """ __slots__ = () @abstractproperty def user_id(self) -> int: + """ + + :return: user id + """ pass @abstractproperty def banned(self) -> bool: + """ + + :return: whether the user is banned or not + """ pass @abstractproperty def reason(self) -> Optional[str]: + """ + + :return: the ban reason or none if not banned + """ pass @abstractproperty def case_id(self) -> Optional[int]: + """ + + :return: the case id or none if not banned + """ pass @abstractproperty def proof(self) -> Optional[str]: + """ + + :return: the proof or none if not banned + """ pass @abstractmethod @@ -31,6 +57,9 @@ class BanABC(ABC): class Ban(BanABC): + """ + Represents a DBan entry of a *banned* user. + """ __slots__ = ('_proof', '_user_id', '_case_id', '_reason') def __init__(self, user_id: Union[int, str], reason: str, case_id: Union[str, int], proof: str): @@ -60,12 +89,13 @@ class Ban(BanABC): return self._proof def __str__(self): - return ''.format( - user=self.user_id, - case=self.case_id, - reason=self.reason, - proof=self.proof, - ) + return ''.format \ + (user=self.user_id, + case=self.case_id, + reason=self.reason, + proof=self.proof, + ) def __eq__(self, other): if not isinstance(other, Ban): @@ -75,6 +105,9 @@ class Ban(BanABC): class NoBan(BanABC): + """ + Represents a DBan entry of a *safe* user. + """ __slots__ = ('_user_id',) def __init__(self, user_id: Union[str, int]): diff --git a/discord_ban_list/version.py b/discord_ban_list/version.py index 3fc3d54..124f28f 100644 --- a/discord_ban_list/version.py +++ b/discord_ban_list/version.py @@ -28,4 +28,4 @@ class VersionInfo: return str(self) -version = VersionInfo(1, 0, 0, 'a', 0) +VERSION = VersionInfo(1, 0, 0, 'a', 0) diff --git a/setup.py b/setup.py index 2bece50..c632b52 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup with open('discord_ban_list/version.py') as fp: _loc, _glob = {}, {} exec(fp.read(), _loc, _glob) - version = {**_loc, **_glob}['version'] + version = {**_loc, **_glob}['VERSION'] with open('requirements.txt') as fp: requirements = fp.read().splitlines() diff --git a/tests/test_login.py b/tests/test_login.py index fb8f086..79b1747 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -20,8 +20,8 @@ async def a_test_banned(): assert ban.banned assert ban.user_id == user assert ban.case_id == 9999 - assert ban.reason == "THIS IS A VIRTUAL DBANS API TESTING ACCOUNT" - assert ban.proof == "https://yourmom-is.gae" + assert ban.reason + assert ban.proof class TestSomething(TestCase): -- cgit