Changeset 2160 for trunk

Show
Ignore:
Timestamp:
04/13/08 18:10:28 (7 months ago)
Author:
wichert
Message:

Make sure all encoding utility methods raise a TypeError? if a value of the wrong type is passed in.

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/CHANGES.txt

    r1129 r2160  
    11Pyrad 1.2 (unreleased) 
    22====================== 
     3 
     4* Make sure all encoding utility methods raise a TypeError if a value of 
     5  the wrong type is passed in. 
    36 
    47 
  • trunk/LICENSE.txt

    r1024 r2160  
    1 Copyright 2002-2007 Wichert Akkerman. All rights reserved. 
    2 Copyright 2007 Simplon. All rights reserved. 
     1Copyright 2002-2008 Wichert Akkerman. All rights reserved. 
     2Copyright 2007-2008 Simplon. All rights reserved. 
    33 
    44All rights reserved. 
  • trunk/README.txt

    r1085 r2160  
    4444=============================== 
    4545 
    46 pyrad was written by Wichert Akkerman <wichert@wiggy.net> 
     46pyrad was written by Wichert Akkerman <wichert@wiggy.net> and is licensed 
     47under a BSD license.  
    4748 
    48 Copyright and license information can be found in LICENSE.txt 
     49Copyright and license information can be found in the LICENSE.txt file. 
    4950 
    5051The current version and documentation can be found at its homepage: 
     
    5455https://code.wiggy.net/tracker/pyrad/ 
    5556 
    56  
  • trunk/pyrad/tests/testTools.py

    r1128 r2160  
    88 
    99 
     10    def testInvalidStringEncodingRaisesTypeError(self): 
     11        self.assertRaises(TypeError, tools.EncodeString, 1) 
     12 
     13 
    1014    def testAddressEncoding(self): 
    1115        self.assertRaises(ValueError, tools.EncodeAddress, "123") 
    1216        self.assertEqual(tools.EncodeAddress("192.168.0.255"), 
    1317                            "\xc0\xa8\x00\xff") 
     18 
     19 
     20    def testInvalidAddressEncodingRaisesTypeError(self): 
     21        self.assertRaises(TypeError, tools.EncodeAddress, 1) 
    1422 
    1523 
     
    1927 
    2028 
     29    def testInvalidIntegerEncodingRaisesTypeError(self): 
     30        self.assertRaises(TypeError, tools.EncodeInteger, "1") 
     31 
     32 
    2133    def testDateEncoding(self): 
    2234        self.assertEqual(tools.EncodeDate(0x01020304), 
    2335                "\x01\x02\x03\x04") 
     36 
     37 
     38    def testInvalidDataEncodingRaisesTypeError(self): 
     39        self.assertRaises(TypeError, tools.EncodeDate, "1") 
    2440 
    2541 
  • trunk/pyrad/tools.py

    r1128 r2160  
    1414 
    1515def EncodeAddress(addr): 
     16        if not isinstance(addr, basestring): 
     17                raise TypeError, "Address has to be a string" 
    1618        (a,b,c,d)=map(int, addr.split(".")) 
    1719        return struct.pack("BBBB", a, b, c, d) 
     
    1921 
    2022def EncodeInteger(num): 
     23        if not isinstance(num, int): 
     24                raise TypeError, "Can not encode non-integer as integer" 
    2125        return struct.pack("!I", num) 
    2226 
    2327 
    2428def EncodeDate(num): 
     29        if not isinstance(num, int): 
     30                raise TypeError, "Can not encode non-integer as date" 
    2531        return struct.pack("!I", num) 
    2632 
  • trunk/setup.py

    r1129 r2160  
    1212        license         = "BSD", 
    1313        description     = "RADIUS client tools", 
    14         long_description= open("README.txt").read()+open("CHANGES.txt").read(), 
     14        long_description= open("README.txt").read() + "\n" + 
     15                          open("CHANGES.txt").read(), 
    1516        classifiers     = [ 
    1617            "Intended Audience :: Developers",