def switchUID(uid, gid, euid=False):
 if euid:
  setuid = os.seteuid
  setgid = os.setegid
  getuid = os.geteuid
 else:
  setuid = os.setuid
  setgid = os.setgid
  getuid = os.getuid
 if (gid is not None):
  setgid(gid)
 if (uid is not None):
  if (uid == getuid()):
   uidText = ((euid and 'euid') or 'uid')
   actionText = ('tried to drop privileges and set%s %s' % (uidText, uid))
   problemText = ('%s is already %s' % (uidText, getuid()))
   warnings.warn(('%s but %s; should we be root? Continuing.' % (actionText, problemText)))
  else:
   initgroups(uid, gid)
   setuid(uid)

def switchUID ( uid , gid , euid = False ) : if euid : setuid = os . seteuid setgid = os . setegid getuid = os . geteuid else : setuid = os . setuid setgid = os . setgid getuid = os . getuid if ( gid is not None ) : setgid ( gid ) if ( uid is not None ) : if ( uid == getuid ( ) ) : uidText = ( ( euid and 'euid' ) or 'uid' ) actionText = ( 'tried to drop privileges and set%s %s' % ( uidText , uid ) ) problemText = ( '%s is already %s' % ( uidText , getuid ( ) ) ) warnings . warn ( ( '%s but %s; should we be root? Continuing.' % ( actionText , problemText ) ) ) else : initgroups ( uid , gid ) setuid ( uid )
attempts to switch the uid/euid and gid/egid for the current process .