mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Lazy-load component in item
This commit is contained in:
parent
bdbfc360ff
commit
325304c50f
1 changed files with 6 additions and 3 deletions
|
|
@ -14,12 +14,15 @@ class Item(object):
|
||||||
def __init__(self, raw, component=None):
|
def __init__(self, raw, component=None):
|
||||||
assert isinstance(raw, str), type(raw)
|
assert isinstance(raw, str), type(raw)
|
||||||
self._raw = raw
|
self._raw = raw
|
||||||
|
if component is not None:
|
||||||
|
self.__dict__['_component'] = component
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def _component(self):
|
||||||
try:
|
try:
|
||||||
self._component = component or \
|
return native.parse_component(self.raw.encode('utf-8'))
|
||||||
native.parse_component(self.raw.encode('utf-8'))
|
|
||||||
except exceptions.VobjectParseError:
|
except exceptions.VobjectParseError:
|
||||||
self._component = None
|
return None
|
||||||
|
|
||||||
def with_uid(self, new_uid):
|
def with_uid(self, new_uid):
|
||||||
if not self._component:
|
if not self._component:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue