Commit 8ea505a1 authored by Moul's avatar Moul

[enh] output conditions: add __eq__() and __hash__() methods

parent e5132867
...@@ -48,6 +48,19 @@ class SIG: ...@@ -48,6 +48,19 @@ class SIG:
def __str__(self) -> str: def __str__(self) -> str:
return self.value return self.value
def __eq__(self, other: Any) -> bool:
"""
Check SIG instances equality
"""
if not isinstance(other, SIG):
return NotImplemented
return self.value == other.value and \
self.pubkey == other.pubkey
def __hash__(self) -> int:
return hash((self.value, self.pubkey))
@classmethod @classmethod
def token(cls: Type[SIGType], pubkey: str) -> SIGType: def token(cls: Type[SIGType], pubkey: str) -> SIGType:
""" """
...@@ -94,6 +107,19 @@ class CSV: ...@@ -94,6 +107,19 @@ class CSV:
def __str__(self) -> str: def __str__(self) -> str:
return self.value return self.value
def __eq__(self, other: Any) -> bool:
"""
Check CSV instances equality
"""
if not isinstance(other, CSV):
return NotImplemented
return self.value == other.value and \
self.time == other.time
def __hash__(self) -> int:
return hash((self.value, self.time))
@classmethod @classmethod
def token(cls: Type[CSVType], time: int) -> CSVType: def token(cls: Type[CSVType], time: int) -> CSVType:
""" """
...@@ -139,6 +165,19 @@ class CLTV: ...@@ -139,6 +165,19 @@ class CLTV:
def __str__(self) -> str: def __str__(self) -> str:
return self.value return self.value
def __eq__(self, other: Any) -> bool:
"""
Check CLTV instances equality
"""
if not isinstance(other, CLTV):
return NotImplemented
return self.value == other.value and \
self.timestamp == other.timestamp
def __hash__(self) -> int:
return hash((self.value, self.timestamp))
@classmethod @classmethod
def token(cls: Type[CLTVType], timestamp: int) -> CLTVType: def token(cls: Type[CLTVType], timestamp: int) -> CLTVType:
""" """
...@@ -184,6 +223,19 @@ class XHX: ...@@ -184,6 +223,19 @@ class XHX:
def __str__(self) -> str: def __str__(self) -> str:
return self.value return self.value
def __eq__(self, other: Any) -> bool:
"""
Check XHX instances equality
"""
if not isinstance(other, XHX):
return NotImplemented
return self.value == other.value and \
self.sha_hash == other.sha_hash
def __hash__(self) -> int:
return hash((self.value, self.sha_hash))
@classmethod @classmethod
def token(cls: Type[XHXType], sha_hash: str) -> XHXType: def token(cls: Type[XHXType], sha_hash: str) -> XHXType:
""" """
...@@ -262,6 +314,21 @@ class Condition: ...@@ -262,6 +314,21 @@ class Condition:
self.right = '' self.right = ''
self.op = '' self.op = ''
def __eq__(self, other: Any) -> bool:
"""
Check Condition instances equality
"""
if not isinstance(other, Condition):
return NotImplemented
return self.value == other.value and \
self.left == other.left and \
self.right == other.right and \
self.op == other.op
def __hash__(self) -> int:
return hash((self.value, self.left, self.right, self.op))
def __str__(self) -> str: def __str__(self) -> str:
return self.value return self.value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment