Changeset 80

Show
Ignore:
Timestamp:
06/27/07 18:17:23 (2 years ago)
Author:
jkyllo
Message:

Added beginning of doctest framework and fixed a couple docstrings.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cube/cube.py

    r69 r80  
    108108 
    109109 
     110def _test(): 
     111    import doctest 
     112    print doctest.testmod(verbose=True) 
     113 
    110114if __name__ == "__main__": 
    111115    import time 
  • trunk/cube/network.py

    r70 r80  
    134134 
    135135def 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    """ 
    137141    ip = socket.ntohl(struct.unpack('I',s)[0]) 
    138142    ip = signed32bit_to_unsigned(ip) 
     
    140144 
    141145def 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 
    143152    import re 
    144153    r = re.compile('') 
     
    261270def iprange(cidr): 
    262271    """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    """ 
    264283 
    265284    t = re.split("\/", cidr) 
     
    443462 
    444463        return ret 
     464 
     465 
     466 
     467def _test(): 
     468    import doctest 
     469    print doctest.testmod(verbose=True) 
     470 
     471if __name__ == '__main__': 
     472    _test()