This file contains 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 contextlib import nullcontext | |
from typing import ContextManager, Optional, Union | |
import pytest | |
def maybe_raises( | |
exception: Union[type[BaseException], tuple[type[BaseException], ...]] | |
) -> ContextManager[Optional[pytest.ExceptionInfo[BaseException]]]: | |
if exception is None: |
This file contains 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 | |
from contextlib import AsyncExitStack, ExitStack | |
import contextvars | |
import functools | |
import inspect | |
import sys | |
__all__ = ['exit_stack'] |
This file contains 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 time, asyncio, hashlib | |
def sync_cpu_bound(): | |
s = bytes(range(256)) | |
for i in range(100000): | |
hashlib.sha256(s) | |
start = time.time() | |
sync_cpu_bound() |
This file contains 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
""" | |
Benchmark for PR to serialize execution of SQL in asyncpg. | |
See: https://github.com/MagicStack/asyncpg/pull/367 | |
""" | |
import asyncio | |
from asyncio import Lock | |
class _Atomic: |
This file contains 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
registry = Registry() | |
ReplicatedModel = registry.multidb( | |
admin=AdminBase, | |
front=FrontBase, | |
) | |
@registry.model(ReplicatedModel) | |
def Media(models): |
This file contains 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 sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column, Integer, ForeignKey, create_engine | |
from sqlalchemy.orm import sessionmaker, Session, relationship | |
Base = declarative_base() | |
class AB(Base): | |
__tablename__ = 'AB' | |
a_id = Column(ForeignKey('A.id'), primary_key=True) |
This file contains 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 sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine | |
from sqlalchemy.orm import sessionmaker, relationship | |
from sqlalchemy.orm.collections import attribute_mapped_collection | |
Base = declarative_base() | |
class Parent(Base): | |
__tablename__ = 'parents' | |
id = Column(Integer, primary_key=True) |
This file contains 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
#!/usr/bin/python2.7 | |
import path_config | |
from app import db_maker | |
db = db_maker() | |
from models import admin | |
from models.admin.base import AdminFrontModel | |
from sqlalchemy.orm.attributes import manager_of_class |
This file contains 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 os, sys, warnings | |
def _get_root(): | |
# Only .py file is symbolic link, while compiled module can be placed | |
# locally | |
name, ext = os.path.splitext(__file__) | |
fn = os.path.abspath(name +'.py') | |
if os.path.islink(fn): | |
# Symlinks are relative to target, not working dir | |
fn = os.path.join(os.path.dirname(fn), os.readlink(fn)) |
This file contains 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 sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column, Integer, ForeignKey, create_engine | |
from sqlalchemy.orm import sessionmaker, relationship | |
Base = declarative_base() | |
class Parent(Base): | |
__tablename__ = 'parents' | |
id = Column(Integer, primary_key=True) | |
#children = relationship('Child', cascade='all') # doesn't merge |
NewerOlder