#NEWLINE# def crossdomain( origin = None , methods = None , headers = None , max_age = 21600 , attach_to_all = True , automatic_options = True ) : #NEWLINE# #INDENT# if ( methods is not None ) : #NEWLINE# #INDENT# methods = ', ' . join ( sorted ( ( x . upper ( ) for x in methods ) ) ) #NEWLINE# #UNINDENT# if ( ( headers is not None ) and ( not isinstance ( headers , basestring ) ) ) : #NEWLINE# #INDENT# headers = ', ' . join ( ( x . upper ( ) for x in headers ) ) #NEWLINE# #UNINDENT# if ( not isinstance ( origin , basestring ) ) : #NEWLINE# #INDENT# origin = ', ' . join ( origin ) #NEWLINE# #UNINDENT# if isinstance ( max_age , timedelta ) : #NEWLINE# #INDENT# max_age = max_age . total_seconds ( ) #NEWLINE# #UNINDENT# def get_methods( ) : #NEWLINE# #INDENT# if ( methods is not None ) : #NEWLINE# #INDENT# return methods #NEWLINE# #UNINDENT# options_resp = current_app . make_default_options_response ( ) #NEWLINE# return options_resp . headers [ 'allow' ] #NEWLINE# #UNINDENT# def decorator( f ) : #NEWLINE# #INDENT# def wrapped_function( * args , **kwargs ) : #NEWLINE# #INDENT# if ( automatic_options and ( request . method == 'OPTIONS' ) ) : #NEWLINE# #INDENT# resp = current_app . make_default_options_response ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# resp = make_response ( f ( * args , ** kwargs ) ) #NEWLINE# #UNINDENT# if ( ( not attach_to_all ) and ( request . method != 'OPTIONS' ) ) : #NEWLINE# #INDENT# return resp #NEWLINE# #UNINDENT# h = resp . headers #NEWLINE# h [ 'Access-Control-Allow-Origin' ] = origin #NEWLINE# h [ 'Access-Control-Allow-Methods' ] = get_methods ( ) #NEWLINE# h [ 'Access-Control-Max-Age' ] = str ( max_age ) #NEWLINE# if ( headers is not None ) : #NEWLINE# #INDENT# h [ 'Access-Control-Allow-Headers' ] = headers #NEWLINE# #UNINDENT# return resp #NEWLINE# #UNINDENT# f . provide_automatic_options = False #NEWLINE# return update_wrapper ( wrapped_function , f ) #NEWLINE# #UNINDENT# return decorator