# HG changeset patch # User Paul Boddie # Date 1422820973 -3600 # Node ID 9a293696e570fa68d941ed8f7c808680f7b8b1df # Parent c2d3c267e55fe287a0d91e830ec4f089788ae6d0 Moved is_new_object into the data module. diff -r c2d3c267e55f -r 9a293696e570 imiptools/content.py --- a/imiptools/content.py Sun Feb 01 19:59:29 2015 +0100 +++ b/imiptools/content.py Sun Feb 01 21:02:53 2015 +0100 @@ -24,8 +24,8 @@ from email.mime.text import MIMEText from imiptools.config import MANAGER_PATH, MANAGER_URL from imiptools.data import Object, parse_object, \ - get_address, get_fragments, \ - get_uri, get_value, uri_dict, uri_item + get_address, get_fragments, get_uri, get_value, \ + is_new_object, uri_dict, uri_item from imiptools.dates import * from imiptools.period import have_conflict, insert_period, remove_period from pytz import timezone @@ -38,28 +38,6 @@ except ImportError: from StringIO import StringIO -def is_new_object(old_sequence, new_sequence, old_dtstamp, new_dtstamp, partstat_set): - - """ - Return for the given 'old_sequence' and 'new_sequence', 'old_dtstamp' and - 'new_dtstamp', and the 'partstat_set' indication, whether the object - providing the new information is really newer than the object providing the - old information. - """ - - have_sequence = old_sequence is not None and new_sequence is not None - is_same_sequence = have_sequence and int(new_sequence) == int(old_sequence) - - have_dtstamp = old_dtstamp and new_dtstamp - is_old_dtstamp = have_dtstamp and new_dtstamp < old_dtstamp or old_dtstamp and not new_dtstamp - - is_old_sequence = have_sequence and ( - int(new_sequence) < int(old_sequence) or - is_same_sequence and is_old_dtstamp - ) - - return is_same_sequence and partstat_set or not is_old_sequence - # NOTE: Need to expose the 100 day window for recurring events in the # NOTE: configuration. diff -r c2d3c267e55f -r 9a293696e570 imiptools/data.py --- a/imiptools/data.py Sun Feb 01 19:59:29 2015 +0100 +++ b/imiptools/data.py Sun Feb 01 21:02:53 2015 +0100 @@ -223,4 +223,28 @@ def uri_items(items): return [(get_uri(value), attr) for value, attr in items] +# Operations on structure data. + +def is_new_object(old_sequence, new_sequence, old_dtstamp, new_dtstamp, partstat_set): + + """ + Return for the given 'old_sequence' and 'new_sequence', 'old_dtstamp' and + 'new_dtstamp', and the 'partstat_set' indication, whether the object + providing the new information is really newer than the object providing the + old information. + """ + + have_sequence = old_sequence is not None and new_sequence is not None + is_same_sequence = have_sequence and int(new_sequence) == int(old_sequence) + + have_dtstamp = old_dtstamp and new_dtstamp + is_old_dtstamp = have_dtstamp and new_dtstamp < old_dtstamp or old_dtstamp and not new_dtstamp + + is_old_sequence = have_sequence and ( + int(new_sequence) < int(old_sequence) or + is_same_sequence and is_old_dtstamp + ) + + return is_same_sequence and partstat_set or not is_old_sequence + # vim: tabstop=4 expandtab shiftwidth=4