Package conduit :: Package datatypes
[hide private]

Source Code for Package conduit.datatypes

 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  #Constants used for comparison 
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   
19 -class Rid(object):
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
34 - def __eq__(self, other):
35 if other == None: 36 return False 37 #log.debug("EQ: UID:%s mtime:%s hash:%s" % (self.uid != other.uid, self.mtime != other.mtime, self.hash != other.hash)) 38 #log.debug("EQ Types: UID:%sv%s mtime:%sv%s hash:%sv%s" % (type(self.uid),type(other.uid),type(self.mtime),type(other.mtime),type(self.hash),type(other.hash))) 39 return self.uid == other.uid and self.mtime == other.mtime and self.hash == other.hash
40
41 - def __ne__(self, other):
42 if other == None: 43 return True 44 #log.debug("NE: UID:%s mtime:%s hash:%s" % (self.uid != other.uid, self.mtime != other.mtime, self.hash != other.hash)) 45 #log.debug("NE Types: UID:%sv%s mtime:%sv%s hash:%sv%s" % (type(self.uid),type(other.uid),type(self.mtime),type(other.mtime),type(self.hash),type(other.hash))) 46 return self.uid != other.uid or self.mtime != other.mtime or self.hash != other.hash
47
48 - def __hash__(self):
49 return hash( (self.uid, self.mtime, self.hash) )
50
51 - def __str__(self):
52 return "UID:%s mtime:%s hash:%s" % (self.uid, self.mtime, self.hash)
53
54 - def get_UID(self):
55 return self.uid
56
57 - def get_mtime(self):
58 return self.mtime
59
60 - def get_hash(self):
61 return self.hash
62
63 - def __getstate__(self):
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
73 - def __setstate__(self, data):
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
82 -def compare_mtimes_and_hashes(data1, data2):
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