src/pyams_security/schema.py
changeset 2 94e76f8e9828
child 32 5b6650d040c2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_security/schema.py	Mon Feb 23 17:55:05 2015 +0100
@@ -0,0 +1,62 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from zope.schema.interfaces import ITextLine, ISet
+
+# import packages
+from zope.interface import implementer, Interface
+from zope.schema import TextLine, Set
+
+
+class IRoleField(Interface):
+    """Base role field interface"""
+
+    role_id = TextLine(title="Matching role ID",
+                       required=False)
+
+
+class IPrincipal(ITextLine, IRoleField):
+    """Principal field interface"""
+
+
+@implementer(IPrincipal)
+class Principal(TextLine):
+    """Principal field"""
+
+    role_id = None
+
+    def __init__(self, **kwargs):
+        if 'role_id' in kwargs:
+            self.role_id = kwargs.pop('role_id')
+        super(Principal, self).__init__(**kwargs)
+
+
+class IPrincipalsSet(ISet, IRoleField):
+    """Principals set interface"""
+
+
+@implementer(IPrincipalsSet)
+class PrincipalsSet(Set):
+    """Principals set field"""
+
+    role_id = None
+
+    def __init__(self, **kwargs):
+        if 'role_id' in kwargs:
+            self.role_id = kwargs.pop('role_id')
+        super(PrincipalsSet, self).__init__(**kwargs)