1 """
2 Exposes the DataTypes for public use
3
4 It is expected that DataProviders (written by the user, or included within
5 Conduit) may require the use of DataTypes other than their own in their
6 implementation. For example all email programs should share the same common
7 mail datatype. For this reason DataTypes, not DataProviders are exported
8 """
9
10 COMPARISON_EQUAL = 0
11 COMPARISON_NEWER = 1
12 COMPARISON_OLDER = 2
13 COMPARISON_UNKNOWN = 3
14
15 import datetime
16 import logging
17 log = logging.getLogger("datatypes.Rid")
18
20
21 - def __init__(self, uid=None, mtime=None, hash=""):
22 """
23 @param uid: str or None
24 @param mtime: datetime or None
25 @param hash: str
26 """
27 self.uid = uid
28 self.mtime = mtime
29 self.hash = str(hash)
30
31 assert (type(uid) == str or type(uid) == unicode or uid == None), "UID must be unicode,string or None not %s" % type(uid)
32 assert (type(mtime) == datetime.datetime or mtime == None), "mtime must be datatime or None not %s" % type(datetime)
33
35 if other == None:
36 return False
37
38
39 return self.uid == other.uid and self.mtime == other.mtime and self.hash == other.hash
40
42 if other == None:
43 return True
44
45
46 return self.uid != other.uid or self.mtime != other.mtime or self.hash != other.hash
47
49 return hash( (self.uid, self.mtime, self.hash) )
50
52 return "UID:%s mtime:%s hash:%s" % (self.uid, self.mtime, self.hash)
53
56
59
62
64 """
65 Store the Rid state in a dict for pickling
66 """
67 data = {}
68 data['uid'] = self.uid
69 data['mtime'] = self.mtime
70 data['hash'] = self.hash
71 return data
72
74 """
75 Restore Rid state from dict (after unpickling)
76 """
77 self.uid = data['uid']
78 self.mtime = data['mtime']
79 self.hash = data['hash']
80
81
83 """
84 Compares data based upon its mtime and hashes only
85 """
86 mtime1 = data1.get_mtime()
87 mtime2 = data2.get_mtime()
88 hash1 = data1.get_hash()
89 hash2 = data2.get_hash()
90