forked from LBRYCommunity/lbry-sdk
Normalize only when writing (setting, updating)
This commit is contained in:
parent
db34f89251
commit
7cb03dde44
2 changed files with 11 additions and 6 deletions
|
@ -540,16 +540,17 @@ class TagList(BaseMessageList[str]):
|
|||
__slots__ = ()
|
||||
item_class = str
|
||||
|
||||
def __init__(self, message):
|
||||
@classmethod
|
||||
def create_normalized(cls, message):
|
||||
message[:] = clean_tags(message)
|
||||
self.message = message
|
||||
return cls(message)
|
||||
|
||||
def append(self, tag: str):
|
||||
tag = normalize_tag(tag)
|
||||
if tag not in self.message:
|
||||
self.message.append(tag)
|
||||
if tag not in self._message:
|
||||
self._message.append(tag)
|
||||
|
||||
def extend(self, tags: List[str]):
|
||||
tags = clean_tags(tags)
|
||||
tags = list(set(tags).difference(set(self.message)))
|
||||
self.message.extend(tags)
|
||||
tags = list(set(tags).difference(set(self._message)))
|
||||
self._message.extend(tags)
|
||||
|
|
|
@ -167,6 +167,10 @@ class BaseClaim:
|
|||
def tags(self) -> List[str]:
|
||||
return TagList(self.claim.message.tags)
|
||||
|
||||
@tags.setter
|
||||
def tags(self, tags: List[str]):
|
||||
self.claim.message.tags = TagList.create_normalized(tags)
|
||||
|
||||
@property
|
||||
def languages(self) -> LanguageList:
|
||||
return LanguageList(self.claim.message.languages)
|
||||
|
|
Loading…
Reference in a new issue