Best Python code snippet using localstack_python
s3_listener.py
Source:s3_listener.py
...384 return response385 s3_backend.buckets[bucket_name].payer = payer["RequestPaymentConfiguration"]["Payer"]386 response.status_code = 200387 return response388def convert_origins_into_list(allowed_origins):389 if isinstance(allowed_origins, list):390 return allowed_origins391 return [allowed_origins]392def get_origin_host(headers):393 origin = headers.get("Origin") or get_forwarded_for_host(headers)394 return origin395def append_cors_headers(bucket_name, request_method, request_headers, response):396 bucket_name = normalize_bucket_name(bucket_name)397 # Checking CORS is allowed or not398 cors = BUCKET_CORS.get(bucket_name)399 if not cors:400 return401 # Cleaning headers402 for header in CORS_HEADERS:403 if header in response.headers:404 del response.headers[header]405 # Fetching origin of the request406 origin = get_origin_host(request_headers)407 rules = cors["CORSConfiguration"]["CORSRule"]408 if not isinstance(rules, list):409 rules = [rules]410 response.headers["Access-Control-Allow-Origin"] = ""411 response.headers["Access-Control-Allow-Methods"] = ""412 response.headers["Access-Control-Allow-Headers"] = ""413 response.headers["Access-Control-Expose-Headers"] = ""414 for rule in rules:415 # add allow-origin header416 allowed_methods = rule.get("AllowedMethod", [])417 if request_method in allowed_methods:418 allowed_origins = rule.get("AllowedOrigin", [])419 # when only one origin is being set in cors then the allowed_origins is being420 # reflected as a string here,so making it a list and then proceeding.421 allowed_origins = convert_origins_into_list(allowed_origins)422 for allowed in allowed_origins:423 allowed = allowed or ""424 if origin in allowed or re.match(allowed.replace("*", ".*"), origin):425 response.headers["Access-Control-Allow-Origin"] = origin426 if "AllowedMethod" in rule:427 response.headers["Access-Control-Allow-Methods"] = (428 ",".join(allowed_methods)429 if isinstance(allowed_methods, list)430 else allowed_methods431 )432 if "AllowedHeader" in rule:433 allowed_headers = rule["AllowedHeader"]434 response.headers["Access-Control-Allow-Headers"] = (435 ",".join(allowed_headers)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!