| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- class cutter:
- def __init__(self, target: bytes) -> None:
- self.__current = target
- def __check(self, count: int) -> None:
- if count == 0:
- raise RuntimeError("Cutter is already empty.")
- if count > self.size:
- raise RuntimeError("Count is higher than size.")
-
- def from_start(self, count: int) -> bytes:
- self.__check(count)
- result = self.__current[:count]
- self.__current = self.__current[count:]
- return result
- def from_end(self, count: int) -> bytes:
- self.__check(count)
- result = self.__current[self.size - count:]
- self.__current = self.__current[:self.size - count]
- return result
- def cut(self, count: int) -> bytes:
- return self.from_end(count)
- def trim(self, count: int) -> bytes:
- return self.from_start(count)
- @property
- def content(self) -> bytes:
- return self.__current
- @property
- def size(self) -> int:
- return len(self.__current)
- def __len__(self) -> int:
- return self.size
|