<s> """<STR_LIT>""" <EOL> import unittest <EOL> import zlib <EOL> import set_sys_path <EOL> from mod_pywebsocket import common <EOL> from mod_pywebsocket import extensions <EOL> class ExtensionsTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_parse_window_bits ( self ) : <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , None ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertTrue ( extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertTrue ( extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT:0>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> self . assertRaises ( <EOL> ValueError , extensions . _parse_window_bits , '<STR_LIT>' ) <EOL> class DeflateFrameExtensionProcessorParsingTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_registry ( self ) : <EOL> processor = extensions . get_extension_processor ( <EOL> common . ExtensionParameter ( '<STR_LIT>' ) ) <EOL> self . assertIsInstance ( processor , <EOL> extensions . DeflateFrameExtensionProcessor ) <EOL> processor = extensions . get_extension_processor ( <EOL> common . ExtensionParameter ( '<STR_LIT>' ) ) <EOL> self . assertIsInstance ( processor , <EOL> extensions . DeflateFrameExtensionProcessor ) <EOL> def test_minimal_offer ( self ) : <EOL> processor = extensions . DeflateFrameExtensionProcessor ( <EOL> common . ExtensionParameter ( '<STR_LIT>' ) ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . name ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( response . get_parameters ( ) ) ) <EOL> self . assertEqual ( zlib . MAX_WBITS , <EOL> processor . _rfc1979_deflater . _window_bits ) <EOL> self . assertFalse ( processor . _rfc1979_deflater . _no_context_takeover ) <EOL> def test_offer_with_max_window_bits ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> processor = extensions . DeflateFrameExtensionProcessor ( parameter ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . name ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( response . get_parameters ( ) ) ) <EOL> self . assertEqual ( <NUM_LIT:10> , processor . _rfc1979_deflater . _window_bits ) <EOL> def test_offer_with_out_of_range_max_window_bits ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , '<STR_LIT:0>' ) <EOL> processor = extensions . DeflateFrameExtensionProcessor ( parameter ) <EOL> self . assertIsNone ( processor . get_extension_response ( ) ) <EOL> def test_offer_with_max_window_bits_without_value ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , None ) <EOL> processor = extensions . DeflateFrameExtensionProcessor ( parameter ) <EOL> self . assertIsNone ( processor . get_extension_response ( ) ) <EOL> def test_offer_with_no_context_takeover ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , None ) <EOL> processor = extensions . DeflateFrameExtensionProcessor ( parameter ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . name ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( response . get_parameters ( ) ) ) <EOL> self . assertTrue ( processor . _rfc1979_deflater . _no_context_takeover ) <EOL> def test_offer_with_no_context_takeover_with_value ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> processor = extensions . DeflateFrameExtensionProcessor ( parameter ) <EOL> self . assertIsNone ( processor . get_extension_response ( ) ) <EOL> def test_offer_with_unknown_parameter ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> processor = extensions . DeflateFrameExtensionProcessor ( parameter ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . name ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( response . get_parameters ( ) ) ) <EOL> class PerMessageDeflateExtensionProcessorParsingTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_registry ( self ) : <EOL> processor = extensions . get_extension_processor ( <EOL> common . ExtensionParameter ( '<STR_LIT>' ) ) <EOL> self . assertIsInstance ( processor , <EOL> extensions . PerMessageDeflateExtensionProcessor ) <EOL> def test_minimal_offer ( self ) : <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( <EOL> common . ExtensionParameter ( '<STR_LIT>' ) ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . name ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( response . get_parameters ( ) ) ) <EOL> self . assertEqual ( zlib . MAX_WBITS , <EOL> processor . _rfc1979_deflater . _window_bits ) <EOL> self . assertFalse ( processor . _rfc1979_deflater . _no_context_takeover ) <EOL> def test_offer_with_max_window_bits ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( parameter ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . name ( ) ) <EOL> self . assertEqual ( [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , <EOL> response . get_parameters ( ) ) <EOL> self . assertEqual ( <NUM_LIT:10> , processor . _rfc1979_deflater . _window_bits ) <EOL> def test_offer_with_out_of_range_max_window_bits ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , '<STR_LIT:0>' ) <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( parameter ) <EOL> self . assertIsNone ( processor . get_extension_response ( ) ) <EOL> def test_offer_with_max_window_bits_without_value ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , None ) <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( parameter ) <EOL> self . assertIsNone ( processor . get_extension_response ( ) ) <EOL> def test_offer_with_no_context_takeover ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , None ) <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( parameter ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . name ( ) ) <EOL> self . assertEqual ( [ ( '<STR_LIT>' , None ) ] , <EOL> response . get_parameters ( ) ) <EOL> self . assertTrue ( processor . _rfc1979_deflater . _no_context_takeover ) <EOL> def test_offer_with_no_context_takeover_with_value ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( parameter ) <EOL> self . assertIsNone ( processor . get_extension_response ( ) ) <EOL> def test_offer_with_unknown_parameter ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( parameter ) <EOL> self . assertIsNone ( processor . get_extension_response ( ) ) <EOL> class PerMessageDeflateExtensionProcessorBuildingTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_response_with_max_window_bits ( self ) : <EOL> parameter = common . ExtensionParameter ( '<STR_LIT>' ) <EOL> parameter . add_parameter ( '<STR_LIT>' , None ) <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( parameter ) <EOL> processor . set_client_max_window_bits ( <NUM_LIT:10> ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . name ( ) ) <EOL> self . assertEqual ( [ ( '<STR_LIT>' , '<STR_LIT>' ) ] , <EOL> response . get_parameters ( ) ) <EOL> def test_response_with_max_window_bits_without_client_permission ( self ) : <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( <EOL> common . ExtensionParameter ( '<STR_LIT>' ) ) <EOL> processor . set_client_max_window_bits ( <NUM_LIT:10> ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertIsNone ( response ) <EOL> def test_response_with_true_for_no_context_takeover ( self ) : <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( <EOL> common . ExtensionParameter ( '<STR_LIT>' ) ) <EOL> processor . set_client_no_context_takeover ( True ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . name ( ) ) <EOL> self . assertEqual ( [ ( '<STR_LIT>' , None ) ] , <EOL> response . get_parameters ( ) ) <EOL> def test_response_with_false_for_no_context_takeover ( self ) : <EOL> processor = extensions . PerMessageDeflateExtensionProcessor ( <EOL> common . ExtensionParameter ( '<STR_LIT>' ) ) <EOL> processor . set_client_no_context_takeover ( False ) <EOL> response = processor . get_extension_response ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . name ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( response . get_parameters ( ) ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
