def swift_acl_translate(acl, group='', user='', xml=False):
 swift_acl = {}
 swift_acl['public-read'] = [['HTTP_X_CONTAINER_READ', '.r:*,.rlistings']]
 swift_acl['public-read-write'] = [['HTTP_X_CONTAINER_WRITE', '.r:*'], ['HTTP_X_CONTAINER_READ', '.r:*,.rlistings']]
 swift_acl['private'] = [['HTTP_X_CONTAINER_WRITE', '.'], ['HTTP_X_CONTAINER_READ', '.']]
 if xml:
  dom = parseString(acl)
  acl = 'unknown'
  for grant in dom.getElementsByTagName('Grant'):
   permission = grant.getElementsByTagName('Permission')[0].firstChild.data
   grantee = grant.getElementsByTagName('Grantee')[0].getAttributeNode('xsi:type').nodeValue
   if ((permission == 'FULL_CONTROL') and (grantee == 'CanonicalUser') and (acl != 'public-read') and (acl != 'public-read-write')):
    acl = 'private'
   elif ((permission == 'READ') and (grantee == 'Group') and (acl != 'public-read-write')):
    acl = 'public-read'
   elif ((permission == 'WRITE') and (grantee == 'Group')):
    acl = 'public-read-write'
   else:
    acl = 'unsupported'
 if (acl == 'authenticated-read'):
  return 'Unsupported'
 elif (acl not in swift_acl):
  return 'InvalidArgument'
 return swift_acl[acl]

def swift_acl_translate ( acl , group = '' , user = '' , xml = False ) : swift_acl = { } swift_acl [ 'public-read' ] = [ [ 'HTTP_X_CONTAINER_READ' , '.r:*,.rlistings' ] ] swift_acl [ 'public-read-write' ] = [ [ 'HTTP_X_CONTAINER_WRITE' , '.r:*' ] , [ 'HTTP_X_CONTAINER_READ' , '.r:*,.rlistings' ] ] swift_acl [ 'private' ] = [ [ 'HTTP_X_CONTAINER_WRITE' , '.' ] , [ 'HTTP_X_CONTAINER_READ' , '.' ] ] if xml : dom = parseString ( acl ) acl = 'unknown' for grant in dom . getElementsByTagName ( 'Grant' ) : permission = grant . getElementsByTagName ( 'Permission' ) [ 0 ] . firstChild . data grantee = grant . getElementsByTagName ( 'Grantee' ) [ 0 ] . getAttributeNode ( 'xsi:type' ) . nodeValue if ( ( permission == 'FULL_CONTROL' ) and ( grantee == 'CanonicalUser' ) and ( acl != 'public-read' ) and ( acl != 'public-read-write' ) ) : acl = 'private' elif ( ( permission == 'READ' ) and ( grantee == 'Group' ) and ( acl != 'public-read-write' ) ) : acl = 'public-read' elif ( ( permission == 'WRITE' ) and ( grantee == 'Group' ) ) : acl = 'public-read-write' else : acl = 'unsupported' if ( acl == 'authenticated-read' ) : return 'Unsupported' elif ( acl not in swift_acl ) : return 'InvalidArgument' return swift_acl [ acl ]
takes an s3 style acl and returns a list of header/value pairs that implement that acl in swift .