#NEWLINE# def gnu_getopt( args , shortopts , longopts = [ ] ) : #NEWLINE# #INDENT# "getopt(args, options[, long_options]) -> opts, args\n\n    This function works like getopt(), except that GNU style scanning\n    mode is used by default. This means that option and non-option\n    arguments may be intermixed. The getopt() function stops\n    processing options as soon as a non-option argument is\n    encountered.\n\n    If the first character of the option string is `+', or if the\n    environment variable POSIXLY_CORRECT is set, then option\n    processing stops as soon as a non-option argument is encountered.\n    " #NEWLINE# opts = [ ] #NEWLINE# prog_args = [ ] #NEWLINE# if isinstance ( longopts , '' . __class__ ) : #NEWLINE# #INDENT# longopts = [ longopts ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# longopts = list ( longopts ) #NEWLINE# #UNINDENT# if shortopts . startswith ( '+' ) : #NEWLINE# #INDENT# shortopts = shortopts [ 1 : ] #NEWLINE# all_options_first = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if os . environ . get ( 'POSIXLY_CORRECT' ) : #NEWLINE# #INDENT# all_options_first = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# all_options_first = False #NEWLINE# #UNINDENT# #UNINDENT# while args : #NEWLINE# #INDENT# if ( args [ 0 ] == '--' ) : #NEWLINE# #INDENT# prog_args += opts [ 1 : ] #NEWLINE# break #NEWLINE# #UNINDENT# if ( args [ 0 ] [ : 2 ] == '--' ) : #NEWLINE# #INDENT# ( opts , args ) = do_longs ( opts , args [ 0 ] [ 2 : ] , longopts , args [ 1 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( args [ 0 ] [ : 1 ] == '-' ) : #NEWLINE# #INDENT# ( opts , args ) = do_shorts ( opts , args [ 0 ] [ 1 : ] , shortopts , args [ 1 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if all_options_first : #NEWLINE# #INDENT# prog_args += args #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# prog_args . append ( args [ 0 ] ) #NEWLINE# args = args [ 1 : ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( opts , prog_args )