Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'message': vcard_errors.NOTE_INVALID_SUB_VALUE_COUNT,
'vcards': tuple()}
VCARDS_INVALID_TEXT_VALUE = {
'message': vcard_errors.NOTE_INVALID_TEXT_VALUE,
'vcards': tuple()}
VCARDS_INVALID_TIME = {
'message': vcard_errors.NOTE_INVALID_TIME,
'vcards': tuple()}
VCARDS_INVALID_TIME_ZONE = {
'message': vcard_errors.NOTE_INVALID_TIME_ZONE,
'vcards': tuple()}
VCARDS_INVALID_URI = {
'message': vcard_errors.NOTE_INVALID_URI,
'vcards': tuple()}
VCARDS_INVALID_VALUE = {
'message': vcard_errors.NOTE_INVALID_VALUE,
'vcards': ('invalid_begin.vcf',)}
VCARDS_INVALID_VALUE_COUNT = {
'message': vcard_errors.NOTE_INVALID_VALUE_COUNT,
'vcards': ('invalid_value_count_wp.vcf',)}
VCARDS_INVALID_X_NAME = {
'message': vcard_errors.NOTE_INVALID_X_NAME,
'vcards': tuple()}
VCARDS_MISMATCH_GROUP = {
'message': vcard_errors.NOTE_MISMATCH_GROUP,
'vcards': ('mismatch_group.vcf',)}
VCARDS_MISMATCH_PARAMETER = {
'message': vcard_errors.NOTE_MISMATCH_PARAMETER,
'vcards': tuple()}
VCARDS_MISSING_GROUP = {
'message': vcard_errors.NOTE_MISSING_GROUP,
'vcards': ('missing_group.vcf',)}
def get_vcard_property_param_values(values_string):
"""
Get the parameter values. RFC 2426 page 29.
@param values_string: Comma separated values
@return: Set of values. Assumes that sequence doesn't matter and that
duplicate values can be discarded, even though RFC 2426 doesn't explicitly
say this. I.e., assumes that TYPE=WORK,VOICE,WORK === TYPE=VOICE,WORK.
"""
values = set(vcard_utils.split_unescaped(values_string, ','))
# Validate
for value in values:
if not re.match(u'^[{0}]+$|^"[{1}]+"$'.format(
re.escape(SAFE_CHARACTERS), re.escape(QUOTE_SAFE_CHARACTERS)), value):
raise VCardValueError('{0}: {1}'.format(NOTE_INVALID_VALUE, value), {})
return values
. Checks are grouped by
property to allow easy overview rather than a short function.
@param property_: Formatted property
"""
property_name = property_.name.upper()
try:
if property_name in ('BEGIN', 'END'):
#
_expect_no_parameters(property_)
_expect_value_count(property_.values, 1)
_expect_sub_value_count(property_.values[0], 1)
if property_.values[0][0].lower() != 'vcard':
raise VCardValueError(
'{0}: {1} (expected "VCARD")'.format(NOTE_INVALID_VALUE, property_.values[0][0]), {})
if property_name == 'NAME':
#
_expect_no_parameters(property_)
_expect_value_count(property_.values, 1)
_expect_sub_value_count(property_.values[0], 1)
validate_text_value(property_.values[0][0])
if property_name == 'PROFILE':
#
_expect_no_parameters(property_)
_expect_value_count(property_.values, 1)
_expect_sub_value_count(property_.values[0], 1)
if property_.values[0][0].lower() != 'vcard':
raise VCardValueError(
'{0}: {1} (expected "VCARD")'.format(NOTE_INVALID_VALUE, property_.values[0][0]), {})
if property_name == 'NAME':
#
_expect_no_parameters(property_)
_expect_value_count(property_.values, 1)
_expect_sub_value_count(property_.values[0], 1)
validate_text_value(property_.values[0][0])
if property_name == 'PROFILE':
#
_expect_no_parameters(property_)
_expect_value_count(property_.values, 1)
_expect_sub_value_count(property_.values[0], 1)
if property_.values[0][0].lower() != 'vcard':
raise VCardValueError(
'{0}: {1} (expected "VCARD")'.format(NOTE_INVALID_VALUE, property_.values[0][0]), {})
validate_text_value(property_.values[0][0])
if property_name == 'SOURCE':
#
_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: