diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2010-10-26 02:29:43 +0200 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2010-10-26 02:29:43 +0200 |
| commit | 9a44bc91a7f2aad0f14e486f77ed88bb1b2980c1 (patch) | |
| tree | d35c5228a4fe91c064bd6978bd6991dc7f3a4556 | |
| parent | c6dc4fa3ca6841854641205c8ceeab40a66c7c8b (diff) | |
| download | alias-9a44bc91a7f2aad0f14e486f77ed88bb1b2980c1.tar.gz | |
Fix a bug in Object.setPermission (newlines were added when changing the permissions)
| -rw-r--r-- | object.py | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- import StringIO import hashlib +import sys import os import os.path import zlib import datetime import fileinput -import permission +from permission import * class Object : @@ -92,6 +93,7 @@ class Object : file.close() def getPermission( self, user ) : + file = open( self.path + '/permissions', 'r' ) for line in file : @@ -101,7 +103,7 @@ class Object : return 0 - def setPermission(self, user, perm ) : + def setPermission(self, user, permission ) : if not self.saved : self.save() @@ -109,22 +111,25 @@ class Object : for line in fileinput.input( self.path + "/permissions", inplace=1 ) : name, sep, perm = line.rstrip('\n').partition(' ') if name == user : - print name + sep + perm + sys.stdout.write( name + ' ' + str( permission ) + '\n' ) sentinel = True else : - print line + sys.stdout.write( line ) if not sentinel : file = open( self.path + '/permissions', 'a' ) - file.write( user + ' ' + str( perm ) ) + file.write( user + ' ' + str( permission ) + '\n' ) file.close() if __name__== '__main__' : x = Object({'parent' : 'toto', 'author' : 'Zaran'}) - x.setPermission("test", permission.READ) - + x.setPermission("test", READ ) + x.setPermission( "toto", READ | MODIFY ) + x.setPermission( "toto", READ | MODIFY | APPEND ) + x.setPermission( "toto2", READ | MODIFY | APPEND ) + print x.getPermission("toto") child = Object({'parent' : x.name, 'author' : 'Zaran'}) child.save() |
