<s> import socket <EOL> import unittest <EOL> from flashproxy . util import parse_addr_spec , canonical_ip , addr_family , format_addr <EOL> class ParseAddrSpecTest ( unittest . TestCase ) : <EOL> def test_ipv4 ( self ) : <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> def test_ipv6 ( self ) : <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> def test_defhost_defport_ipv4 ( self ) : <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT::>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> def test_defhost_defport_ipv6 ( self ) : <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT::>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT> ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> def test_empty_defaults ( self ) : <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" , defport = <NUM_LIT:0> ) , ( "<STR_LIT>" , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defhost = "<STR_LIT>" ) , ( "<STR_LIT>" , <NUM_LIT> ) ) <EOL> self . assertRaises ( ValueError , parse_addr_spec , "<STR_LIT>" ) <EOL> self . assertEqual ( parse_addr_spec ( "<STR_LIT>" , defport = <NUM_LIT:0> ) , ( "<STR_LIT>" , <NUM_LIT:0> ) ) <EOL> self . assertRaises ( ValueError , parse_addr_spec , "<STR_LIT>" ) <EOL> def test_canonical_ip_noresolve ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( ValueError , canonical_ip , * parse_addr_spec ( "<STR_LIT>" ) ) <EOL> class AddrFamilyTest ( unittest . TestCase ) : <EOL> def test_ipv4 ( self ) : <EOL> self . assertEqual ( addr_family ( "<STR_LIT>" ) , socket . AF_INET ) <EOL> def test_ipv6 ( self ) : <EOL> self . assertEqual ( addr_family ( "<STR_LIT>" ) , socket . AF_INET6 ) <EOL> def test_name ( self ) : <EOL> self . assertRaises ( socket . gaierror , addr_family , "<STR_LIT:localhost>" ) <EOL> class FormatAddrTest ( unittest . TestCase ) : <EOL> def test_none_none ( self ) : <EOL> self . assertRaises ( ValueError , format_addr , ( None , None ) ) <EOL> def test_none_port ( self ) : <EOL> self . assertEqual ( format_addr ( ( None , <NUM_LIT> ) ) , "<STR_LIT>" ) <EOL> def test_none_invalid ( self ) : <EOL> self . assertRaises ( ValueError , format_addr , ( None , "<STR_LIT:string>" ) ) <EOL> def test_empty_none ( self ) : <EOL> self . assertRaises ( ValueError , format_addr , ( "<STR_LIT>" , None ) ) <EOL> def test_empty_port ( self ) : <EOL> self . assertEqual ( format_addr ( ( "<STR_LIT>" , <NUM_LIT> ) ) , "<STR_LIT>" ) <EOL> def test_empty_invalid ( self ) : <EOL> self . assertRaises ( ValueError , format_addr , ( "<STR_LIT>" , "<STR_LIT:string>" ) ) <EOL> def test_ipv4_none ( self ) : <EOL> self . assertEqual ( format_addr ( ( "<STR_LIT>" , None ) ) , "<STR_LIT>" ) <EOL> def test_ipv4_port ( self ) : <EOL> self . assertEqual ( format_addr ( ( "<STR_LIT>" , <NUM_LIT> ) ) , "<STR_LIT>" ) <EOL> def test_ipv4_invalid ( self ) : <EOL> self . assertRaises ( ValueError , format_addr , ( "<STR_LIT>" , "<STR_LIT:string>" ) ) <EOL> def test_ipv6_none ( self ) : <EOL> self . assertEqual ( format_addr ( ( "<STR_LIT>" , None ) ) , "<STR_LIT>" ) <EOL> def test_ipv6_port ( self ) : <EOL> self . assertEqual ( format_addr ( ( "<STR_LIT>" , <NUM_LIT> ) ) , "<STR_LIT>" ) <EOL> def test_ipv6_invalid ( self ) : <EOL> self . assertRaises ( ValueError , format_addr , ( "<STR_LIT>" , "<STR_LIT:string>" ) ) <EOL> def test_name_none ( self ) : <EOL> self . assertEqual ( format_addr ( ( "<STR_LIT:localhost>" , None ) ) , "<STR_LIT:localhost>" ) <EOL> def test_name_port ( self ) : <EOL> self . assertEqual ( format_addr ( ( "<STR_LIT:localhost>" , <NUM_LIT> ) ) , "<STR_LIT>" ) <EOL> def test_name_invalid ( self ) : <EOL> self . assertRaises ( ValueError , format_addr , ( "<STR_LIT:localhost>" , "<STR_LIT:string>" ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
