How to use the vcard.vcard_errors.NOTE_INVALID_PARAMETER_NAME 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
'message': vcard_errors.NOTE_DOT_AT_LINE_START,
    'vcards': ('dot_at_line_start.vcf',)}
VCARDS_EMPTY_VCARD = {
    'message': vcard_errors.NOTE_EMPTY_VCARD,
    'vcards': ('', None)}
VCARDS_INVALID_DATE = {
    'message': vcard_errors.NOTE_INVALID_DATE,
    'vcards': tuple()}
VCARDS_INVALID_LANGUAGE_VALUE = {
    'message': vcard_errors.NOTE_INVALID_LANGUAGE_VALUE,
    'vcards': ('invalid_language_value.vcf',)}
VCARDS_INVALID_LINE_SEPARATOR = {
    'message': vcard_errors.NOTE_INVALID_LINE_SEPARATOR,
    'vcards': ('line_ending_mac.vcf', 'line_ending_unix.vcf', 'line_ending_mixed.vcf',)}
VCARDS_INVALID_PARAM_NAME = {
    'message': vcard_errors.NOTE_INVALID_PARAMETER_NAME,
    'vcards': ('invalid_param_name.vcf',)}
VCARDS_INVALID_PARAM_VALUE = {
    'message': vcard_errors.NOTE_INVALID_PARAMETER_VALUE,
    'vcards': ('invalid_param_value.vcf',)}
VCARDS_INVALID_PROPERTY_NAME = {
    'message': vcard_errors.NOTE_INVALID_PROPERTY_NAME,
    'vcards': ('invalid_property_foo.vcf',)}
VCARDS_INVALID_SUB_VALUE = {
    'message': vcard_errors.NOTE_INVALID_SUB_VALUE,
    'vcards': tuple()}
VCARDS_INVALID_SUB_VALUE_COUNT = {
    'message': vcard_errors.NOTE_INVALID_SUB_VALUE_COUNT,
    'vcards': tuple()}
VCARDS_INVALID_TEXT_VALUE = {
    'message': vcard_errors.NOTE_INVALID_TEXT_VALUE,
    'vcards': tuple()}
github l0b0 / vcard / vcard / vcard_validator.py View on Github external
"""
    Get the parameter name and value(s). RFC 2426 page 29.

    @param param_string: Single parameter and values
    @return: Dictionary with a parameter name and values
    """
    try:
        param_name, values_string = vcard_utils.split_unescaped(param_string, '=')
    except ValueError as error:
        raise VCardItemCountError('{0}: {1}'.format(NOTE_MISSING_PARAM_VALUE, str(error)), {})

    values = get_vcard_property_param_values(values_string)

    # Validate
    if not re.match('^[{0}]+$'.format(re.escape(ID_CHARACTERS)), param_name):
        raise VCardNameError('{0}: {1}'.format(NOTE_INVALID_PARAMETER_NAME, param_name), {})

    return {'name': param_name, 'values': values}
github l0b0 / vcard / vcard / vcard_validators.py View on Github external
_expect_sub_value_count(property_.values[0], 1)
            validate_text_value(property_.values[0][0])

        elif property_name == 'TEL':
            # 
            if property_.parameters is not None:
                for parameter_name, param_values in property_.parameters.items():
                    if parameter_name.upper() == 'TYPE':
                        for param_sub_value in param_values:
                            if param_sub_value.lower() not in TELEPHONE_TYPE_VALUES:
                                raise VCardValueError(
                                    '{0}: {1}'.format(NOTE_INVALID_PARAMETER_VALUE, param_sub_value), {})
                        if set([value.lower() for value in param_values]) == {'voice'}:
                            warnings.warn('{0}: {1}'.format(WARN_DEFAULT_TYPE_VALUE, property_.values))
                    else:
                        raise VCardNameError('{0}: {1}'.format(NOTE_INVALID_PARAMETER_NAME, parameter_name), {})
            _expect_value_count(property_.values, 1)
            _expect_sub_value_count(property_.values[0], 1)

        elif property_name == 'EMAIL':
            # 
            if property_.parameters is not None:
                for parameter_name, param_values in property_.parameters.items():
                    if parameter_name.upper() == 'TYPE':
                        for param_sub_value in param_values:
                            if param_sub_value.lower() not in EMAIL_TYPE_VALUES:
                                warnings.warn('{0}: {1}'.format(WARN_INVALID_EMAIL_TYPE, param_sub_value))
                        if set([value.lower() for value in param_values]) == {'internet'}:
                            warnings.warn('{0}: {1[values]}'.format(WARN_DEFAULT_TYPE_VALUE, property_))
                    else:
                        raise VCardNameError('{0}: {1}'.format(NOTE_INVALID_PARAMETER_NAME, parameter_name), {})
            _expect_value_count(property_.values, 1)
github l0b0 / vcard / vcard / vcard_validators.py View on Github external
_expect_parameters(property_)
            for parameter_name, param_values in property_.parameters.items():
                if parameter_name.upper() == 'VALUE':
                    if param_values != {'uri'}:
                        raise VCardValueError('{0}: {1}'.format(NOTE_INVALID_PARAMETER_VALUE, param_values), {})
                    if 'CONTEXT' in property_.parameters:
                        raise VCardValueError(
                            '{0}: {1} and {2}'.format(NOTE_MISMATCH_PARAMETER, ('VALUE', 'CONTEXT')), {})
                elif parameter_name.upper() == 'CONTEXT':
                    if param_values != {'word'}:
                        raise VCardValueError('{0}: {1}'.format(NOTE_INVALID_PARAMETER_VALUE, param_values), {})
                    if 'VALUE' in property_.parameters:
                        raise VCardValueError(
                            '{0}: {1} and {2}'.format(NOTE_MISMATCH_PARAMETER, ('VALUE', 'CONTEXT')), {})
                else:
                    raise VCardNameError('{0}: {1}'.format(NOTE_INVALID_PARAMETER_NAME, parameter_name), {})

        if property_name == 'FN':
            # 
            if property_.parameters is not None:
                for parameter in property_.parameters.items():
                    validate_text_parameter(parameter)
            _expect_value_count(property_.values, 1)
            _expect_sub_value_count(property_.values[0], 1)
            validate_text_value(property_.values[0][0])

        elif property_name == 'VERSION':
            _expect_no_parameters(property_)
            _expect_value_count(property_.values, 1)
            if property_.values[0][0] != '3.0':
                raise VCardValueError(
                    '{0}: {1} (expected "3.0")'.format(NOTE_INVALID_VALUE, property_.values[0][0]), {})