clipcloudlib 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: clipcloudlib
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Project-URL: Repository, https://github.com/rorka491/clipcloud-lib.git
6
+ Requires-Python: >=3.13
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: build>=1.5.0
9
+ Requires-Dist: pydantic>=2.13.4
File without changes
@@ -0,0 +1,19 @@
1
+ class ObjectNotFound(Exception):
2
+ def __init__(self, message: str = "Object not found"):
3
+ super().__init__(message)
4
+
5
+
6
+ class MissingAttributeError(Exception):
7
+ def __init__(self, message: str = "Attribute not found"):
8
+ super().__init__(message)
9
+
10
+
11
+ class CanNotCreateRoomCommand(Exception):
12
+ def __init__(self, message: str = "Can not create room"):
13
+ super().__init__(message)
14
+
15
+
16
+ class InvalidTokenException(Exception):
17
+
18
+ def __init__(self, message: str = "Invalid token") -> None:
19
+ super().__init__(message)
@@ -0,0 +1,61 @@
1
+ from datetime import datetime
2
+ from uuid import UUID
3
+ import json
4
+ from typing import Any, Generic, TypeVar
5
+ from abc import abstractmethod, ABC
6
+
7
+
8
+ M = TypeVar("M")
9
+
10
+
11
+ class BaseMapper(Generic[M], ABC):
12
+
13
+ @abstractmethod
14
+ def to_dict(self, obj: M) -> dict: ...
15
+
16
+ @abstractmethod
17
+ def to_obj(self, data: dict) -> M: ...
18
+
19
+ @staticmethod
20
+ def get(data: dict, key: str) -> Any:
21
+ value = data.get(key)
22
+ if not value:
23
+ raise ValueError(f"Missing or empty field: {key}")
24
+ return value
25
+
26
+ @staticmethod
27
+ def get_or_none(data: dict, key: str) -> str | None:
28
+ value = data.get(key)
29
+ return value if value else None
30
+
31
+
32
+ @staticmethod
33
+ def get_uuid(data: dict, key: str) -> UUID:
34
+ value = data.get(key)
35
+ if not value:
36
+ raise ValueError(f"Missing or empty UUID field: {key}")
37
+ return UUID(value)
38
+
39
+ @staticmethod
40
+ def get_uuid_or_none(data: dict, key: str) -> UUID | None:
41
+ value = data.get(key)
42
+ return UUID(value) if value else None
43
+
44
+ @staticmethod
45
+ def get_datetime(data: dict, key: str) -> datetime:
46
+ value = datetime.fromisoformat(data[key])
47
+ if not value:
48
+ raise ValueError(f"Missing or empty datetime field: {key}")
49
+ return value
50
+
51
+ @staticmethod
52
+ def dump_uuid(value: UUID | None) -> str | None:
53
+ return str(value) if value else None
54
+
55
+ @staticmethod
56
+ def dump_datetime(value: datetime) -> str:
57
+ return value.isoformat()
58
+
59
+ @staticmethod
60
+ def clean_dict(data: dict) -> dict:
61
+ return {k: v for k, v in data.items() if v is not None}
@@ -0,0 +1,35 @@
1
+ from uuid import UUID
2
+ from datetime import datetime
3
+ from clipcloudlib.mappers.base import BaseMapper
4
+ from clipcloudlib.models.redis.room import Room, RoomAlias
5
+
6
+
7
+ class RoomMapper(BaseMapper[Room]):
8
+
9
+ def to_dict(self, obj: Room) -> dict:
10
+ return {
11
+ "id": self.dump_uuid(obj.id),
12
+ "room_code": obj.room_code,
13
+ "created_at": obj.created_at.isoformat(),
14
+ "owner_session_id": self.dump_uuid(obj.owner_session_id)
15
+ }
16
+
17
+ def to_obj(self, data: dict) -> Room:
18
+ return Room(
19
+ id=UUID(data.get("id")),
20
+ room_code=str(data.get("room_code")),
21
+ created_at=datetime.fromisoformat(data["created_at"]),
22
+ owner_session_id=UUID(data.get("owner_session_id"))
23
+ )
24
+
25
+ class RoomAliasMapper(BaseMapper[RoomAlias]):
26
+
27
+ def to_dict(self, obj: RoomAlias) -> dict:
28
+ return {
29
+ "room_code": obj.room_code,
30
+ }
31
+
32
+ def to_obj(self, data: dict) -> RoomAlias:
33
+ return RoomAlias(
34
+ room_code=self.get(data, "room_code")
35
+ )
@@ -0,0 +1,41 @@
1
+ from clipcloudlib.mappers.base import BaseMapper
2
+ from clipcloudlib.models.redis.session import Session
3
+ from clipcloudlib.schemas.room import RoomMember
4
+
5
+
6
+ class SessionMapper(BaseMapper[Session]):
7
+ def to_dict(self, obj: Session) -> dict:
8
+ return {
9
+ "id": self.dump_uuid(obj.id),
10
+ "username": obj.username,
11
+ "telegram_user_id": obj.telegram_user_id,
12
+ "room_uuid": self.dump_uuid(obj.room_uuid),
13
+ "created_at": self.dump_datetime(obj.created_at),
14
+ }
15
+
16
+ def to_obj(self, data: dict) -> Session:
17
+ return Session(
18
+ id=self.get_uuid(data, "id"),
19
+ username=self.get(data, "username"),
20
+ _room_uuid=self.get_uuid_or_none(data, "room_uuid"),
21
+ _telegram_user_id=self.get(data, "telegram_user_id"),
22
+ created_at=self.get_datetime(data, "created_at")
23
+ )
24
+
25
+ def sessions_to_members(self, sessions: list[Session], target_session: Session) -> list[RoomMember]:
26
+ members = []
27
+ for s in sessions:
28
+ if target_session.id == s.id:
29
+ is_owner = True
30
+ else:
31
+ is_owner = False
32
+
33
+ member = RoomMember(
34
+ username=s.username,
35
+ session_id=s.id,
36
+ is_owner=is_owner
37
+ )
38
+ members.append(member)
39
+ return members
40
+
41
+
@@ -0,0 +1,14 @@
1
+ from datetime import datetime
2
+ from uuid import UUID
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass
7
+ class BaseModel:
8
+ id: UUID
9
+ created_at: datetime
10
+
11
+ @classmethod
12
+ def model_name(cls) -> str:
13
+ return cls.__name__.lower()
14
+
@@ -0,0 +1,15 @@
1
+ from datetime import datetime
2
+ from dataclasses import dataclass
3
+ from uuid import UUID
4
+ from clipcloudlib.models.redis.base import BaseModel
5
+
6
+
7
+ @dataclass
8
+ class Room(BaseModel):
9
+ room_code: str
10
+ owner_session_id: UUID
11
+
12
+
13
+ @dataclass
14
+ class RoomAlias():
15
+ room_code: str
@@ -0,0 +1,35 @@
1
+ from typing import Annotated, Optional
2
+ from uuid import UUID
3
+ from dataclasses import dataclass
4
+ from clipcloudlib.required import Required
5
+ from clipcloudlib.exceptions import MissingAttributeError
6
+ from clipcloudlib.models.redis.base import BaseModel
7
+
8
+
9
+ @dataclass
10
+ class Session(BaseModel):
11
+ username: str
12
+ _room_uuid: UUID | None = None
13
+ _telegram_user_id: int | None = None
14
+
15
+ @property
16
+ def room_uuid(self) -> UUID:
17
+ if self._room_uuid is None:
18
+ raise MissingAttributeError(
19
+ "The user has not joined the room"
20
+ )
21
+ return self._room_uuid
22
+
23
+ @room_uuid.setter
24
+ def room_uuid(self, value: UUID | None) -> None:
25
+ self._room_uuid = value
26
+
27
+ @property
28
+ def telegram_user_id(self) -> int:
29
+ if self._telegram_user_id is None:
30
+ raise MissingAttributeError("The user does not have telegram_user_id")
31
+ return self._telegram_user_id
32
+
33
+ @telegram_user_id.setter
34
+ def telegram_user_id(self, value: int | None=None) -> None:
35
+ self._telegram_user_id = value
@@ -0,0 +1,22 @@
1
+ from exceptions import MissingAttributeError
2
+
3
+
4
+ class Required:
5
+
6
+ def __set_name__(self, owner, name):
7
+ self.name = name
8
+
9
+ def __get__(self, instance, owner):
10
+ if instance is None:
11
+ return self
12
+
13
+ value = instance.__dict__.get(self.name)
14
+ if value is None:
15
+ raise MissingAttributeError(
16
+ f"{self.name} is not set"
17
+ )
18
+
19
+ return value
20
+
21
+ def __set__(self, instance, value):
22
+ instance.__dict__[self.name] = value
@@ -0,0 +1,17 @@
1
+ from datetime import datetime
2
+ from uuid import UUID
3
+ from pydantic import BaseModel, ConfigDict
4
+
5
+
6
+ class RoomSchema(BaseModel):
7
+ id: UUID
8
+ room_code: str
9
+ created_at: datetime
10
+
11
+ model_config = ConfigDict(from_attributes=True)
12
+
13
+
14
+ class RoomMember(BaseModel):
15
+ session_id: UUID
16
+ username: str
17
+ is_owner: bool = False
@@ -0,0 +1,20 @@
1
+ from typing import Optional
2
+ from uuid import UUID
3
+ from pydantic import BaseModel, ConfigDict
4
+
5
+
6
+ class SessionSchema(BaseModel):
7
+ id: UUID
8
+ username: str
9
+ room_uuid: Optional[UUID] = None
10
+ telegram_user_id: Optional[int] = None
11
+ model_config = ConfigDict(from_attributes=True)
12
+
13
+
14
+ class SessionSchemaAccessToken(BaseModel):
15
+ id: UUID
16
+ username: str
17
+ room_uuid: Optional[UUID] = None
18
+ access_token: str
19
+
20
+ model_config = ConfigDict(from_attributes=True)
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: clipcloudlib
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Project-URL: Repository, https://github.com/rorka491/clipcloud-lib.git
6
+ Requires-Python: >=3.13
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: build>=1.5.0
9
+ Requires-Dist: pydantic>=2.13.4
@@ -0,0 +1,17 @@
1
+ README.md
2
+ pyproject.toml
3
+ clipcloudlib/exceptions.py
4
+ clipcloudlib/required.py
5
+ clipcloudlib.egg-info/PKG-INFO
6
+ clipcloudlib.egg-info/SOURCES.txt
7
+ clipcloudlib.egg-info/dependency_links.txt
8
+ clipcloudlib.egg-info/requires.txt
9
+ clipcloudlib.egg-info/top_level.txt
10
+ clipcloudlib/mappers/base.py
11
+ clipcloudlib/mappers/room.py
12
+ clipcloudlib/mappers/session.py
13
+ clipcloudlib/models/redis/base.py
14
+ clipcloudlib/models/redis/room.py
15
+ clipcloudlib/models/redis/session.py
16
+ clipcloudlib/schemas/room.py
17
+ clipcloudlib/schemas/session.py
@@ -0,0 +1,2 @@
1
+ build>=1.5.0
2
+ pydantic>=2.13.4
@@ -0,0 +1 @@
1
+ clipcloudlib
@@ -0,0 +1,16 @@
1
+ [project]
2
+ name = "clipcloudlib"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ dependencies = [
8
+ "build>=1.5.0",
9
+ "pydantic>=2.13.4",
10
+ ]
11
+
12
+ [project.urls]
13
+ Repository = "https://github.com/rorka491/clipcloud-lib.git"
14
+
15
+ [tool.hatch.build.targets.wheel]
16
+ packages = ["clipcloudlib"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+