-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
resource.py
53 lines (34 loc) · 1.08 KB
/
resource.py
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
from __future__ import annotations
from pathlib import Path
from typing import Generic, TypeVar
from avilla.core.selector import Selector
from .metadata import Metadata
T = TypeVar("T")
class Resource(Metadata, Generic[T]):
selector: Selector
def __init__(self, selector: Selector):
self.selector = selector
def to_selector(self):
return self.selector
class LocalFileResource(Resource[bytes]):
file: Path
def __init__(self, file: Path | str):
if isinstance(file, str):
file = Path(file)
self.file = file
@property
def selector(self) -> Selector:
return Selector().land("avilla-core").local_file(str(self.file))
class RawResource(Resource[T]):
data: T
def __init__(self, data: T):
self.data = data
@property
def selector(self):
return Selector().land("avilla-core").raw_data(str(id(self)))
class UrlResource(Resource[bytes]):
def __init__(self, url: str):
self.url = url
@property
def selector(self):
return Selector().land("avilla-core").url(self.url)