def _acl_from_headers(self, headers):
    canned_acl = headers.get('x-amz-acl', '')
    if canned_acl:
        return get_canned_acl(canned_acl)
    grants = []
    for (header, value) in headers.items():
        header = header.lower()
        if (not header.startswith('x-amz-grant-')):
            continue
        permission = {'read': 'READ', 'write': 'WRITE', 'read-acp': 'READ_ACP', 'write-acp': 'WRITE_ACP', 'full-control': 'FULL_CONTROL'}[header[len('x-amz-grant-'):]]
        grantees = []
        for key_and_value in value.split(','):
            (key, value) = re.match('([^=]+)="?([^"]+)"?', key_and_value.strip()).groups()
            if (key.lower() == 'id'):
                grantees.append(FakeGrantee(id=value))
            else:
                grantees.append(FakeGrantee(uri=value))
        grants.append(FakeGrant(grantees, [permission]))
    if grants:
        return FakeAcl(grants)
    else:
        return None
def _acl_from_headers(self, headers):
    canned_acl = headers.get('x-amz-acl', )
    if canned_acl:
        return get_canned_acl(canned_acl)
    grants = []
    for (header, value) in headers.items():
        header = header.lower()
        if (not header.startswith('x-amz-grant-')):
            continue
        permission = {'read': 'READ', 'write': 'WRITE', 'read-acp': 'READ_ACP', 'write-acp': 'WRITE_ACP', 'full-control': 'FULL_CONTROL'}[header[len('x-amz-grant-'):]]
        grantees = []
        for key_and_value in value.split(','):
            (key, value) = re.match('([^=]+)="?([^"]+)"?', key_and_value.strip()).groups()
            if (key.lower() == 'id'):
                grantees.append(FakeGrantee(id=value))
            else:
                grantees.append(FakeGrantee(uri=value))
        grants.append(FakeGrant(grantees, [permission]))
    if grants:
        return FakeAcl(grants)
    else:
        return None