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
import json | |
import re | |
from typing import Tuple | |
def dict_to_openapi(d: dict) -> dict: | |
result = {} | |
for k, v in d.items(): | |
if isinstance(v, dict): | |
result[k] = dict(type="object", properties=dict_to_openapi(v)) |
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 Iterable, Tuple, Type, Optional, List | |
from django.conf import settings | |
from django.contrib.auth.models import Permission | |
from django.contrib.contenttypes.models import ContentType | |
from django.db.models import Model | |
from keycloak.admin.clientroles import ClientRoles | |
from keycloak.exceptions import KeycloakClientError | |
from keycloak.openid_connect import KeycloakOpenidConnect | |
from keycloak.realm import KeycloakRealm |
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
import inspect | |
class Value: | |
__slots__ = ('name', 'default') | |
def __init__(self, name, default=None): | |
self.name = name | |
self.default = default |
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 Callable, Union | |
class Pipe: | |
def __init__(self, callable_: Callable): | |
self.callable_ = callable_ | |
def __rshift__(self, then: Union[Callable, "Pipe"]) -> "Pipe": | |
if not isinstance(then, Pipe): | |
then = Pipe(then) |
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 peewee import * | |
User = Table('users', ('id', 'username')) | |
s = Select().columns('id', 'username').from_(User) | |
sub = Select().columns(s.c.id, s.c.username).from_(s) | |
print(s.c) | |
print(s._returning) | |
print(sub._returning) |
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
import asyncio | |
import asyncpg | |
async def main(): | |
conn: asyncpg.Connection = await asyncpg.connect() | |
def callback(c: asyncpg.Connection, pid: int, ch: str, p: str): | |
print(c, pid, ch, p) |
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
import inspect | |
from typing import List, TypeVar, Type, Set | |
T = TypeVar('T') | |
def find_subclasses(cls: Type[T], deep=True) -> List[Type[T]]: | |
res: List[Type[T]] = [] | |
subclasses: List[Type[T]] = cls.__subclasses__() | |
for subclass in subclasses: |
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 to_minutes(wd, h, m): | |
return wd * 24 * 60 + h * 60 + m | |
def from_minutes(minutes): | |
wd = minutes // (24 * 60) | |
rest = minutes - (wd * 24 * 60) | |
return wd, rest // 60, rest % 60 | |
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
import asyncio | |
class Awaitable: | |
def __await__(self): | |
yield | |
async def main(): | |
await Awaitable() |
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
# models mixin | |
class SyncMixin: | |
@classmethod | |
def get_sync_type(cls) -> int: | |
"""Returns sync type.""" | |
raise NotImplemented() | |
@classmethod | |
def get_sync_model(cls): | |
"""Returns django.db.Model child class. |
NewerOlder