tdk.internal.utils¶
This module contains miscellaneous utilities for the library.
Module Contents¶
Functions¶
Make an async function run synchronously. |
|
Convert a sound code to a valid sound URL. |
|
Convert an image code to a valid image URL. |
|
Get an enum member from an enum instance, value or name. |
|
Assert that the data is a |
|
Validate a meaning property. |
Data¶
|
|
|
|
|
|
|
|
The constant “not found” response of the API, decoded from JSON. |
|
|
API¶
- tdk.internal.utils.make_sync(func_to_be_cloned, /)¶
Make an async function run synchronously.
Creates a decorator that runs the async function given as a parameter synchronously.
Important
The wrapped function is discarded and not used.
Example usage
from tdk.internal.utils import make_sync async def wait(): from asyncio import sleep await sleep(1) return "Hello, world!" @make_sync(wait) def wait_sync(): ... print(wait_sync()) # Hello, world!
- tdk.internal.utils.int_or_none_as_str(value: str, /) int | None¶
Convert a string to an
intor aNone.Empty strings are converted to
None, other strings are converted to typeint.
- tdk.internal.utils.IntOrNone¶
None
pydantic.BeforeValidatortype hint for an integer or None.Works using
int_or_none_as_str.
- tdk.internal.utils.str_or_none_as_str(value: str, /) str | None¶
Convert a string to a
strorNone.Empty strings are converted to
None, other strings are converted to typestr.
- tdk.internal.utils.StrOrNone¶
None
pydantic.BeforeValidatortype hint for a string or None.Works using
str_or_none_as_str.
- tdk.internal.utils.sound_url_validator(v: str, /) str¶
Convert a sound code to a valid sound URL.
Strings that do not start with
https://are converted tohttps://sozluk.gov.tr/ses/{}.wav.
- tdk.internal.utils.SoundURL¶
None
pydantic.AfterValidatortype hint for a sound URL.Works using
sound_url_validator.
- tdk.internal.utils.image_url_validator(v: str, /) str¶
Convert an image code to a valid image URL.
Strings that do not start with
https://are converted tohttps://sozluk.gov.tr/dosyalar/tarornek/{}.gif.
- tdk.internal.utils.ImageURL¶
None
pydantic.AfterValidatortype hint for an image URL.Works using
image_url_validator.
- tdk.internal.utils.adapt_input_to_enum(input: Any, enum: Type[enum.Enum]) enum.Enum¶
Get an enum member from an enum instance, value or name.
>>> from enum import Enum >>> class Color(Enum): ... RED = 1 ... GREEN = 2 ... BLUE = 3 ... >>> adapt_input_to_enum(Color.RED, Color) <Color.RED: 1> >>> adapt_input_to_enum(2, Color) <Color.GREEN: 2> >>> adapt_input_to_enum("blue", Color) <Color.BLUE: 3>
- Raises:
ValueError – If
inputis not found inenum.
- tdk.internal.utils.NOT_FOUND: dict¶
None
The constant “not found” response of the API, decoded from JSON.
The TDK APIs always return this response when the requested data is not found.
- tdk.internal.utils.assert_not_found(data: Any, /)¶
Assert that the data is a
NOT_FOUNDresponse.- Raises:
TypeError – If the data is not a dict.
ValueError – If the data is not a
NOT_FOUNDresponse.
- tdk.internal.utils.validate_property(v: str | int | tdk.enums.MeaningProperty, /)¶
Validate a meaning property.
If the input is a
MeaningPropertyinstance, it is returned as is. Otherwise,MeaningProperty.getis used to find the correctMeaningPropertyinstance, and it is returned.
- tdk.internal.utils.ValidatedProperty¶
None
pydantic.BeforeValidatortype hint for a validated meaning property.Works using
validate_property.