How to use the vdirsyncer.vobject._Component.parse function in vdirsyncer

To help you get started, we’ve selected a few vdirsyncer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / vdirsyncer / tests / unit / utils / test_vobject.py View on Github external
def test_component_contains():
    item = vobject._Component.parse([
        'BEGIN:FOO',
        'FOO:YES',
        'END:FOO'
    ])

    assert 'FOO' in item
    assert 'BAZ' not in item

    with pytest.raises(ValueError):
        42 in item
github pimutils / vdirsyncer / tests / unit / utils / test_vobject.py View on Github external
def test_input_types():
    lines = ['BEGIN:FOO', 'FOO:BAR', 'END:FOO']

    for x in (lines, '\r\n'.join(lines), '\r\n'.join(lines).encode('ascii')):
        c = vobject._Component.parse(x)
        assert c.name == 'FOO'
        assert c.props == ['FOO:BAR']
        assert not c.subcomponents
github pimutils / vdirsyncer / tests / unit / utils / test_vobject.py View on Github external
def parse(self, unparsed):
        return vobject._Component.parse(unparsed)
github pimutils / vdirsyncer / tests / unit / utils / test_vobject.py View on Github external
def test_multiple_items():
    with pytest.raises(ValueError) as excinfo:
        vobject._Component.parse([
            'BEGIN:FOO',
            'END:FOO',
            'BEGIN:FOO',
            'END:FOO',
        ])

    assert 'Found 2 components, expected one' in str(excinfo.value)

    c1, c2 = vobject._Component.parse([
        'BEGIN:FOO',
        'END:FOO',
        'BEGIN:FOO',
        'END:FOO',
    ], multiple=True)
    assert c1.name == c2.name == 'FOO'
github pimutils / vdirsyncer / vdirsyncer / vobject.py View on Github external
def with_uid(self, new_uid):
        parsed = _Component.parse(self.raw)
        stack = [parsed]
        while stack:
            component = stack.pop()
            stack.extend(component.subcomponents)

            if component.name in ('VEVENT', 'VTODO', 'VJOURNAL', 'VCARD'):
                del component['UID']
                if new_uid:
                    component['UID'] = new_uid

        return Item('\r\n'.join(parsed.dump_lines()))
github pimutils / vdirsyncer / vdirsyncer / vobject.py View on Github external
def split_collection(text):
    assert isinstance(text, str)
    inline = []
    items = {}  # uid => item
    ungrouped_items = []

    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 '\r\n'.join(item.dump_lines())
github pimutils / vdirsyncer / vdirsyncer / vobject.py View on Github external
def parsed(self):
        '''Don't cache because the rv is mutable.'''
        try:
            return _Component.parse(self.raw)
        except Exception:
            return None
github pimutils / vdirsyncer / vdirsyncer / vobject.py View on Github external
def join_collection(items, wrappers=_default_join_wrappers):
    '''
    :param wrappers: {
        item_type: wrapper_type
    }
    '''

    items1, items2 = tee((_Component.parse(x)
                          for x in items), 2)
    item_type, wrapper_type = _get_item_type(items1, wrappers)
    wrapper_props = []

    def _get_item_components(x):
        if x.name == wrapper_type:
            wrapper_props.extend(x.props)
            return x.subcomponents
        else:
            return [x]

    components = chain(*(_get_item_components(x) for x in items2))
    lines = chain(*uniq(tuple(x.dump_lines()) for x in components))

    if wrapper_type is not None:
        lines = chain(*(