How to use the vcard.vcard_errors.VCardItemCountError 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 / vcard / vcard_validator.py View on Github external
def get_vcard_property_parameter(param_string):
    """
    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_validator.py View on Github external
def get_vcard_property(property_line):
    """
    Get a single property.

    @param property_line: Single unfolded vCard line
    @return: Dictionary with name, parameters and values
    """
    property_parts = vcard_utils.split_unescaped(property_line, ':')
    if len(property_parts) < 2:
        raise VCardItemCountError('{0}: {1}'.format(NOTE_MISSING_VALUE_STRING, property_line), {})
    elif len(property_parts) > 2:
        # Merge - Colon doesn't have to be escaped in values
        property_parts[1] = ':'.join(property_parts[1:])
        property_parts = property_parts[:2]
    property_string, values_string = property_parts

    # Split property name and property parameters
    property_name_and_params = vcard_utils.split_unescaped(property_string, ';')

    property_ = VcardProperty(property_name_and_params.pop(0))

    # String validation
    if not property_.name.upper() in ALL_PROPERTIES and not re.match(
            '^X-[{0}]+$'.format(re.escape(ID_CHARACTERS)), property_.name, re.IGNORECASE):
        raise VCardNameError('{0}: {1}'.format(NOTE_INVALID_PROPERTY_NAME, property_.name), {})
github l0b0 / vcard / vcard / vcard_validators.py View on Github external
def _expect_no_parameters(property_):
    parameters = __get_parameters(property_)
    if parameters is not None:
        raise VCardItemCountError('{0}: {1}'.format(NOTE_NON_EMPTY_PARAMETER, parameters), {})
github l0b0 / vcard / vcard / vcard_validator.py View on Github external
properties = []
    for index in range(len(lines)):
        property_line = lines[index]
        if property_line != NEWLINE_CHARACTERS:
            try:
                properties.append(get_vcard_property(property_line))
            except VCardError as error:
                error.context['vCard line'] = index
                err_type = type(error)
                raise err_type(
                    error.message,
                    error.context)

    for mandatory_property in MANDATORY_PROPERTIES:
        if mandatory_property not in [property_.name.upper() for property_ in properties]:
            raise VCardItemCountError(
                '{0}: {1}'.format(NOTE_MISSING_PROPERTY, mandatory_property), {'Property': mandatory_property})

    return properties
github l0b0 / vcard / vcard / vcard_validators.py View on Github external
def _expect_sub_value_count(sub_values, count):
    if len(sub_values) != count:
        raise VCardItemCountError(
            '{0}: {1:d} (expected {2})'.format(NOTE_INVALID_SUB_VALUE_COUNT, len(sub_values), count), {})
github l0b0 / vcard / vcard / vcard_validators.py View on Github external
def _expect_value_count(values, count):
    if len(values) != count:
        raise VCardItemCountError('{0}: {1:d} (expected {2})'.format(NOTE_INVALID_VALUE_COUNT, len(values), count), {})