def _testPermissions(uid, gid, spath, mode='r'):
 if (mode == 'r'):
  usr = stat.S_IRUSR
  grp = stat.S_IRGRP
  oth = stat.S_IROTH
  amode = os.R_OK
 elif (mode == 'w'):
  usr = stat.S_IWUSR
  grp = stat.S_IWGRP
  oth = stat.S_IWOTH
  amode = os.W_OK
 else:
  raise ValueError(("Invalid mode %r: must specify 'r' or 'w'" % (mode,)))
 access = False
 if os.path.exists(spath):
  if (uid == 0):
   access = True
  else:
   s = os.stat(spath)
   if ((usr & s.st_mode) and (uid == s.st_uid)):
    access = True
   elif ((grp & s.st_mode) and (gid in _getgroups(uid))):
    access = True
   elif (oth & s.st_mode):
    access = True
 if access:
  if (not os.access(spath, amode)):
   access = False
   log.msg(('Filesystem grants permission to UID %d but it is inaccessible to me running as UID %d' % (uid, os.getuid())))
 return access

def _testPermissions ( uid , gid , spath , mode = 'r' ) : if ( mode == 'r' ) : usr = stat . S_IRUSR grp = stat . S_IRGRP oth = stat . S_IROTH amode = os . R_OK elif ( mode == 'w' ) : usr = stat . S_IWUSR grp = stat . S_IWGRP oth = stat . S_IWOTH amode = os . W_OK else : raise ValueError ( ( "Invalid mode %r: must specify 'r' or 'w'" % ( mode , ) ) ) access = False if os . path . exists ( spath ) : if ( uid == 0 ) : access = True else : s = os . stat ( spath ) if ( ( usr & s . st_mode ) and ( uid == s . st_uid ) ) : access = True elif ( ( grp & s . st_mode ) and ( gid in _getgroups ( uid ) ) ) : access = True elif ( oth & s . st_mode ) : access = True if access : if ( not os . access ( spath , amode ) ) : access = False log . msg ( ( 'Filesystem grants permission to UID %d but it is inaccessible to me running as UID %d' % ( uid , os . getuid ( ) ) ) ) return access
checks to see if uid has proper permissions to access path with mode @type uid: c{int} .