def startElement(self, name, attrs, connection): if name == "AccessControlPolicy": self.namespace = attrs.get("xmlns", None) return None if name == "Owner": self.owner = User(self) return self.owner elif name == "AccessControlList": self.acl = ACL(self) return self.acl else: return None
class Policy(object): def __init__(self, parent=None): self.parent = parent self.namespace = None self.acl = None def __repr__(self): grants = [] for g in self.acl.grants: if g.id == self.owner.id: grants.append("%s (owner) = %s" % (g.display_name, g.permission)) else: if g.type == "CanonicalUser": u = g.display_name elif g.type == "Group": u = g.uri else: u = g.email_address grants.append("%s = %s" % (u, g.permission)) return "<Policy: %s>" % ", ".join(grants) def startElement(self, name, attrs, connection): if name == "AccessControlPolicy": self.namespace = attrs.get("xmlns", None) return None if name == "Owner": self.owner = User(self) return self.owner elif name == "AccessControlList": self.acl = ACL(self) return self.acl else: return None def endElement(self, name, value, connection): if name == "Owner": pass elif name == "AccessControlList": pass else: setattr(self, name, value) def to_xml(self): if self.namespace is not None: s = '<AccessControlPolicy xmlns="{0}">'.format(self.namespace) else: s = "<AccessControlPolicy>" s += self.owner.to_xml() s += self.acl.to_xml() s += "</AccessControlPolicy>" return s