1.1 --- a/imiptools/content.py Sun Feb 01 19:59:29 2015 +0100
1.2 +++ b/imiptools/content.py Sun Feb 01 21:02:53 2015 +0100
1.3 @@ -24,8 +24,8 @@
1.4 from email.mime.text import MIMEText
1.5 from imiptools.config import MANAGER_PATH, MANAGER_URL
1.6 from imiptools.data import Object, parse_object, \
1.7 - get_address, get_fragments, \
1.8 - get_uri, get_value, uri_dict, uri_item
1.9 + get_address, get_fragments, get_uri, get_value, \
1.10 + is_new_object, uri_dict, uri_item
1.11 from imiptools.dates import *
1.12 from imiptools.period import have_conflict, insert_period, remove_period
1.13 from pytz import timezone
1.14 @@ -38,28 +38,6 @@
1.15 except ImportError:
1.16 from StringIO import StringIO
1.17
1.18 -def is_new_object(old_sequence, new_sequence, old_dtstamp, new_dtstamp, partstat_set):
1.19 -
1.20 - """
1.21 - Return for the given 'old_sequence' and 'new_sequence', 'old_dtstamp' and
1.22 - 'new_dtstamp', and the 'partstat_set' indication, whether the object
1.23 - providing the new information is really newer than the object providing the
1.24 - old information.
1.25 - """
1.26 -
1.27 - have_sequence = old_sequence is not None and new_sequence is not None
1.28 - is_same_sequence = have_sequence and int(new_sequence) == int(old_sequence)
1.29 -
1.30 - have_dtstamp = old_dtstamp and new_dtstamp
1.31 - is_old_dtstamp = have_dtstamp and new_dtstamp < old_dtstamp or old_dtstamp and not new_dtstamp
1.32 -
1.33 - is_old_sequence = have_sequence and (
1.34 - int(new_sequence) < int(old_sequence) or
1.35 - is_same_sequence and is_old_dtstamp
1.36 - )
1.37 -
1.38 - return is_same_sequence and partstat_set or not is_old_sequence
1.39 -
1.40 # NOTE: Need to expose the 100 day window for recurring events in the
1.41 # NOTE: configuration.
1.42
2.1 --- a/imiptools/data.py Sun Feb 01 19:59:29 2015 +0100
2.2 +++ b/imiptools/data.py Sun Feb 01 21:02:53 2015 +0100
2.3 @@ -223,4 +223,28 @@
2.4 def uri_items(items):
2.5 return [(get_uri(value), attr) for value, attr in items]
2.6
2.7 +# Operations on structure data.
2.8 +
2.9 +def is_new_object(old_sequence, new_sequence, old_dtstamp, new_dtstamp, partstat_set):
2.10 +
2.11 + """
2.12 + Return for the given 'old_sequence' and 'new_sequence', 'old_dtstamp' and
2.13 + 'new_dtstamp', and the 'partstat_set' indication, whether the object
2.14 + providing the new information is really newer than the object providing the
2.15 + old information.
2.16 + """
2.17 +
2.18 + have_sequence = old_sequence is not None and new_sequence is not None
2.19 + is_same_sequence = have_sequence and int(new_sequence) == int(old_sequence)
2.20 +
2.21 + have_dtstamp = old_dtstamp and new_dtstamp
2.22 + is_old_dtstamp = have_dtstamp and new_dtstamp < old_dtstamp or old_dtstamp and not new_dtstamp
2.23 +
2.24 + is_old_sequence = have_sequence and (
2.25 + int(new_sequence) < int(old_sequence) or
2.26 + is_same_sequence and is_old_dtstamp
2.27 + )
2.28 +
2.29 + return is_same_sequence and partstat_set or not is_old_sequence
2.30 +
2.31 # vim: tabstop=4 expandtab shiftwidth=4