#NEWLINE# def formal( self , options_first ) : #NEWLINE# #INDENT# names = self . known #NEWLINE# result = [ ] #NEWLINE# skip = 0 #NEWLINE# for ( index , each ) in enumerate ( self ) : #NEWLINE# #INDENT# if skip : #NEWLINE# #INDENT# skip -= 1 #NEWLINE# continue #NEWLINE# #UNINDENT# if ( options_first and ( ( each in ( '-' , '--' ) ) or ( not each . startswith ( '-' ) ) ) ) : #NEWLINE# #INDENT# result . extend ( ( each , '--' ) ) #NEWLINE# result . extend ( self [ ( index + 1 ) : ] ) #NEWLINE# break #NEWLINE# #UNINDENT# if ( ( each == '--' ) and self . auto_dashes ) : #NEWLINE# #INDENT# result . extend ( self [ index : ] ) #NEWLINE# break #NEWLINE# #UNINDENT# if ( each == '-' ) : #NEWLINE# #INDENT# result . append ( each ) #NEWLINE# continue #NEWLINE# #UNINDENT# expect_args = 0 #NEWLINE# if ( each . startswith ( '-' ) and ( not each . startswith ( '--' ) ) ) : #NEWLINE# #INDENT# if self . stdopt : #NEWLINE# #INDENT# this_opt = each [ : 2 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# this_opt = each #NEWLINE# #UNINDENT# if ( this_opt not in names ) : #NEWLINE# #INDENT# self . error = UnknownOptionExit ( ( 'Unknown option: %s.' % this_opt ) , option = this_opt , inside = each ) #NEWLINE# result . extend ( self [ index : ] ) #NEWLINE# break #NEWLINE# #UNINDENT# result . append ( each ) #NEWLINE# expect_args = names [ this_opt ] #NEWLINE# if ( this_opt != each ) : #NEWLINE# #INDENT# expect_args = 0 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not each . startswith ( '--' ) ) : #NEWLINE# #INDENT# result . append ( each ) #NEWLINE# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( option , equal , value ) = each . partition ( '=' ) #NEWLINE# if ( option in names ) : #NEWLINE# #INDENT# result . append ( each ) #NEWLINE# if equal : #NEWLINE# #INDENT# expect_args = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# expect_args = names [ option ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# possible = list ( filter ( ( lambda x : x . startswith ( option ) ) , names ) ) #NEWLINE# if ( not possible ) : #NEWLINE# #INDENT# self . error = UnknownOptionExit ( ( 'Unknown option: %s.' % option ) , option = option , inside = each ) #NEWLINE# result . extend ( self [ index : ] ) #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( possible ) == 1 ) : #NEWLINE# #INDENT# replace = '' . join ( ( possible [ 0 ] , equal , value ) ) #NEWLINE# logger . debug ( 'expand %s -> %s' , each , replace ) #NEWLINE# result . append ( replace ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . error = AmbiguousPrefixExit ( ( '%s is not a unique prefix: %s?' % ( option , ', ' . join ( possible ) ) ) , prefix = option , ambiguous = possible ) #NEWLINE# result . extend ( self [ index : ] ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if expect_args : #NEWLINE# #INDENT# total_rest = self [ ( equal + 1 ) : ] #NEWLINE# if ( len ( total_rest ) < expect_args ) : #NEWLINE# #INDENT# to_append = total_rest #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# to_append = total_rest [ : expect_args ] #NEWLINE# #UNINDENT# skip = len ( to_append ) #NEWLINE# result . extend ( to_append ) #NEWLINE# #UNINDENT# #UNINDENT# logger . debug ( '%s -> %s' , self , result ) #NEWLINE# self [ : ] = result #NEWLINE# return None