Skip to content

Commit

Permalink
Merge pull request #1 from agateau/enforce-cardinality
Browse files Browse the repository at this point in the history
Make sure there is only one instance of prodid, rev and uid
  • Loading branch information
mbideau authored Mar 22, 2017
2 parents 2d0b4af + 20f3cb2 commit 0a1a248
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions vcardlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
OPTION_UPDATE_GROUP_KEY = True
OPTION_FRENCH_TWEAKS = False

SINGLE_INSTANCE_PROPERTIES = {'prodid', 'rev', 'uid'}

def add_attributes(attributes, a):
"""
Return void
Expand Down Expand Up @@ -382,6 +384,9 @@ def build_vcard(attributes):

logging.debug("Building vcard ...")
vcard = vCard()

defined_single_instance_properties = set()

for a_name, a in attributes.items():
#logging.debug("\tprocessing '%s' -> '%s'", a_name, a)
if a:
Expand Down Expand Up @@ -430,6 +435,11 @@ def build_vcard(attributes):
vcard.add(a_name).value = a_item
logging.debug("\t%s: %s", a_name, a_item)
elif isinstance(a_item, ContentLine):
if a_name in SINGLE_INSTANCE_PROPERTIES:
if a_name in defined_single_instance_properties:
continue
else:
defined_single_instance_properties.add(a_name)
item_added = vcard.add(a_name)
logging.debug("\t%s: %s", a_name, a_item.value)
item_added.value = a_item.value
Expand Down

0 comments on commit 0a1a248

Please sign in to comment.