+# -*- coding:utf-8 -*-
+
+# py-rsbac - RSBAC Python bindings
+# Copyright (C) 2006 Frederic Jolliton <pyrsbac@tuxee.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+__all__ = [ 'SystemRole' ]
+
+import sys
+
+from rsbac import headers
+
+_g_systemRolesName = {}
+_g_systemRoles = {}
+
+class SystemRole( object ) :
+ __slots__ = ( 'id' , )
+ def __new__( cls , id ) :
+ instance = _g_systemRoles.get( id )
+ if instance is None :
+ instance = object.__new__( cls )
+ instance.__init_singleton__( id )
+ _g_systemRoles[ id ] = instance
+ return instance
+ def __init_singleton__( self , id ) :
+ self.id = id
+ def __int__( self ) :
+ return int( self.id )
+ def __long__( self ) :
+ return long( self.id )
+ def __repr__( self ) :
+ return '<SystemRole %s [%d]>' % ( _g_systemRolesName.get( self.id , '??' ) , self.id )
+
+def createSystemRoles() :
+ m = sys.modules[ __name__ ]
+ for name in dir( headers ) :
+ if name.startswith( 'SR_' ) and name.upper() != 'SR_NONE' :
+ role = name[ 3 : ]
+ value = getattr( headers , name )
+ _g_systemRolesName[ value ] = role
+ setattr( m , role , SystemRole( value ) )
+ __all__.append( role )
+createSystemRoles()
+del createSystemRoles
+
+# Local Variables:
+# indent-tabs-mode: nil
+# python-indent: 4
+# End: