How to use the vcard.vcard_validator.VCard function in vcard

To help you get started, we’ve selected a few vcard 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 l0b0 / vcard / tests / test_package.py View on Github external
def test_valid(self):
        """Valid (but not necessarily sane) vCards"""
        for vcard_file in VCARDS_VALID:
            vcard_text = _get_vcard_file(vcard_file)
            if vcard_text is None:
                continue

            try:
                with warnings.catch_warnings(record=True):
                    vc_obj = vcard_validator.VCard(vcard_text, filename=vcard_file)
                self.assertNotEqual(vc_obj, None)
            except vcard_errors.VCardError as error:
                error_message = '\n\n'.join((
                    'Expected valid vCard for {vcard_file!r}, but it failed to validate'.format(
                        vcard_file=vcard_file
                    ),
                    str(error)
                ))
                self.fail(error_message)
github l0b0 / vcard / tests / test_package.py View on Github external
def test_online(self):
        """vCards in references which are invalid"""
        for vcard_file in VCARDS_REFERENCE_ERRORS:
            vcard_text = _get_vcard_file(vcard_file)
            if vcard_text is None:
                continue

            with warnings.catch_warnings(record=True):
                self.assertRaises(
                    vcard_errors.VCardError,
                    vcard_validator.VCard,
                    vcard_text)
github l0b0 / vcard / tests / test_package.py View on Github external
def test_failing(self):
        """vCards with errors"""
        for test_group in VCARDS_WITH_ERROR:
            for vcard_file in test_group['vcards']:
                vcard_text = _get_vcard_file(vcard_file)
                if vcard_text is None:
                    continue

                try:
                    with warnings.catch_warnings(record=True):
                        vcard_validator.VCard(vcard_text, filename=vcard_file)
                        self.fail('Invalid vCard created:\n{0}'.format(vcard_text))
                except vcard_errors.VCardError as error:
                    error_message = '\n\n'.join((
                        'Wrong message for vCard {vcard_file!r}:'.format(vcard_file=vcard_file),
                        'Expected: {expected}'.format(expected=test_group['message']),
                        'Got: {got}'.format(got=str(error)),
                        ))
                    self.assertTrue(
                        test_group['message'] in str(error),
                        msg=error_message
                    )
github l0b0 / vcard / vcard / vcard_validator.py View on Github external
file_pointer = sys.stdin
    else:
        file_pointer = codecs.open(filename, 'r', 'utf-8')

    contents = file_pointer.read().splitlines(True)

    vcard_text = ''
    result = ''
    try:
        for index in range(len(contents)):
            line = contents[index]
            vcard_text += line

            if line == NEWLINE_CHARACTERS:
                try:
                    vcard = VCard(vcard_text, filename)
                    vcard_text = ''
                    if verbose:
                        print(vcard)
                except VCardError as error:
                    error.context['File'] = filename
                    error.context['File line'] = index
                    err_type = type(error)
                    raise err_type(error.message, error.context)

    except VCardError as error:
        result += str(error)

    if vcard_text != '' and result == '':
        result += 'Could not process entire %s - %i lines remain' % (filename, len(vcard_text.splitlines(False)))

    if result == '':