<s> from datetime import timedelta <EOL> from flask import make_response , request , current_app <EOL> from functools import update_wrapper <EOL> def crossdomain ( origin = None , methods = None , headers = None , expose_headers = None , <EOL> max_age = <NUM_LIT> , attach_to_all = True , <EOL> automatic_options = True , credentials = False ) : <EOL> """<STR_LIT>""" <EOL> if methods is not None : <EOL> methods = '<STR_LIT:U+002CU+0020>' . join ( sorted ( x . upper ( ) for x in methods ) ) <EOL> if headers is not None and not isinstance ( headers , str ) : <EOL> headers = '<STR_LIT:U+002CU+0020>' . join ( x . upper ( ) for x in headers ) <EOL> if expose_headers is not None and not isinstance ( expose_headers , str ) : <EOL> expose_headers = '<STR_LIT:U+002CU+0020>' . join ( x . upper ( ) for x in expose_headers ) <EOL> if not isinstance ( origin , str ) : <EOL> origin = '<STR_LIT:U+002CU+0020>' . join ( origin ) <EOL> if isinstance ( max_age , timedelta ) : <EOL> max_age = max_age . total_seconds ( ) <EOL> def get_methods ( ) : <EOL> if methods is not None : <EOL> return methods <EOL> options_resp = current_app . make_default_options_response ( ) <EOL> return options_resp . headers [ '<STR_LIT>' ] <EOL> def decorator ( f ) : <EOL> def wrapped_function ( * args , ** kwargs ) : <EOL> if automatic_options and request . method == '<STR_LIT>' : <EOL> resp = current_app . make_default_options_response ( ) <EOL> else : <EOL> resp = make_response ( f ( * args , ** kwargs ) ) <EOL> if not attach_to_all and request . method != '<STR_LIT>' : <EOL> return resp <EOL> h = resp . headers <EOL> h [ '<STR_LIT>' ] = origin <EOL> h [ '<STR_LIT>' ] = get_methods ( ) <EOL> h [ '<STR_LIT>' ] = str ( max_age ) <EOL> if credentials : <EOL> h [ '<STR_LIT>' ] = '<STR_LIT:true>' <EOL> if headers is not None : <EOL> h [ '<STR_LIT>' ] = headers <EOL> if expose_headers is not None : <EOL> h [ '<STR_LIT>' ] = expose_headers <EOL> return resp <EOL> f . provide_automatic_options = False <EOL> return update_wrapper ( wrapped_function , f ) <EOL> return decorator </s>
