예제 #1
0
 def __init__(self, query_db: Callable[
     [str, DefaultArg(Tuple
                      ), DefaultArg(bool, 'one')], Row],
              store_db: Callable[[str, DefaultArg(Tuple)], int]):
     self.query_db = query_db
     self.store_db = store_db
     self.university = university.University(self.query_db)
     self.scraper = scraper.Scraper(get_webpage)
예제 #2
0
    def __init__(self, query_db: Callable[[str, DefaultArg(Tuple), DefaultArg(bool, 'one')], Row]):
        # need to decide how degree/course details passed in
        # unpack and create degree.Degree and course.Course objects
        self.query_db = query_db
        self.course_requirement_types = self.load_course_requirement_types()
        self.course_filter_types = self.load_course_filter_types()

        # cache of courses loaded from the db for this session, indexed by database id
        self.courses: Dict[int, 'course.Course'] = {}
        # cache of degrees loaded from the db for this session, indexed by numeric code (which is
        # also db id)
        self.degrees: Dict[Tuple[str, int], 'degree.Degree'] = {}
예제 #3
0
def test__pass_args_to_function(
    function: Callable[[
        DefaultArg(Any, 'arg0'),
        DefaultArg(Any, 'arg1'),
        DefaultArg(Any, 'arg2'),
    ], None]
) -> None:
    """Test passing argument to functions decorated by `@pass_args`."""
    function()
    function("a")
    function("a", "b")
    function(arg1="b")
    function(arg2="c")
    function(arg0="a", arg1="b")
    function(arg0="a", arg1="b", arg2="c")
예제 #4
0
WAIT_DELETE_S = 5

BounceMethodResult = TypedDict(
    'BounceMethodResult',
    {
        "create_app": bool,
        "tasks_to_drain": Set,
    },
)

BounceMethod = Callable[[
    Arg(BounceMethodConfigDict, 'new_config'),
    Arg(bool, 'new_app_running'),
    Arg(Collection, 'happy_new_tasks'),
    Arg(Sequence, 'old_non_draining_tasks'),
    DefaultArg(float, 'margin_factor'),
], BounceMethodResult]

_bounce_method_funcs: Dict[str, BounceMethod] = {}


def register_bounce_method(
        name: str) -> Callable[[BounceMethod], BounceMethod]:
    """Returns a decorator that registers that bounce function at a given name
    so get_bounce_method_func can find it."""
    def outer(bounce_func: BounceMethod):
        _bounce_method_funcs[name] = bounce_func
        return bounce_func

    return outer
예제 #5
0
test_pattern = """
>>> m1= path_pat.match( "/anscombe/I" )
>>> m1.groupdict()
{'dataset': 'I'}
>>> m2= path_pat.match( "/anscombe/II/" )
>>> m2.groupdict()
{'dataset': 'II'}
>>> m3= path_pat.match( "/anscombe/" )
>>> m3.groupdict()
{'dataset': ''}
"""

from typing import Callable, List, Tuple, Iterable
from mypy_extensions import DefaultArg

SR_Func = Callable[[str, List[Tuple[str, str]], DefaultArg(Tuple)], None]

import traceback
import urllib.parse


def anscombe_app(environ: Dict, start_response: SR_Func) -> Iterable[bytes]:
    log = environ['wsgi.errors']
    try:
        match = path_pat.match(environ['PATH_INFO'])
        set_id = match.group('dataset').upper()
        query = urllib.parse.parse_qs(environ['QUERY_STRING'])
        print(environ['PATH_INFO'],
              environ['QUERY_STRING'],
              match.groupdict(),
              file=log)
예제 #6
0
파일: handlers.py 프로젝트: nipz/py-evm
            manager: ExchangeManager[Any, Any, Any]
            manager = ExchangeManager(self._peer,
                                      exchange_cls.response_cmd_type,
                                      peer.cancel_token)
            exchange = exchange_cls(manager)
            setattr(self, attr, exchange)

    def __iter__(self) -> Iterator[BaseExchange[Any, Any, Any]]:
        for key in self._exchange_config.keys():
            yield getattr(self, key)

    def get_stats(self) -> Dict[str, str]:
        return {
            exchange.response_cmd_type.__name__: exchange.tracker.get_stats()
            for exchange in self
        }


