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__ = ()
|
__slots__ = ()
|
||||||
item_class = str
|
item_class = str
|
||||||
|
|
||||||
def __init__(self, message):
|
@classmethod
|
||||||
|
def create_normalized(cls, message):
|
||||||
message[:] = clean_tags(message)
|
message[:] = clean_tags(message)
|
||||||
self.message = message
|
return cls(message)
|
||||||
|
|
||||||
def append(self, tag: str):
|
def append(self, tag: str):
|
||||||
tag = normalize_tag(tag)
|
tag = normalize_tag(tag)
|
||||||
if tag not in self.message:
|
if tag not in self._message:
|
||||||
self.message.append(tag)
|
self._message.append(tag)
|
||||||
|
|
||||||
def extend(self, tags: List[str]):
|
def extend(self, tags: List[str]):
|
||||||
tags = clean_tags(tags)
|
tags = clean_tags(tags)
|
||||||
tags = list(set(tags).difference(set(self.message)))
|
tags = list(set(tags).difference(set(self._message)))
|
||||||
self.message.extend(tags)
|
self._message.extend(tags)
|
||||||
|
|
|
@ -167,6 +167,10 @@ class BaseClaim:
|
||||||
def tags(self) -> List[str]:
|
def tags(self) -> List[str]:
|
||||||
return TagList(self.claim.message.tags)
|
return TagList(self.claim.message.tags)
|
||||||
|
|
||||||
|
@tags.setter
|
||||||
|
def tags(self, tags: List[str]):
|
||||||
|
self.claim.message.tags = TagList.create_normalized(tags)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def languages(self) -> LanguageList:
|
def languages(self) -> LanguageList:
|
||||||
return LanguageList(self.claim.message.languages)
|
return LanguageList(self.claim.message.languages)
|
||||||
|
|
Loading…
Reference in a new issue