ref: asPrintable instead of __repr__

This commit is contained in:
relikd
2024-01-27 16:17:53 +01:00
parent f3ae2e3ff4
commit 43d979f630

View File

@@ -76,8 +76,11 @@ class Queryable: # Protocol
def parent(self) -> int: def parent(self) -> int:
return self._parent return self._parent
def classStr(self, value: str) -> str: def __repr__(self) -> str:
return '<{} "{}">'.format(self.__class__.__name__, value) return '<{} "{}">'.format(self.__class__.__name__, self.asPrintable())
def asPrintable(self) -> str:
return '?'
def asVCard(self, markPref: bool) -> str: def asVCard(self, markPref: bool) -> str:
raise NotImplementedError() raise NotImplementedError()
@@ -96,8 +99,8 @@ class Email(Queryable):
self.label = x520(row[1]) or '' # type: str self.label = x520(row[1]) or '' # type: str
self.email = x520(row[2]) or '' # type: str self.email = x520(row[2]) or '' # type: str
def __repr__(self) -> str: def asPrintable(self) -> str:
return self.classStr(self.email) return self.email
def asVCard(self, markPref: bool) -> str: def asVCard(self, markPref: bool) -> str:
return buildLabel( return buildLabel(
@@ -117,8 +120,8 @@ class Phone(Queryable):
self.label = x520(row[1]) or '' # type: str self.label = x520(row[1]) or '' # type: str
self.number = x520(row[2]) or '' # type: str self.number = x520(row[2]) or '' # type: str
def __repr__(self) -> str: def asPrintable(self) -> str:
return self.classStr(self.number) return self.number
def asVCard(self, markPref: bool) -> str: def asVCard(self, markPref: bool) -> str:
mapping = { mapping = {
@@ -158,9 +161,9 @@ class Address(Queryable):
self.zip = x520(row[5]) or '' # type: str self.zip = x520(row[5]) or '' # type: str
self.country = x520(row[6]) or '' # type: str self.country = x520(row[6]) or '' # type: str
def __repr__(self) -> str: def asPrintable(self) -> str:
return self.classStr(', '.join(filter(None, ( return ', '.join(filter(None, (
self.street, self.city, self.state, self.zip, self.country)))) self.street, self.city, self.state, self.zip, self.country)))
def asVCard(self, markPref: bool) -> str: def asVCard(self, markPref: bool) -> str:
value = ';'.join(( value = ';'.join((
@@ -182,8 +185,8 @@ class SocialProfile(Queryable):
# no x520(); actually, Apple does that ... and it breaks on reimport # no x520(); actually, Apple does that ... and it breaks on reimport
self.user = row[2] or '' # type: str self.user = row[2] or '' # type: str
def __repr__(self) -> str: def asPrintable(self) -> str:
return self.classStr(self.service + ':' + self.user) return self.service + ':' + self.user
def asVCard(self, markPref: bool) -> str: def asVCard(self, markPref: bool) -> str:
# Apple does some x-user, x-apple, and url stuff that is wrong # Apple does some x-user, x-apple, and url stuff that is wrong
@@ -202,8 +205,8 @@ class Note(Queryable):
self._parent = row[0] # type: int self._parent = row[0] # type: int
self.text = x520(row[1]) or '' # type: str self.text = x520(row[1]) or '' # type: str
def __repr__(self) -> str: def asPrintable(self) -> str:
return self.classStr(self.text) return self.text
def asVCard(self, markPref: bool) -> str: def asVCard(self, markPref: bool) -> str:
return self.text return self.text
@@ -222,8 +225,8 @@ class URL(Queryable):
self.label = x520(row[1]) or '' # type: str self.label = x520(row[1]) or '' # type: str
self.url = x520(row[2]) or '' # type: str self.url = x520(row[2]) or '' # type: str
def __repr__(self) -> str: def asPrintable(self) -> str:
return self.classStr(self.url) return self.url
def asVCard(self, markPref: bool) -> str: def asVCard(self, markPref: bool) -> str:
return buildLabel('URL', self.label, markPref, self.url) return buildLabel('URL', self.label, markPref, self.url)
@@ -246,9 +249,8 @@ class Service(Queryable):
self.label = x520(row[2]) or '' # type: str self.label = x520(row[2]) or '' # type: str
self.username = x520(row[3]) or '' # type: str self.username = x520(row[3]) or '' # type: str
def __repr__(self) -> str: def asPrintable(self) -> str:
return self.classStr(', '.join(( return ', '.join((self.service, self.label, self.username))
self.service, self.label, self.username)))
def isSpecial(self) -> bool: def isSpecial(self) -> bool:
return self.service in ['Jabber', 'MSN', 'Yahoo', 'ICQ'] return self.service in ['Jabber', 'MSN', 'Yahoo', 'ICQ']