if TYPE_CHECKING:
    from mypy_extensions import DefaultArg
    BlockHeadersCallable = Callable[[
        BaseExchangeHandler, BlockIdentifier, int,
        DefaultArg(int, 'skip'),
        DefaultArg(int, 'reverse')
    ], Awaitable[Tuple[BlockHeader, ...]]]


# This class is only needed to please mypy for type checking
class BaseChainExchangeHandler(BaseExchangeHandler):
    get_block_headers: 'BlockHeadersCallable'
예제 #7
0
ZK_LOCK_CONNECT_TIMEOUT_S = 10.0  # seconds to wait to connect to zookeeper
ZK_LOCK_PATH = "/bounce"
WAIT_CREATE_S = 3
WAIT_DELETE_S = 5

BounceMethodResult = TypedDict("BounceMethodResult", {
    "create_app": bool,
    "tasks_to_drain": Set
})

BounceMethod = Callable[[
    Arg(BounceMethodConfigDict, "new_config"),
    Arg(bool, "new_app_running"),
    Arg(Collection, "happy_new_tasks"),
    Arg(Sequence, "old_non_draining_tasks"),
    DefaultArg(float, "margin_factor"),
], BounceMethodResult, ]

_bounce_method_funcs: Dict[str, BounceMethod] = {}


def register_bounce_method(
        name: str) -> Callable[[BounceMethod], BounceMethod]:
    """Returns a decorator that registers that bounce function at a given name
    so get_bounce_method_func can find it."""
    def outer(bounce_func: BounceMethod):
        _bounce_method_funcs[name] = bounce_func
        return bounce_func

    return outer
예제 #8
0
파일: types.py 프로젝트: spilop/electrumsv
from typing import Callable, NamedTuple, Optional
from mypy_extensions import Arg, DefaultArg

class TxoKeyType(NamedTuple):
    tx_hash: bytes
    tx_index: int

WaitingUpdateCallback = Callable[[Arg(bool, "advance"), DefaultArg(Optional[str], "message")], None]
예제 #9
0
from typing import (
    Awaitable,
    Callable,
    Tuple,
    TYPE_CHECKING,
)

from eth_typing import BlockIdentifier

from eth.rlp.headers import BlockHeader

from p2p.exchange import BaseExchangeHandler

if TYPE_CHECKING:
    from mypy_extensions import DefaultArg
    BlockHeadersCallable = Callable[[
        BaseExchangeHandler, BlockIdentifier,
        DefaultArg(int, 'max_headers'),
        DefaultArg(int, 'skip'),
        DefaultArg(int, 'reverse'),
        DefaultArg(float, 'timeout')
    ], Awaitable[Tuple[BlockHeader, ...]]]


# This class is only needed to please mypy for type checking
class BaseChainExchangeHandler(BaseExchangeHandler):
    get_block_headers: 'BlockHeadersCallable'
예제 #10
0
파일: handlers.py 프로젝트: s0b0lev/trinity
            manager = ExchangeManager(self._peer,
                                      exchange_cls.response_cmd_type,
                                      peer.cancel_token)
            exchange = exchange_cls(manager)
            setattr(self, attr, exchange)

    def __iter__(self) -> Iterator[BaseExchange[Any, Any, Any]]:
        for key in self._exchange_config.keys():
            yield getattr(self, key)

    def get_stats(self) -> Dict[str, str]:
        return {
            exchange.response_cmd_type.__name__: exchange.tracker.get_stats()
            for exchange in self
        }


if TYPE_CHECKING:
    from mypy_extensions import DefaultArg
    BlockHeadersCallable = Callable[[
        BaseExchangeHandler, BlockIdentifier, int,
        DefaultArg(int, 'skip'),
        DefaultArg(int, 'reverse'),
        DefaultArg(float, 'timeout')
    ], Awaitable[Tuple[BlockHeader, ...]]]


# This class is only needed to please mypy for type checking
class BaseChainExchangeHandler(BaseExchangeHandler):
    get_block_headers: 'BlockHeadersCallable'