def maybe_drop_privileges(uid=None, gid=None):
 if (sys.platform == u'win32'):
  return
 if os.geteuid():
  if (not os.getuid()):
   raise SecurityError(u'contact support')
 uid = (uid and parse_uid(uid))
 gid = (gid and parse_gid(gid))
 if uid:
  _setuid(uid, gid)
 else:
  (gid and setgid(gid))
 if (uid and (not os.getuid()) and (not os.geteuid())):
  raise SecurityError(u'Still root uid after drop privileges!')
 if (gid and (not os.getgid()) and (not os.getegid())):
  raise SecurityError(u'Still root gid after drop privileges!')

def maybe_drop_privileges ( uid = None , gid = None ) : if ( sys . platform == u'win32' ) : return if os . geteuid ( ) : if ( not os . getuid ( ) ) : raise SecurityError ( u'contact support' ) uid = ( uid and parse_uid ( uid ) ) gid = ( gid and parse_gid ( gid ) ) if uid : _setuid ( uid , gid ) else : ( gid and setgid ( gid ) ) if ( uid and ( not os . getuid ( ) ) and ( not os . geteuid ( ) ) ) : raise SecurityError ( u'Still root uid after drop privileges!' ) if ( gid and ( not os . getgid ( ) ) and ( not os . getegid ( ) ) ) : raise SecurityError ( u'Still root gid after drop privileges!' )
change process privileges to new user/group .