Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

v0.7.0 preparing version #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# mod.io

> [!WARNING]
> This project is now archived, feel free to fork it.

![mod.io Logo](https://static.mod.io/v1/images/branding/modio-color-dark.png "https://mod.io")
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# The short X.Y version
version = ""
# The full version, including alpha/beta/rc tags
release = "0.6.0"
release = "0.7.0"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion modio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from .errors import *
from .mod import *

__version__ = "0.6.1"
__version__ = "0.7.0"
14 changes: 10 additions & 4 deletions modio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@

MAX_TRIES = 2


class Connection:
"""Class handling under the hood requests and ratelimits."""

def __init__(self, api_path, api_key, access_token, lang, version, test, platform, portal, ratelimit_max_sleep):
def __init__(
self, api_path, api_key, access_token, lang, version, test, platform, portal, ratelimit_max_sleep
):
self.test = test
self.version = version
self.api_path = api_path
Expand Down Expand Up @@ -262,6 +265,9 @@ class Client:

Parameters
-----------
api_path: str
The api path is the "root" from which you will access the api. This has two format: "g-<game_id>"
for a game root path or "u-<user_id>" for a user root path.
api_key : Optional[str]
The api key that will be used to authenticate the bot while it makes most of
its GET requests. This can be generated on the mod.io website. Optional if an access
Expand Down Expand Up @@ -300,15 +306,15 @@ class Client:
def __init__(
self,
*,
api_path=None,
api_path,
api_key=None,
access_token=None,
lang="en",
version="v1",
test=False,
platform=None,
portal=None,
ratelimit_max_sleep=math.inf
ratelimit_max_sleep=math.inf,
):
self.lang = lang
self.version = version
Expand All @@ -322,7 +328,7 @@ def __init__(
lang=lang,
platform=platform,
portal=portal,
ratelimit_max_sleep=ratelimit_max_sleep
ratelimit_max_sleep=ratelimit_max_sleep,
)

def __repr__(self):
Expand Down
32 changes: 15 additions & 17 deletions modio/entities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Module for miscs objects."""
import time
import json
from typing import List

from .mixins import OwnerMixin, RatingMixin, ReportMixin, StatsMixin
from .errors import modioException
Expand Down Expand Up @@ -406,23 +406,22 @@ async def async_delete(self):
)
return resp


def manage_platforms(self, approved:list[str]=None, denied:list[str]=None):
def manage_platforms(self, approved: List[str] = None, denied: List[str] = None):
"""Manage the platform status of this mod file. Returns an updated
instances of the file.
instances of the file.

Parameters
-----------
approved : str
Change the release version of the file
denied : str
Change the changelog of this release
Parameters
-----------
approved : str
Change the release version of the file
denied : str
Change the changelog of this release

Returns
--------
ModFile
The updated file
"""
Returns
--------
ModFile
The updated file
"""

if approved is None:
approved = []
Expand All @@ -446,7 +445,7 @@ def manage_platforms(self, approved:list[str]=None, denied:list[str]=None):

return self.__class__(connection=self.connection, game_id=self.game_id, **file_json)

async def manage_platforms_async(self, approved:list[str]=None, denied:list[str]=None):
async def manage_platforms_async(self, approved: List[str] = None, denied: List[str] = None):
if approved is None:
approved = []
if denied is None:
Expand All @@ -469,7 +468,6 @@ async def manage_platforms_async(self, approved:list[str]=None, denied:list[str]

return self.__class__(connection=self.connection, game_id=self.game_id, **file_json)


def url_is_expired(self):
"""Check if the url is still valid for this modfile.

Expand Down
7 changes: 5 additions & 2 deletions modio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,16 @@ def retry_logic(*args, **kwargs):
except modioException as e:
if e.code != 429 or args[0].ratelimit_max_sleep == 0:
raise e

error = e

raise error

return retry_logic

return wrapper


def async_ratelimit_retry(max_retries):
def wrapper(func):
@wraps(func)
Expand All @@ -187,10 +189,11 @@ async def retry_logic(*args, **kwargs):
except modioException as e:
if e.code != 429 or args[0].ratelimit_max_sleep == 0:
raise e

error = e

raise error

return retry_logic

return wrapper
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp==3.8.1
aiohttp==3.8.5
requests==2.31.0
typing-extensions==4.3.0

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
long_description_content_type="text/markdown",
long_description=readme,
packages=find_packages(include=["modio", "modio.*"]),
install_requires=["aiohttp==3.8.1", "requests==2.31.0", "typing-extensions==4.3.0"],
install_requires=["aiohttp==3.8.5", "requests==2.31.0", "typing-extensions==4.3.0"],
)
18 changes: 10 additions & 8 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,18 @@ def test_portal(self):
assert "X-Modio-Portal" in headers
assert headers["X-Modio-Portal"] is modio.enums.TargetPortal.facebook.value

@pytest.mark.parametrize("retry_after, max_sleep, expected", [
(60, 0, False),
(60, 60, True),
(0, 60, True),
(60, 3600, True)
])
@pytest.mark.parametrize(
"retry_after, max_sleep, expected", [(60, 0, False), (60, 60, True), (0, 60, True), (60, 3600, True)]
)
@mock.patch("time.sleep")
def test_ratelimit(self, sleep_mock, retry_after, max_sleep, expected):
client = modio.Client(access_token=access_token, test=use_test_env, ratelimit_max_sleep=max_sleep)
with pytest.raises(modioException):
client.connection._post_process(FakeRequest(status_code=429, headers={"retry-after": retry_after}, json_data={"error": {"code": "", "message": "", "error_ref": ""}}))
client.connection._post_process(
FakeRequest(
status_code=429,
headers={"retry-after": retry_after},
json_data={"error": {"code": "", "message": "", "error_ref": ""}},
)
)
assert sleep_mock.called == expected

8 changes: 4 additions & 4 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_comment(self):
comments = self.mod.get_comments().results
if not comments:
return

comment = comments[0]

comment.edit("test edit")
Expand All @@ -73,7 +73,7 @@ def test_async_comment(self):
comments = run(self.mod.async_get_comments()).results
if not comments:
return

comment = comments[0]

run(comment.async_edit("test edit async"))
Expand Down Expand Up @@ -198,13 +198,13 @@ def tearDown(self):
def test_mute(self):
with pytest.raises(modioException):
self.member.mute()

self.member.unmute()

def test_async_mute(self):
with pytest.raises(modioException):
run(self.member.async_mute())

run(self.member.async_unmute())


Expand Down
Loading