<s> from suds . xsd . doctor import Import <EOL> from suds . xsd . sxbasic import Import as BasicImport <EOL> from suds import ServiceNotFound <EOL> from suds . transport . https import HttpAuthenticated <EOL> from suds . transport . https import WindowsHttpAuthenticated <EOL> from suds . transport . http import HttpAuthenticated as AlwaysSendTransport <EOL> from . utils import * <EOL> import robot <EOL> class _OptionsKeywords ( object ) : <EOL> def set_service ( self , service ) : <EOL> """<STR_LIT>""" <EOL> service = parse_index ( service ) <EOL> self . _client ( ) . set_options ( service = service ) <EOL> def set_port ( self , port ) : <EOL> """<STR_LIT>""" <EOL> port = parse_index ( port ) <EOL> self . _client ( ) . set_options ( port = port ) <EOL> def set_proxies ( self , * protocol_url_pairs ) : <EOL> """<STR_LIT>""" <EOL> if len ( protocol_url_pairs ) % <NUM_LIT:2> != <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> proxy = { } <EOL> for i in range ( <NUM_LIT:0> , len ( protocol_url_pairs ) , <NUM_LIT:2> ) : <EOL> proxy [ protocol_url_pairs [ i ] ] = protocol_url_pairs [ i + <NUM_LIT:1> ] <EOL> self . _client ( ) . set_options ( proxy = proxy ) <EOL> def set_headers ( self , * dict_or_key_value_pairs ) : <EOL> """<STR_LIT>""" <EOL> length = len ( dict_or_key_value_pairs ) <EOL> if length == <NUM_LIT:1> : <EOL> headers = dict_or_key_value_pairs [ <NUM_LIT:0> ] <EOL> elif length % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> headers = { } <EOL> for i in range ( <NUM_LIT:0> , len ( dict_or_key_value_pairs ) , <NUM_LIT:2> ) : <EOL> headers [ dict_or_key_value_pairs [ i ] ] = dict_or_key_value_pairs [ i + <NUM_LIT:1> ] <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _client ( ) . set_options ( headers = headers ) <EOL> def set_soap_headers ( self , * headers ) : <EOL> """<STR_LIT>""" <EOL> self . _client ( ) . set_options ( soapheaders = headers ) <EOL> def set_return_xml ( self , return_xml ) : <EOL> """<STR_LIT>""" <EOL> return_xml = to_bool ( return_xml ) <EOL> old_value = self . _get_external_option ( "<STR_LIT>" , False ) <EOL> self . _set_external_option ( "<STR_LIT>" , return_xml ) <EOL> return old_value <EOL> def set_http_authentication ( self , username , password , type = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> transport = self . _get_transport ( type , username = username , password = password ) <EOL> self . _client ( ) . set_options ( transport = transport ) <EOL> def set_location ( self , url , service = None , names = None ) : <EOL> """<STR_LIT>""" <EOL> wsdl = self . _client ( ) . wsdl <EOL> service_count = len ( wsdl . services ) <EOL> if ( service_count == <NUM_LIT:1> ) : <EOL> service = <NUM_LIT:0> <EOL> elif not service is None : <EOL> service = parse_index ( service ) <EOL> if isinstance ( names , basestring ) : <EOL> names = names . split ( "<STR_LIT:U+002C>" ) <EOL> if service is None : <EOL> for svc in wsdl . services : <EOL> svc . setlocation ( url , names ) <EOL> elif isinstance ( service , int ) : <EOL> wsdl . services [ service ] . setlocation ( url , names ) <EOL> else : <EOL> for svc in wsdl . services : <EOL> if svc . name == service : <EOL> svc . setlocation ( url , names ) <EOL> return <EOL> raise ServiceNotFound ( service ) <EOL> def add_doctor_import ( self , import_namespace , location = None , filters = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( filters , basestring ) : <EOL> filters = filters . split ( "<STR_LIT:U+002C>" ) <EOL> imp = Import ( import_namespace , location ) <EOL> if not filters is None : <EOL> for filter in filters : <EOL> imp . filter . add ( filter ) <EOL> self . _imports . append ( imp ) <EOL> def bind_schema_to_location ( self , namespace , location ) : <EOL> """<STR_LIT>""" <EOL> BasicImport . bind ( namespace , location ) <EOL> def set_soap_timeout ( self , timeout ) : <EOL> """<STR_LIT>""" <EOL> self . _set_soap_timeout ( timeout ) <EOL> timestr = format_robot_time ( timeout ) <EOL> self . _logger . info ( "<STR_LIT>" % timestr ) <EOL> def _set_boolean_option ( self , name , value ) : <EOL> value = to_bool ( value ) <EOL> self . _client ( ) . set_options ( ** { name : value } ) <EOL> def _set_soap_timeout ( self , timeout ) : <EOL> timeout_in_secs = robot . utils . timestr_to_secs ( timeout ) <EOL> self . _client ( ) . set_options ( timeout = timeout_in_secs ) <EOL> def _get_external_option ( self , name , default ) : <EOL> value = default <EOL> if self . _client ( ) in self . _external_options : <EOL> options = self . _external_options [ self . _client ( ) ] <EOL> value = options . get ( name , default ) <EOL> return value <EOL> def _set_external_option ( self , name , value ) : <EOL> if self . _client ( ) not in self . _external_options : <EOL> self . _external_options [ self . _client ( ) ] = { } <EOL> old_value = self . _external_options [ self . _client ( ) ] . get ( name , None ) <EOL> self . _external_options [ self . _client ( ) ] [ name ] = value <EOL> return old_value <EOL> def _get_transport ( self , auth_type , username , password ) : <EOL> classes = { <EOL> '<STR_LIT>' : HttpAuthenticated , <EOL> '<STR_LIT>' : AlwaysSendTransport , <EOL> '<STR_LIT>' : WindowsHttpAuthenticated <EOL> } <EOL> try : <EOL> _class = classes [ auth_type . upper ( ) . strip ( ) ] <EOL> except KeyError : <EOL> raise ValueError ( "<STR_LIT>" % auth_type ) <EOL> transport = _class ( username = username , password = password ) <EOL> return transport </s>
