Package ldaptor :: Module U32
[hide private]
[frames] | no frames]

Source Code for Module ldaptor.U32

  1  """Utility library for handling 32-bit unsigner integers.""" 
  2   
  3  # http://www.geocities.com/rozmanov/python/ 
  4   
  5  """ 
  6  From: "Dmitry Rozmanov" <dima@xenon.spb.ru> 
  7  To: "Tommi Virtanen" <tv@debian.org> 
  8  Subject: Re: About your md4.py 
  9   
 10  Hi. 
 11   
 12  Year, I am thinking of this, but could not find time for this. Thanks for 
 13  the link. 
 14   
 15  But why? 
 16   
 17  Consider it as a GPL for now if it is important. 
 18   
 19  Regards. 
 20   
 21      ---Dmitry. 
 22   
 23  ----- Original Message ----- 
 24  From: "Tommi Virtanen" <tv@debian.org> 
 25  To: "Dmitry Rozmanov" <dima@xenon.spb.ru> 
 26  Sent: Tuesday, August 27, 2002 9:17 PM 
 27  Subject: About your md4.py 
 28   
 29   
 30  > Hi. Could you consider adding a license 
 31  > in your U32.py and md4.py files? Here's 
 32  > a quick reference: 
 33  > 
 34  > http://zooko.com/license_quick_ref.html 
 35  > 
 36  > -- 
 37  > :(){ :|:&};: 
 38  """ 
 39   
 40  """ 
 41  From: "Dmitry Rozmanov" <dima@xenon.spb.ru> 
 42  To: "Tommi Virtanen" <tv@debian.org> 
 43  Subject: Re: About your md4.py 
 44   
 45  Ok. Let it be LGPL. Use libs, soon I will modify them and post to the site. 
 46   
 47  Regards. 
 48   
 49      ---Dmitry. 
 50   
 51  ----- Original Message ----- 
 52  From: "Tommi Virtanen" <tv@debian.org> 
 53  To: "Dmitry Rozmanov" <dima@xenon.spb.ru> 
 54  Sent: Wednesday, August 28, 2002 9:21 AM 
 55  Subject: Re: About your md4.py 
 56   
 57   
 58  > On Wed, Aug 28, 2002 at 02:56:25AM +0400, Dmitry Rozmanov wrote: 
 59  > > Year, I am thinking of this, but could not find time for 
 60  > > this. Thanks for the link. 
 61  > > 
 62  > > But why? 
 63  > > 
 64  > > Consider it as a GPL for now if it is important. 
 65  > 
 66  > Please include that information in the files themselves; 
 67  > it would really help. Otherwise, all I have is this 
 68  > email to point to. 
 69  > 
 70  > Oh, and please reconsider the actual license. For example, 
 71  > I have an LGPL'ed library I need md4 in. If you choose GPL, 
 72  > my library couldn't use your md4.py. 
 73  > 
 74  > -- 
 75  > :(){ :|:&};: 
 76  """ 
 77   
 78  C = 0x1000000000L 
 79   
80 -def norm(n):
81 return n & 0xFFFFFFFFL
82 83
84 -class U32:
85 v = 0L 86
87 - def __init__(self, value = 0):
88 self.v = C + norm(abs(long(value)))
89
90 - def set(self, value = 0):
91 self.v = C + norm(abs(long(value)))
92
93 - def __repr__(self):
94 return hex(norm(self.v))
95
96 - def __long__(self): return long(norm(self.v))
97 - def __int__(self): return int(norm(self.v))
98 - def __chr__(self): return chr(norm(self.v))
99
100 - def __add__(self, b):
101 r = U32() 102 r.v = C + norm(self.v + b.v) 103 return r
104
105 - def __sub__(self, b):
106 r = U32() 107 if self.v < b.v: 108 r.v = C + norm(0x100000000L - (b.v - self.v)) 109 else: r.v = C + norm(self.v - b.v) 110 return r
111
112 - def __mul__(self, b):
113 r = U32() 114 r.v = C + norm(self.v * b.v) 115 return r
116
117 - def __div__(self, b):
118 r = U32() 119 r.v = C + (norm(self.v) / norm(b.v)) 120 return r
121
122 - def __mod__(self, b):
123 r = U32() 124 r.v = C + (norm(self.v) % norm(b.v)) 125 return r
126
127 - def __neg__(self): return U32(self.v)
128 - def __pos__(self): return U32(self.v)
129 - def __abs__(self): return U32(self.v)
130
131 - def __invert__(self):
132 r = U32() 133 r.v = C + norm(~self.v) 134 return r
135
136 - def __lshift__(self, b):
137 r = U32() 138 r.v = C + norm(self.v << b) 139 return r
140
141 - def __rshift__(self, b):
142 r = U32() 143 r.v = C + (norm(self.v) >> b) 144 return r
145
146 - def __and__(self, b):
147 r = U32() 148 r.v = C + norm(self.v & b.v) 149 return r
150
151 - def __or__(self, b):
152 r = U32() 153 r.v = C + norm(self.v | b.v) 154 return r
155
156 - def __xor__(self, b):
157 r = U32() 158 r.v = C + norm(self.v ^ b.v) 159 return r
160
161 - def __not__(self):
162 return U32(not norm(self.v))
163
164 - def truth(self):
165 return norm(self.v)
166
167 - def __cmp__(self, b):
168 if norm(self.v) > norm(b.v): return 1 169 elif norm(self.v) < norm(b.v): return -1 170 else: return 0
171
172 - def __nonzero__(self):
173 return norm(self.v)
174