Commit 1b11aaf7 authored by Philipp Hörist's avatar Philipp Hörist

VCard4: Add copy()

parent 6b441d7f
Pipeline #6900 passed with stages
in 4 minutes and 57 seconds
......@@ -173,6 +173,9 @@ class Parameter:
node.addChild(self.type, payload=self.value)
return node
def copy(self):
return self.__class__(value=self.value)
@dataclass
class MultiParameter:
......@@ -208,6 +211,9 @@ class MultiParameter:
node.addChild(self.type, payload=value)
return node
def copy(self):
return self.__class__(values=set(self.values))
@dataclass
class LanguageParameter(Parameter):
......@@ -293,6 +299,10 @@ class TzParameter:
node.addChild(self.value_type, payload=self.value)
return node
def copy(self):
return self.__class__(value_type=self.value_type,
value=self.value)
class Parameters:
def __init__(self, parameters=None):
......@@ -330,6 +340,12 @@ class Parameters:
parameter.values.update(types)
def copy(self):
parameters = {}
for name, parameter in self._parameters.items():
parameters[name] = parameter.copy()
return self.__class__(parameters=parameters)
PARAMETER_CLASSES = {
'language': LanguageParameter,
......@@ -377,6 +393,10 @@ class UriProperty:
def is_empty(self):
return not self.value
def copy(self):
return self.__class__(value=self.value,
parameters=self.parameters.copy())
@dataclass
class TextProperty:
......@@ -410,6 +430,10 @@ class TextProperty:
def is_empty(self):
return not self.value
def copy(self):
return self.__class__(value=self.value,
parameters=self.parameters.copy())
@dataclass
class TextListProperty:
......@@ -447,6 +471,10 @@ class TextListProperty:
def is_empty(self):
return not self.values
def copy(self):
return self.__class__(values=list(self.values),
parameters=self.parameters.copy())
@dataclass
class MultipleValueProperty:
......@@ -480,6 +508,11 @@ class MultipleValueProperty:
def is_empty(self):
return not self.value
def copy(self):
return self.__class__(value_type=self.value_type,
value=self.value,
parameters=self.parameters.copy())
@dataclass
class SourceProperty(UriProperty):
......@@ -564,6 +597,13 @@ class NProperty:
return False
return True
def copy(self):
return self.__class__(surname=list(self.surname),
given=list(self.given),
additional=list(self.additional),
prefix=list(self.prefix),
suffix=list(self.suffix),
parameters=self.parameters.copy())
@dataclass
class NicknameProperty(TextListProperty):
......@@ -631,6 +671,11 @@ class GenderProperty:
return False
return True
def copy(self):
return self.__class__(sex=self.sex,
identity=self.identity,
parameters=self.parameters.copy())
@dataclass
class AdrProperty:
......@@ -690,6 +735,16 @@ class AdrProperty:
return False
return True
def copy(self):
return self.__class__(pobox=list(self.pobox),
ext=list(self.ext),
street=list(self.street),
locality=list(self.locality),
region=list(self.region),
code=list(self.code),
country=list(self.country),
parameters=self.parameters.copy())
@dataclass
class TelProperty(MultipleValueProperty):
......@@ -741,6 +796,10 @@ class LangProperty:
def is_empty(self):
return not self.value
def copy(self):
return self.__class__(value=self.value,
parameters=self.parameters.copy())
@dataclass
class TzProperty(MultipleValueProperty):
......@@ -885,6 +944,11 @@ class ClientpidmapProperty:
def is_empty(self):
return not self.uri
def copy(self):
return self.__class__(sourceid=self.sourceid,
uri=self.uri,
parameters=self.parameters.copy())
@dataclass
class UrlProperty(UriProperty):
......@@ -1042,6 +1106,16 @@ class VCard:
raise ValueError('prop not found in vcard')
def copy(self):
properties = []
for group_name, props in self._properties:
if group_name is None:
properties.append((None, props.copy()))
else:
group_properties = [prop.copy() for prop in props]
properties.append((group_name, group_properties))
return self.__class__(properties=properties)
class VCard4(BaseModule):
......
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