File size: 2,829 Bytes
9c6594c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union

import numpy as np
import torch
from PIL import Image as PILImage

# Constants
pytorch_weights_only: bool
IMAGE_EXTENSIONS: List[str]

# Type definitions
Sample = Dict[str, Any]
Handler = Callable[[str, bytes], Any]
DecoderList = List[Handler]

# Functions for basic data types
def torch_loads(data: bytes) -> Any: ...
def tenbin_loads(data: bytes) -> Any: ...
def msgpack_loads(data: bytes) -> Any: ...
def npy_loads(data: bytes) -> Any: ...
def npz_loads(data: bytes) -> Dict[str, np.ndarray]: ...
def cbor_loads(data: bytes) -> Any: ...

# Dictionary of decoders
decoders: Dict[str, Callable[[bytes], Any]]

# Basic handlers
def basichandlers(key: str, data: bytes) -> Optional[Any]: ...

# Extension handlers
def call_extension_handler(key: str, data: bytes, f: Callable[[bytes], Any], extensions: List[str]) -> Optional[Any]: ...
def handle_extension(extensions: str, f: Callable[[bytes], Any]) -> Handler: ...

# Image handling
imagespecs: Dict[str, Tuple[str, Optional[str], str]]

class ImageHandler:
    imagespec: str
    extensions: Set[str]

    def __init__(self, imagespec: str, extensions: List[str] = IMAGE_EXTENSIONS) -> None: ...
    def __call__(self, key: str, data: bytes) -> Optional[Union[PILImage.Image, np.ndarray, 'torch.Tensor']]: ...

def imagehandler(imagespec: str, extensions: List[str] = IMAGE_EXTENSIONS) -> ImageHandler: ...

# Video and audio handling
def torch_video(key: str, data: bytes) -> Optional[Tuple['torch.Tensor', 'torch.Tensor', Dict[str, Any]]]: ...
def torch_audio(key: str, data: bytes) -> Optional[Tuple['torch.Tensor', int]]: ...

# Special class for continuing decoding
class Continue:
    key: str
    data: bytes

    def __init__(self, key: str, data: bytes) -> None: ...

def gzfilter(key: str, data: bytes) -> Optional[Continue]: ...

# Default handlers
default_pre_handlers: List[Handler]
default_post_handlers: List[Handler]

# Decoder class and error
class DecodingError(Exception):
    url: Optional[str]
    key: Optional[str]
    k: Optional[str]
    sample: Optional[Sample]

    def __init__(self, url: Optional[str] = None, key: Optional[str] = None,
                 k: Optional[str] = None, sample: Optional[Sample] = None) -> None: ...

class Decoder:
    handlers: List[Handler]
    only: Optional[Set[str]]
    partial: bool

    def __init__(self, handlers: List[Handler], pre: Optional[List[Handler]] = None,
                 post: Optional[List[Handler]] = None, only: Optional[Union[List[str], Set[str], str]] = None,
                 partial: bool = False) -> None: ...
    def decode1(self, key: str, data: bytes) -> Any: ...
    def decode(self, sample: Sample) -> Sample: ...
    def __call__(self, sample: Sample) -> Sample: ...

# Default decoder
default_decoder: Decoder