fix: pylint fixes

This commit is contained in:
SeaswimmerTheFsh 2024-03-28 11:28:24 -04:00
parent c6b723a476
commit 8414fb4b53
Signed by: cswimr
GPG key ID: B8953EC01E5C4063
3 changed files with 82 additions and 21 deletions

View file

@ -1,8 +1,9 @@
"""This is a list of all the models used in PyZipline. They are used to represent the data returned from the Zipline API."""
import logging
from datetime import datetime
from typing import Dict, List, Optional, Union
from pydantic import BaseModel, Field
from pydantic import BaseModel, ConfigDict, Field
class File(BaseModel):
@ -146,13 +147,47 @@ class Stats(BaseModel):
class Embed(BaseModel):
"""Object containing a user's embed settings
Attributes:
color (Optional[str]): String of the embed's color
title (Optional[str]): String of the embed's title
site_name (Optional[str]): String of the embed's site name
description (Optional[str]): String of the embed's description
"""
color: Optional[str] = None
title: Optional[str] = None
siteName: Optional[str] = None
description: Optional[str] = None
def __str__(self):
if self.title is None:
return "None"
return self.title
class User(BaseModel):
"""Object containing user information
/// admonition | Contains Sensitive Information
type: danger
Please be mindful of how you use/store this object, as it contains sensitive information such as the user's token and TOTP information.
///
Attributes:
id (int): Integer ID of the user
uuid (str): String of the user's UUID
username (str): String of the user's username
avatar (Optional[str]): String of the user's avatar, base64 encoded
token (str): String of the user's token
administrator (bool): Boolean of whether the user is an administrator
super_admin (bool): Boolean of whether the user is a super administrator
system_theme (str): String of the user's system theme
embed (Embed): Embed object of the user's embed
totp_secret (Optional[str]): String of the user's TOTP secret
domains (List[str]): List of Strings of the user's domains
oauth (Optional[List[OAuth]]): List of [OAuth](.#pyzipline.models.OAuth) objects
ratelimit (Optional[datetime]): Datetime object of when the user's ratelimit expires
"""
id: int
uuid: str
username: str
@ -170,15 +205,45 @@ class User(BaseModel):
return self.username
class Versions(BaseModel):
"""Object containing the current, stable, and upstream versions of Zipline
Attributes:
stable (str): String of the stable version
upstream (str): String of the upstream version
current (str): String of the current version
"""
stable: str
upstream: str
current: str
class Version(BaseModel):
"""Model containing the current, stable, and upstream versions of Zipline
Attributes:
is_upstream (bool): Boolean of whether the current version is upstream (`trunk` branch)
update_to_type (str): String of the type of update available, one of 'stable' or 'upstream'
versions (Versions): Versions object containing the current, stable, and upstream versions
"""
isUpstream: bool
updateToType: str
versions: Versions
def __str__(self):
return self.versions.current
class ZiplineApiConfig(BaseModel):
"""Represents a configuration instance for the ZiplineApi/RestAdapter class.
Args:
hostname (str): The hostname of your Zipline instance, WITHOUT https or http.
token (str): String used for authentication when making requests.
ssl (bool): Normally set to True, but if your Zipline instance doesn't use SSL/TLS, set this to False.
enforced_signing (bool): Normally set to True, but if having SSL/TLS cert validation issues, can turn off with False.
logger (logging.Logger): If your app has a logger, pass it in here.
"""
model_config = ConfigDict(arbitrary_types_allowed=True)
hostname: str
token: str = ''
ssl: bool = True
enforced_signing: bool = True
logger: logging.Logger = logging.getLogger(__name__)

View file

@ -6,36 +6,32 @@ import requests
from urllib3 import disable_warnings
from pyzipline.exceptions import HTTPFailure, PyZiplineError
from pyzipline.models import Result
from pyzipline.models import Result, ZiplineApiConfig
class RestAdapter:
"""Constructor for RestAdapter
Args:
hostname (str): The hostname of your Zipline instance, WITHOUT https or http.
token (str = None): String used for authentication when making requests.
ssl (bool = True): Normally set to True, but if your Zipline instance doesn't use SSL/TLS, set this to False.
enforced_signing (bool = True): Normally set to True, but if having SSL/TLS cert validation issues, can turn off with False.
logger (logging.Logger = None): If your app has a logger, pass it in here.
config (ZiplineApiConfig): Configuration object for the ZiplineApi class
Raises:
ValueError: Raised when the keyword arguments passed to the class constructor conflict.
"""
def __init__(self, hostname: str, token: str = '', ssl: bool = True, enforced_signing: bool = True, logger: logging.Logger = None):
self._url = f"http{'s' if ssl else ''}://{hostname}/api/"
self._token = token
self._ssl = ssl
self._enforced_signing = enforced_signing
self._logger = logger or logging.getLogger(__name__)
def __init__(self, config = ZiplineApiConfig):
self._url = f"http{'s' if config.ssl else ''}://{config.hostname}/api/"
self._token = config.token
self._ssl = config.ssl
self._enforced_signing = config.enforced_signing
self._logger = config.logger or logging.getLogger(__name__)
if ssl is False and enforced_signing is True:
if config.ssl is False and config.enforced_signing is True:
raise ValueError("Cannot enforce signing without SSL")
if not ssl and not enforced_signing:
if not config.ssl and not config.enforced_signing:
disable_warnings()
def _do(self, http_method: str, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result:
def _do(self, http_method: str, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result: # pylint: disable=too-many-arguments
"""Internal method to make a request to the Zipline server. You shouldn't use this directly.
Args:
@ -82,7 +78,7 @@ class RestAdapter:
return Result(success=is_success, status_code=response.status_code, message=data_out['error'], data=data_out)
def delete(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, timeout: float = 60) -> Result:
def delete(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, timeout: float = 60) -> Result: # pylint: disable=too-many-arguments
"""Make a DELETE request to the Zipline server. You should almost never have to use this directly.
Args:
@ -109,7 +105,7 @@ class RestAdapter:
"""
return self._do(http_method='GET', endpoint=endpoint, headers=headers, params=params, timeout=timeout)
def patch(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result:
def patch(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result: # pylint: disable=too-many-arguments
"""Make a PATCH request to the Zipline server. You should almost never have to use this directly.
Args:
@ -124,7 +120,7 @@ class RestAdapter:
"""
return self._do(http_method='PATCH', endpoint=endpoint, headers=headers, params=params, json=json, files=files, timeout=timeout)
def post(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result:
def post(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result: # pylint: disable=too-many-arguments
"""Make a POST request to the Zipline server. You should almost never have to use this directly.
Args:

View file

@ -42,7 +42,7 @@ class ZiplineApi:
self,
config: ZiplineApiConfig
):
self._rest_adapter = RestAdapter(hostname=config.hostname, token=config.token, ssl=config.ssl, enforced_signing=config.enforced_signing, logger=config.logger)
self._rest_adapter = RestAdapter(config)
def create_invite(self, expiry: timedelta = timedelta(days=1), count: int = 1) -> Union[Invite, List[Invite]]:
"""Create an invite code