<s> from __future__ import unicode_literals <EOL> import pkg_resources <EOL> from six . moves . urllib import parse <EOL> from . . exceptions import TaxiException <EOL> class BackendRegistry ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _entry_points = { } <EOL> self . _backends_registry = { } <EOL> for backend in pkg_resources . iter_entry_points ( '<STR_LIT>' ) : <EOL> self . _entry_points [ backend . name ] = backend <EOL> def __getitem__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . _backends_registry [ key ] <EOL> def __setitem__ ( self , key , value ) : <EOL> self . _backends_registry [ key ] = value <EOL> def __iter__ ( self ) : <EOL> return iter ( self . _backends_registry ) <EOL> def __delitem__ ( self , key ) : <EOL> self . _backends_registry . __delitem__ ( key ) <EOL> def __contains__ ( self , key ) : <EOL> self . load_backends ( ) <EOL> return key in self . _backends_registry <EOL> def items ( self ) : <EOL> return self . _backends_registry . items ( ) <EOL> def populate ( self , backends ) : <EOL> """<STR_LIT>""" <EOL> for name , uri in backends . items ( ) : <EOL> self . _backends_registry [ name ] = self . load_backend ( uri ) <EOL> def load_backend ( self , backend_uri ) : <EOL> """<STR_LIT>""" <EOL> parsed = parse . urlparse ( backend_uri ) <EOL> options = dict ( parse . parse_qsl ( parsed . query ) ) <EOL> try : <EOL> backend = self . _entry_points [ parsed . scheme ] . load ( ) <EOL> except KeyError : <EOL> raise BackendNotFoundError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % parsed . scheme <EOL> ) <EOL> password = ( parse . unquote ( parsed . password ) <EOL> if parsed . password <EOL> else parsed . password ) <EOL> return backend ( <EOL> username = parsed . username , password = password , <EOL> hostname = parsed . hostname , port = parsed . port , <EOL> path = parsed . path , options = options <EOL> ) <EOL> class BackendNotFoundError ( TaxiException ) : <EOL> pass <EOL> backends_registry = BackendRegistry ( ) </s>
