This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@classmethod | |
def _get_connection(cls) -> TableConnection: | |
meta = getattr(cls, "Meta", None) | |
if not meta or cls._connection: | |
return super()._get_connection() | |
for key, value in cls._app_config.items(): | |
if not getattr(meta, key, None): | |
setattr(meta, key, value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@classmethod | |
def _get_connection(cls) -> TableConnection: | |
""" | |
Returns a (cached) connection | |
""" | |
if not hasattr(cls, "Meta"): | |
raise AttributeError( | |
'As of v1.0 PynamoDB Models require a `Meta` class.\n' | |
'Model: {}.{}\n' | |
'See https://pynamodb.readthedocs.io/en/latest/release_notes.html\n'.format( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PynamoDB: | |
Model = ModelClass | |
def __init__(self, app: Flask = None): | |
self.app = app | |
if app: | |
self.init_app(app) | |
def init_app(self, app: Flask): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partialmethod | |
from typing import Union, Dict, List, Any | |
import requests | |
JSONType = Union[None, bool, int, float, str, List[Any], Dict[str, Any]] | |
class RestError(Exception): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GitHubClient: | |
BASE_URL = 'https://api.github.com' | |
def __init__(self, username: str, token: str, headers: Dict[str, str] = None): | |
self._session = requests.Session() | |
self._session.auth = requests.auth.HTTPBasicAuth(username, token) | |
self._session.headers = headers or GITHUB_DEFAULT_HEADERS | |
@property | |
def username(self) -> str: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GitHubClient: | |
BASE_URL = 'https://api.github.com' | |
def __init__(self, username: str, token: str, headers: Dict[str, str] = None): | |
self._session = requests.Session() | |
self._session.auth = requests.auth.HTTPBasicAuth(username, token) | |
self._session.headers = headers or GITHUB_DEFAULT_HEADERS | |
def __enter__(self): | |
return self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Union, Dict, List, Any | |
import requests | |
GITHUB_DEFAULT_HEADERS = {'Accept': 'application/vnd.github.v3+json', | |
'User-Agent': 'python-requests'} | |
JSONType = Union[None, bool, int, float, str, List[Any], Dict[str, Any]] | |
class GitHubError(Exception): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get(path: str, **kwargs) -> JSONType: | |
kwargs['headers'] = {**HEADERS, **kwargs.get('headers', {})} | |
kwargs['auth'] = kwargs.get('auth', AUTH) | |
try: | |
resp = requests.get(f'{BASE_URL}/{path}', **kwargs) | |
resp.raise_for_status() | |
return resp.json() | |
except requests.HTTPError as http_error: | |
raise GitHubError(f'Invalid request from GitHub API: {http_error}') from http_error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, List, Any | |
import requests | |
BASE_URL = 'https://api.github.com' | |
USERNAME = '<USERNAME>' | |
ACCESS_TOKEN = '<TOKEN>' | |
AUTH = USERNAME, ACCESS_TOKEN | |
HEADERS = {'Accept': 'application/vnd.github.v3+json'} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, List, Any | |
import requests | |
BASE_URL = 'https://api.github.com' | |
USERNAME = '<USERNAME>' | |
ACCESS_TOKEN = '<TOKEN>' | |
AUTH = USERNAME, ACCESS_TOKEN | |
HEADERS = {'Accept': 'application/vnd.github.v3+json'} |
NewerOlder