Changeset 80
- Timestamp:
- 06/27/07 18:17:23 (2 years ago)
- Files:
-
- trunk/cube/cube.py (modified) (1 diff)
- trunk/cube/network.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cube/cube.py
r69 r80 108 108 109 109 110 def _test(): 111 import doctest 112 print doctest.testmod(verbose=True) 113 110 114 if __name__ == "__main__": 111 115 import time trunk/cube/network.py
r70 r80 134 134 135 135 def bytes_to_int(s): 136 """Reads four bytes into an unsigned integer.""" 136 """Reads four bytes into an unsigned integer. 137 138 >>> bytes_to_int('\xc0\xa8\x03\x15') 139 3232236309L 140 """ 137 141 ip = socket.ntohl(struct.unpack('I',s)[0]) 138 142 ip = signed32bit_to_unsigned(ip) … … 140 144 141 145 def dottedquad_to_int(s): 142 """Converts an IPv4 dotted quad into an integer. Not yet implemented.""" 146 """Converts an IPv4 dotted quad into a long integer. Not yet implemented. 147 148 >>> dottedquad_to_int("192.168.3.21") 149 3232236309L 150 """ 151 143 152 import re 144 153 r = re.compile('') … … 261 270 def iprange(cidr): 262 271 """Calculate the low and high IP addresses of a given CIDR range and return 263 them as 32 bit unsigned integers.""" 272 them as 32 bit unsigned integers. 273 274 >>> iprange("192.168.3.21/24") 275 (3232236288L, 3232236543L) 276 277 >>> iprange("192.168.3.21/0") 278 (0L, 4294967295L) 279 280 >>> iprange("192.168.3.21/32") 281 (3232236309L, 3232236309L) 282 """ 264 283 265 284 t = re.split("\/", cidr) … … 443 462 444 463 return ret 464 465 466 467 def _test(): 468 import doctest 469 print doctest.testmod(verbose=True) 470 471 if __name__ == '__main__': 472 _test()
