49 lines
990 B
Python
49 lines
990 B
Python
from dataclasses import dataclass, field
|
|
from typing import Type
|
|
|
|
# TODO: unnecessary?
|
|
|
|
@dataclass
|
|
class PathItem:
|
|
name: str
|
|
t: Type
|
|
|
|
@dataclass
|
|
class Path:
|
|
path: list[PathItem] = field(default_factory=list)
|
|
|
|
def append(self, name, t):
|
|
self.path.append(PathItem(name, t))
|
|
|
|
def __str__(self):
|
|
return "/".join([i.name for i in self.path])
|
|
|
|
|
|
@dataclass
|
|
class Group:
|
|
name: str
|
|
passwords: list["Password"] = field(default_factory=list)
|
|
parent: "Group|None" = None
|
|
|
|
@property
|
|
def path(self):
|
|
if self.parent is None:
|
|
new_path = Path()
|
|
new_path.append(self.name, type(self))
|
|
return new_path
|
|
return self.parent.path.append(self.name, type(self))
|
|
|
|
|
|
@dataclass
|
|
class Password:
|
|
name: str
|
|
group: Group
|
|
|
|
@property
|
|
def path(self):
|
|
return self.group.path.append(self.name, type(self))
|
|
|
|
class UnencryptedPassword(Password):
|
|
def __init__(self, name: str, value: str, group: Group):
|
|
super().__init__(name, group)
|
|
self.value = value
|