#NEWLINE# def allow_origins( func = None , custom_origins = None ) : #NEWLINE# #INDENT# '\n    Add headers for Cross-origin resource sharing based on\n    `CORS_ALLOWED_ORIGINS` in config, or parameters passed to the decorator.\n    `CORS_ALLOWED_ORIGINS` can be a list of allowed origins or `"*"` to allow\n    all origins.\n\n    ' #NEWLINE# def wrapped( func ) : #NEWLINE# #INDENT# def _get_origin( allowed_origins , origin ) : #NEWLINE# #INDENT# " Helper method to discover the proper value for\n            Access-Control-Allow-Origin to use.\n\n            If the allowed origin is a string it will check if it's '*'\n            wildcard or an actual domain. When a tuple or list is given\n            instead, it will look for the current domain in the list. If any of\n            the checks fail it will return False.\n\n            " #NEWLINE# if ( type ( allowed_origins ) in ( str , unicode ) ) : #NEWLINE# #INDENT# if ( ( allowed_origins == '*' ) or ( allowed_origins == origin ) ) : #NEWLINE# #INDENT# return allowed_origins #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( type ( allowed_origins ) in ( list , tuple ) ) : #NEWLINE# #INDENT# if ( origin in allowed_origins ) : #NEWLINE# #INDENT# return origin #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return False #NEWLINE# #UNINDENT# @ wraps ( func ) #NEWLINE# def decorated( * args , **kwargs ) : #NEWLINE# #INDENT# origin = request . headers . get ( 'Origin' ) #NEWLINE# allowed_origins = ( custom_origins or app . config . get ( 'CORS_ALLOWED_ORIGINS' , [ ] ) ) #NEWLINE# g . cors = _get_origin ( allowed_origins , origin ) #NEWLINE# return func ( * args , ** kwargs ) #NEWLINE# #UNINDENT# return decorated #NEWLINE# #UNINDENT# if func : #NEWLINE# #INDENT# return wrapped ( custom_origins ) #NEWLINE# #UNINDENT# return wrapped