def cors_validation(func):
 @functools.wraps(func)
 def wrapped(*a, **kw):
  controller = a[0]
  req = a[1]
  req_origin = req.headers.get('Origin', None)
  if req_origin:
   container_info = controller.container_info(controller.account_name, controller.container_name, req)
   cors_info = container_info.get('cors', {})
   resp = func(*a, **kw)
   if (controller.app.strict_cors_mode and (not controller.is_origin_allowed(cors_info, req_origin))):
    return resp
   if ('Access-Control-Expose-Headers' not in resp.headers):
    expose_headers = set(['cache-control', 'content-language', 'content-type', 'expires', 'last-modified', 'pragma', 'etag', 'x-timestamp', 'x-trans-id', 'x-openstack-request-id'])
    for header in resp.headers:
     if (header.startswith('X-Container-Meta') or header.startswith('X-Object-Meta')):
      expose_headers.add(header.lower())
    if cors_info.get('expose_headers'):
     expose_headers = expose_headers.union([header_line.strip().lower() for header_line in cors_info['expose_headers'].split(' ') if header_line.strip()])
    resp.headers['Access-Control-Expose-Headers'] = ', '.join(expose_headers)
   if ('Access-Control-Allow-Origin' not in resp.headers):
    if (cors_info['allow_origin'] and (cors_info['allow_origin'].strip() == '*')):
     resp.headers['Access-Control-Allow-Origin'] = '*'
    else:
     resp.headers['Access-Control-Allow-Origin'] = req_origin
   return resp
  else:
   return func(*a, **kw)
 return wrapped

def cors_validation ( func ) : @ functools . wraps ( func ) def wrapped ( * a , ** kw ) : controller = a [ 0 ] req = a [ 1 ] req_origin = req . headers . get ( 'Origin' , None ) if req_origin : container_info = controller . container_info ( controller . account_name , controller . container_name , req ) cors_info = container_info . get ( 'cors' , { } ) resp = func ( * a , ** kw ) if ( controller . app . strict_cors_mode and ( not controller . is_origin_allowed ( cors_info , req_origin ) ) ) : return resp if ( 'Access-Control-Expose-Headers' not in resp . headers ) : expose_headers = set ( [ 'cache-control' , 'content-language' , 'content-type' , 'expires' , 'last-modified' , 'pragma' , 'etag' , 'x-timestamp' , 'x-trans-id' , 'x-openstack-request-id' ] ) for header in resp . headers : if ( header . startswith ( 'X-Container-Meta' ) or header . startswith ( 'X-Object-Meta' ) ) : expose_headers . add ( header . lower ( ) ) if cors_info . get ( 'expose_headers' ) : expose_headers = expose_headers . union ( [ header_line . strip ( ) . lower ( ) for header_line in cors_info [ 'expose_headers' ] . split ( ' ' ) if header_line . strip ( ) ] ) resp . headers [ 'Access-Control-Expose-Headers' ] = ', ' . join ( expose_headers ) if ( 'Access-Control-Allow-Origin' not in resp . headers ) : if ( cors_info [ 'allow_origin' ] and ( cors_info [ 'allow_origin' ] . strip ( ) == '*' ) ) : resp . headers [ 'Access-Control-Allow-Origin' ] = '*' else : resp . headers [ 'Access-Control-Allow-Origin' ] = req_origin return resp else : return func ( * a , ** kw ) return wrapped
decorator to check if the request is a cors request and if so .