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
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine | |
from sqlalchemy.orm import relationship, sessionmaker | |
from sqlalchemy.ext.declarative import declarative_base | |
Base = declarative_base() | |
class DocLink(Base): | |
__tablename__ = 'DocLink' |
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 import Column, Integer, ForeignKey | |
from sqlalchemy.orm import relationship | |
from sqlalchemy.ext.declarative import declarative_base | |
Base = declarative_base() | |
class Link(Base): | |
__tablename__ = 'Link' | |
id = Column(Integer, primary_key=True) | |
doc_id = Column(Integer, ForeignKey('Doc.id'), nullable=False) |
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 sphinx_xmlpipe2 | |
pipe = sphinx_xmlpipe2.Pipe( | |
fields = ['title', 'description', 'body'], | |
attrs = [sphinx_xmlpipe2.Timestamp('date'), sphinx_xmlpipe2.Int8('type')], | |
) | |
with pipe: | |
for doc in docs: | |
pipe.add( |
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.ext.orderinglist import ordering_list | |
Base = declarative_base() | |
class Parent(Base): | |
__tablename__ = 'parents' |
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) |
NewerOlder