22 lines
559 B
Python
22 lines
559 B
Python
import attr
|
|
|
|
def greater_than_zero(instance, attribute, value):
|
|
if value <= 0:
|
|
raise ValueError('must be greater than 0')
|
|
|
|
def is_positive(instance, attribute, value):
|
|
if value < 0:
|
|
raise ValueError('must be positive')
|
|
|
|
@attr.s
|
|
class Span:
|
|
url: int = attr.ib()
|
|
start: int = attr.ib(validator=is_positive)
|
|
length: int = attr.ib(validator=greater_than_zero)
|
|
|
|
def end(self) -> int:
|
|
return self.start + self.length
|
|
|
|
def for_edl(self) -> str:
|
|
return f'{self.url},start={self.start},length={self.length}'
|