import ast
from functools import reduce


def extractACL(headers):
        """
        Extract the ACL from the container headers
        """
        # Get ACLs from the headers
        acl_read = ast.literal_eval(headers.get('x-container-read', '{}'))
        acl_write = ast.literal_eval(headers.get('x-container-write', '{}'))
        
        if acl_read != {}:
            acl_r  = reduce(lambda x, y: x + y, acl_read.values(), [])
             # Remove AUTH_ from names
            readers = map(lambda x: x.replace('AUTH_', ''), acl_r)
            aclr = ','.join(readers)
        else: aclr = ""

        if acl_write != {}:
            acl_w  = reduce(lambda x, y: x + y, acl_write.values(), [])
            writers = map(lambda x: x.replace('AUTH_', ''), acl_w)
            aclw = ','.join(writers)
        else: aclw = ""

        return (aclr,aclw)