#NEWLINE# def find_namespace( self , namespace ) : #NEWLINE# #INDENT# all_namespaces = self . get_namespaces ( ) #NEWLINE# expr = re . sub ( '([^:]+|)' , ( lambda m : ( re . escape ( m . group ( 1 ) ) + '[^:]*' ) ) , namespace ) #NEWLINE# namespaces = sorted ( list ( filter ( ( lambda x : re . findall ( ( '^%s' % expr ) , x ) ) , all_namespaces ) ) ) #NEWLINE# if ( not namespaces ) : #NEWLINE# #INDENT# message = ( 'There are no commands defined in the "%s" namespace.' % namespace ) #NEWLINE# alternatives = self . find_alternatives ( namespace , all_namespaces ) #NEWLINE# if alternatives : #NEWLINE# #INDENT# if ( len ( alternatives ) == 1 ) : #NEWLINE# #INDENT# message += '\n\nDid you mean this?\n    ' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# message += '\n\nDid you mean one of these?\n    ' #NEWLINE# #UNINDENT# message += '\n    ' . join ( alternatives ) #NEWLINE# #UNINDENT# raise Exception ( message ) #NEWLINE# #UNINDENT# exact = ( namespace in namespaces ) #NEWLINE# if ( ( len ( namespaces ) > 1 ) and ( not exact ) ) : #NEWLINE# #INDENT# raise Exception ( ( 'The namespace "%s" is ambiguous (%s).' % ( namespace , self . get_abbreviation_suggestions ( namespaces ) ) ) ) #NEWLINE# #UNINDENT# return ( namespace if exact else namespaces [ 0 ] )