def _get_model(self, type_): if is_subclass(type_, BaseModel): return type_ # workaround because uplink doesn't support Union types # see https://github.com/prkumar/uplink/issues/233 elif typing.get_origin(type_) is Union: typing_args = typing.get_args(type_) all_are_models = all( [is_subclass(inner_type, BaseModel) for inner_type in typing_args] ) if all_are_models: return type_ raise ValueError("Expected pydantic.BaseModel subclass or instance")
def __init__( self, calls=15, period=900, raise_on_limit=False, group_by=BY_HOST_AND_PORT, clock=now, ): self._max_calls = max(1, min(sys.maxsize, math.floor(calls))) self._period = period self._clock = clock self._limiter_cache = {} self._group_by = utils.no_op if group_by is None else group_by if utils.is_subclass(raise_on_limit, Exception) or isinstance( raise_on_limit, Exception): self._create_limit_reached_exception = raise_on_limit elif raise_on_limit: self._create_limit_reached_exception = ( self._create_rate_limit_exceeded) else: self._create_limit_reached_exception = None
def _is_consumer_class(c): return utils.is_subclass(c, interfaces.Consumer)
def _get_schema(cls, type_): if utils.is_subclass(type_, cls.marshmallow.Schema): return type_() elif isinstance(type_, cls.marshmallow.Schema): return type_ raise ValueError("Expected marshmallow.Scheme subclass or instance.")
def _is_annotation(annotation): cls = interfaces.Annotation return utils.is_subclass(annotation, cls) or isinstance( annotation, cls)
def _client_class_handler(key): if utils.is_subclass(key, interfaces.HttpClientAdapter): return key()
def _get_model(self, type_): if is_subclass(type_, self.pydantic.BaseModel): return type_ raise ValueError("Expected pydantic.BaseModel subclass or instance")