Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move mojang/api/utils/* into mojang/api #28

Merged
merged 6 commits into from
Feb 10, 2022
Merged
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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ repos:
- id: check-toml
- id: check-yaml
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
name: isort
args: [--profile, black, -l, '79']
- repo: https://github.com/psf/black
rev: 21.9b0
hooks:
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
sys.path.insert(0, os.path.abspath(".."))
import mojang


# -- Project information -----------------------------------------------------

project = "PyMojang"
Expand Down
5 changes: 3 additions & 2 deletions examples/microsoft_flask/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os

import mojang
import mojang.exceptions
from dotenv import load_dotenv
from flask import Flask, jsonify, redirect, request

import mojang
import mojang.exceptions

load_dotenv()

app = Flask(__name__)
Expand Down
17 changes: 8 additions & 9 deletions mojang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@

Checkout the [`documentation`](https://pymojang.readthedocs.io/en/latest/)
"""
from . import _version
from .api import (
get_uuid,
get_uuids,
get_username,
get_names,
get_status,
connect,
get_blocked_servers,
get_sales,
get_names,
get_profile,
connect,
get_sales,
get_status,
get_username,
get_uuid,
get_uuids,
microsoft_app,
)

from . import _version

__version__ = _version.get_versions()["version"]
12 changes: 6 additions & 6 deletions mojang/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from .base import (
get_status,
get_sales,
get_blocked_servers,
get_uuid,
get_uuids,
get_username,
get_names,
get_profile,
get_sales,
get_status,
get_username,
get_uuid,
get_uuids,
)
from .ext.session import connect
from .ext.microsoft import microsoft_app
from .ext.session import connect
3 changes: 2 additions & 1 deletion mojang/api/auth/microsoft.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from typing import Tuple

import requests

from mojang.exceptions import (
Unauthorized,
XboxLiveAuthenticationError,
XboxLiveInvalidUserHash,
)

from ..utils import helpers, urls
from .. import helpers, urls


def authenticate_xbl(auth_token: str) -> Tuple[str, str]:
Expand Down
2 changes: 1 addition & 1 deletion mojang/api/auth/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import requests

from ...exceptions import Unauthorized
from .. import helpers, urls
from ..structures.auth import ChallengeInfo
from ..utils import helpers, urls


def check_ip(access_token: str) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion mojang/api/auth/yggdrasil.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests

from ...exceptions import CredentialsError, MigratedAccount, TokenError
from ..utils import urls, helpers
from .. import helpers, urls


def authenticate(
Expand Down
11 changes: 2 additions & 9 deletions mojang/api/base.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import base64
import datetime as dt
import json
from typing import (
Dict,
Iterable,
List,
Optional,
Sequence,
Tuple,
)
from typing import Dict, Iterable, List, Optional, Sequence, Tuple

import requests

from ..exceptions import InvalidName
from . import helpers, urls
from .structures.base import NameInfo, ServiceStatus
from .structures.profile import UnauthenticatedProfile
from .structures.session import Cape, Skin
from .utils import helpers, urls


def get_status() -> List[ServiceStatus]:
Expand Down
4 changes: 2 additions & 2 deletions mojang/api/ext/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from .. import session
from ..auth import microsoft, security, yggdrasil
from ..structures.profile import Cape, Skin
from ..structures.base import NameInfo
from ..structures.auth import ChallengeInfo
from ..structures.base import NameInfo
from ..structures.profile import Cape, Skin


class AuthenticatedUser(metaclass=ABCMeta):
Expand Down
1 change: 1 addition & 0 deletions mojang/api/ext/microsoft.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import msal

from mojang.exceptions import MicrosoftInvalidGrant, MicrosoftUserNotOwner

from .. import session
Expand Down
9 changes: 5 additions & 4 deletions mojang/api/utils/helpers.py → mojang/api/helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import inspect
import json
from typing import Optional

import requests
import json
import inspect
from uuid import UUID
from ...exceptions import NotFound, MethodNotAllowed, ServerError

from ..exceptions import MethodNotAllowed, NotFound, ServerError


def get_headers(
Expand Down
2 changes: 1 addition & 1 deletion mojang/api/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
Unauthorized,
UnavailableName,
)
from . import helpers, urls
from .base import get_names
from .structures.profile import AuthenticatedUserProfile
from .structures.session import Cape, NameChange, Skin
from .utils import helpers, urls


def get_user_name_change(access_token: str) -> NameChange:
Expand Down
3 changes: 1 addition & 2 deletions mojang/api/structures/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import typing
import datetime as dt

import typing

ServiceStatus = typing.NamedTuple(
"ServiceStatus", [("name", str), ("status", str)]
Expand Down
3 changes: 2 additions & 1 deletion mojang/api/structures/profile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List, Optional

from .base import NameInfo
from .session import Skin, Cape
from .session import Cape, Skin


class BaseUserProfile:
Expand Down
2 changes: 1 addition & 1 deletion mojang/api/structures/session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ctypes import Union
import datetime as dt
import re
from ctypes import Union
from os import path
from typing import NamedTuple, Optional
from urllib.parse import urlparse
Expand Down
File renamed without changes.
Empty file removed mojang/api/utils/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion mojang/minecraft/proto/rcon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import socket
from contextlib import contextmanager
from typing import Callable, Optional, Tuple, Generator
from typing import Callable, Generator, Optional, Tuple

from .packets import Packets

Expand Down
2 changes: 1 addition & 1 deletion mojang/minecraft/proto/slp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import enum
import socket
from functools import partial
from typing import Optional, Tuple
import enum

from ._structures import SLPResponse
from .post_netty import ping as mping
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import setuptools

import versioneer

if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions tests/session/mock_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from urllib.parse import urlparse

from requests.models import Response


Expand Down
3 changes: 2 additions & 1 deletion tests/session/test_mojang_change_name.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest
from unittest import mock

from mojang.api import session
from mojang.exceptions import InvalidName, UnavailableName, Unauthorized
from mojang.exceptions import InvalidName, Unauthorized, UnavailableName
from tests.session.mock_server import MockSessionServer

VALID_ACCESS_TOKEN = "MY_ACCESS_TOKEN"
Expand Down
1 change: 1 addition & 0 deletions tests/session/test_mojang_change_skin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from unittest import mock

from mojang.api import session
from mojang.exceptions import Unauthorized
from tests.session.mock_server import MockSessionServer
Expand Down
1 change: 1 addition & 0 deletions tests/session/test_mojang_get_profile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from unittest import mock

from mojang.api import session
from mojang.api.structures.session import Skin
from mojang.exceptions import Unauthorized
Expand Down
1 change: 1 addition & 0 deletions tests/session/test_mojang_hide_cape.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from unittest import mock

from mojang.api import session
from mojang.exceptions import Unauthorized
from tests.session.mock_server import MockSessionServer
Expand Down
1 change: 1 addition & 0 deletions tests/session/test_mojang_owns_mc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from unittest import mock

from mojang.api import session
from mojang.exceptions import Unauthorized
from tests.session.mock_server import MockSessionServer
Expand Down
1 change: 1 addition & 0 deletions tests/session/test_mojang_reset_skin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from unittest import mock

from mojang.api import session
from mojang.exceptions import Unauthorized
from tests.session.mock_server import MockSessionServer
Expand Down
1 change: 1 addition & 0 deletions tests/session/test_mojang_show_cape.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from unittest import mock

from mojang.api import session
from mojang.exceptions import NotCapeOwner, Unauthorized
from tests.session.mock_server import MockSessionServer
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from mojang.api.utils import helpers
from mojang.api import helpers


class TestUtilsHelpers(unittest.TestCase):
Expand Down