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):
if methods is not None:<EOL><INDENT>methods = '<STR_LIT:U+002CU+0020>'.join(sorted(x.upper() for x in methods))<EOL><DEDENT>if headers is not None and not isinstance(headers, str):<EOL><INDENT>headers = '<STR_LIT:U+002CU+0020>'.join(x.upper() for x in headers)<EOL><DEDENT>if expose_headers is not None and not isinstance(expose_headers, str):<EOL><INDENT>expose_headers = '<STR_LIT:U+002CU+0020>'.join(x.upper() for x in expose_headers)<EOL><DEDENT>if not isinstance(origin, str):<EOL><INDENT>origin = '<STR_LIT:U+002CU+0020>'.join(origin)<EOL><DEDENT>if isinstance(max_age, timedelta):<EOL><INDENT>max_age = max_age.total_seconds()<EOL><DEDENT>def get_methods():<EOL><INDENT>if methods is not None:<EOL><INDENT>return methods<EOL><DEDENT>options_resp = current_app.make_default_options_response()<EOL>return options_resp.headers['<STR_LIT>']<EOL><DEDENT>def decorator(f):<EOL><INDENT>def wrapped_function(*args, **kwargs):<EOL><INDENT>if automatic_options and request.method == '<STR_LIT>':<EOL><INDENT>resp = current_app.make_default_options_response()<EOL><DEDENT>else:<EOL><INDENT>resp = make_response(f(*args, **kwargs))<EOL><DEDENT>if not attach_to_all and request.method != '<STR_LIT>':<EOL><INDENT>return resp<EOL><DEDENT>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><INDENT>h['<STR_LIT>'] = '<STR_LIT:true>'<EOL><DEDENT>if headers is not None:<EOL><INDENT>h['<STR_LIT>'] = headers<EOL><DEDENT>if expose_headers is not None:<EOL><INDENT>h['<STR_LIT>'] = expose_headers<EOL><DEDENT>return resp<EOL><DEDENT>f.provide_automatic_options = False<EOL>return update_wrapper(wrapped_function, f)<EOL><DEDENT>return decorator<EOL>
http://flask.pocoo.org/snippets/56/