Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
>>> validate_x_name('') # Have to start with X- #doctest: +ELLIPSIS +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
VCardNameError: Invalid X-name (See RFC 2426 section 4 for x-name syntax)
...
>>> validate_x_name('x-abc') # X must be upper case # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
VCardNameError: Invalid X-name (See RFC 2426 section 4 for x-name syntax)
String: x-abc
>>> validate_x_name('foo') # Have to start with X- # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
VCardNameError: Invalid X-name (See RFC 2426 section 4 for x-name syntax)
String: foo
"""
if VALID_X_NAME.match(text) is None:
raise VCardNameError(NOTE_INVALID_X_NAME, {'String': text})
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), {})
try:
if len(property_name_and_params) != 0:
property_.parameters = get_vcard_property_params(';'.join(property_name_and_params))
property_.values = get_vcard_property_values(values_string)
# Validate
vcard_validators.validate_vcard_property(property_)
except VCardError as error:
# Add parameter name to error
error.context['Property line'] = property_line
err_type = type(error)
raise err_type(error.message, error.context)
return property_
raise VCardLineError(NOTE_DOT_AT_LINE_START, {})
for index in range(len(lines)):
line = lines[index]
next_match = group_re.match(line)
if not next_match:
raise VCardLineError(NOTE_MISSING_GROUP, {'File line': index + 1})
if next_match.group(1) != group:
raise VCardNameError(
'{0}: {1} != {2}'.format(NOTE_MISMATCH_GROUP, next_match.group(1), group), {'File line': index + 1})
else:
# Make sure there are no groups elsewhere
for index in range(len(lines)):
next_match = group_re.match(lines[index])
if next_match:
raise VCardNameError(
'{0}: {1} != {2}'.format(NOTE_MISMATCH_GROUP, next_match.group(1), group), {'File line': index + 1})
return group
for parameter_name, param_values in property_.parameters.items():
if parameter_name.upper() == 'ENCODING':
if param_values != {'b'}:
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, ('ENCODING', 'VALUE')), {})
elif parameter_name.upper() == 'TYPE' and 'ENCODING' not in property_.parameters:
raise VCardItemCountError('{0}: {1}'.format(NOTE_MISSING_PARAMETER, 'ENCODING'), {})
elif parameter_name.upper() == 'VALUE':
if param_values != {'uri'}:
raise VCardValueError('{0}: {1}'.format(NOTE_INVALID_PARAMETER_VALUE, param_values), {})
else:
validate_uri(property_.values[0][0])
elif parameter_name.upper() not in ['ENCODING', 'TYPE', 'VALUE']:
raise VCardNameError('{0}: {1}'.format(NOTE_INVALID_PARAMETER_NAME, parameter_name), {})
elif property_name == 'BDAY':
#
_expect_no_parameters(property_)
_expect_value_count(property_.values, 1)
_expect_sub_value_count(property_.values[0], 1)
validate_date(property_.values[0][0])
elif property_name == 'ADR':
#
_expect_value_count(property_.values, 7)
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 not in LABEL_TYPE_VALUES: