mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Clean up split_collections
The additional function args aren't pretty, but I think this is easier to grasp.
This commit is contained in:
parent
9c417248de
commit
b10e82b344
1 changed files with 25 additions and 23 deletions
|
|
@ -125,7 +125,15 @@ def split_collection(text):
|
|||
items = {} # uid => item
|
||||
ungrouped_items = []
|
||||
|
||||
def inner(item, main):
|
||||
for main in _Component.parse(text, multiple=True):
|
||||
_split_collection_impl(main, main, inline, items, ungrouped_items)
|
||||
|
||||
for item in chain(items.values(), ungrouped_items):
|
||||
item.subcomponents.extend(inline)
|
||||
yield u'\r\n'.join(item.dump_lines())
|
||||
|
||||
|
||||
def _split_collection_impl(item, main, inline, items, ungrouped_items):
|
||||
if item.name == u'VTIMEZONE':
|
||||
inline.append(item)
|
||||
elif item.name == u'VCARD':
|
||||
|
|
@ -142,18 +150,12 @@ def split_collection(text):
|
|||
wrapper.subcomponents.append(item)
|
||||
elif item.name in (u'VCALENDAR', u'VADDRESSBOOK'):
|
||||
for subitem in item.subcomponents:
|
||||
inner(subitem, item)
|
||||
_split_collection_impl(subitem, item, inline, items,
|
||||
ungrouped_items)
|
||||
else:
|
||||
raise ValueError('Unknown component: {}'
|
||||
.format(item.name))
|
||||
|
||||
for main in _Component.parse(text, multiple=True):
|
||||
inner(main, main)
|
||||
|
||||
for item in chain(items.values(), ungrouped_items):
|
||||
item.subcomponents.extend(inline)
|
||||
yield u'\r\n'.join(item.dump_lines())
|
||||
|
||||
|
||||
_default_join_wrappers = {
|
||||
u'VCALENDAR': u'VCALENDAR',
|
||||
|
|
|
|||
Loading…
Reference in a new issue