|
2 | 2 |
|
3 | 3 | import base64 |
4 | 4 | import datetime |
| 5 | +import functools |
5 | 6 | import io |
6 | 7 | import json |
7 | 8 | import os |
8 | 9 | import re |
9 | 10 | import uuid as uuid_lib |
| 11 | +import warnings as _warnings |
10 | 12 | from pathlib import Path |
11 | | -from typing import Any, Dict, Generator, List, Optional, Sequence, Tuple, Union, cast |
| 13 | +from typing import Any, Callable, Dict, Generator, List, Optional, Sequence, Tuple, Union, cast |
12 | 14 | from urllib.parse import quote |
13 | 15 |
|
14 | 16 | import httpx |
|
32 | 34 | BYTES_PER_CHUNK = 65535 # The number of bytes to read per chunk when encoding files ~ 64kb |
33 | 35 |
|
34 | 36 |
|
| 37 | +def docstring_deprecated(details: str = "", deprecated_in: str = "") -> Callable: |
| 38 | + """Stdlib replacement for ``deprecation.deprecated``. |
| 39 | +
|
| 40 | + The ``deprecation`` package has not been maintained since 2019 and is |
| 41 | + flagged as a security risk by several dependency scanners. This helper |
| 42 | + replicates the behaviour we need: |
| 43 | +
|
| 44 | + 1. Prepend a ``.. deprecated::`` note to the function docstring. |
| 45 | + 2. Emit a :class:`DeprecationWarning` at call time. |
| 46 | + """ |
| 47 | + |
| 48 | + def decorator(func: Callable) -> Callable: |
| 49 | + @functools.wraps(func) |
| 50 | + def wrapper(*args: object, **kwargs: object) -> object: |
| 51 | + _warnings.warn( |
| 52 | + f"{func.__qualname__} is deprecated since {deprecated_in}. {details}", |
| 53 | + DeprecationWarning, |
| 54 | + stacklevel=2, |
| 55 | + ) |
| 56 | + return func(*args, **kwargs) |
| 57 | + |
| 58 | + docstring = func.__doc__ or "" |
| 59 | + note = f".. deprecated:: {deprecated_in}\n {details}\n\n" if deprecated_in else "" |
| 60 | + wrapper.__doc__ = note + docstring |
| 61 | + |
| 62 | + return wrapper # type: ignore[return-value] |
| 63 | + |
| 64 | + return decorator |
| 65 | + |
| 66 | + |
35 | 67 | def image_encoder_b64(image_or_image_path: Union[str, io.BufferedReader]) -> str: |
36 | 68 | """Encode a image in a Weaviate understandable format from a binary read file or by providing the image path. |
37 | 69 |
|
|
0 commit comments