MCPcopy
hub / github.com/pimutils/vdirsyncer / join_collection

Function join_collection

vdirsyncer/vobject.py:184–217  ·  view source on GitHub ↗

:param wrappers: { item_type: wrapper_type }

(items, wrappers=_default_join_wrappers)

Source from the content-addressed store, hash-verified

182
183
184def join_collection(items, wrappers=_default_join_wrappers):
185 '''
186 :param wrappers: {
187 item_type: wrapper_type
188 }
189 '''
190
191 items1, items2 = tee((_Component.parse(x)
192 for x in items), 2)
193 item_type, wrapper_type = _get_item_type(items1, wrappers)
194 wrapper_props = []
195
196 def _get_item_components(x):
197 if x.name == wrapper_type:
198 wrapper_props.extend(x.props)
199 return x.subcomponents
200 else:
201 return [x]
202
203 components = chain(*(_get_item_components(x) for x in items2))
204 lines = chain(*uniq(tuple(x.dump_lines()) for x in components))
205
206 if wrapper_type is not None:
207 lines = chain(*(
208 ['BEGIN:{}'.format(wrapper_type)],
209 # XXX: wrapper_props is a list of lines (with line-wrapping), so
210 # filtering out duplicate lines will almost certainly break
211 # multiline-values. Since the only props we usually need to
212 # support are PRODID and VERSION, I don't care.
213 uniq(wrapper_props),
214 lines,
215 ['END:{}'.format(wrapper_type)]
216 ))
217 return ''.join(line + '\r\n' for line in lines)
218
219
220def _get_item_type(components, wrappers):

Callers 1

_writeMethod · 0.85

Calls 6

_get_item_typeFunction · 0.85
_get_item_componentsFunction · 0.85
uniqFunction · 0.85
dump_linesMethod · 0.80
joinMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected