thanks for asking this, it helped me.
youll probably need to flesh out the exceptions and re for the rootprompt but here you go.
def sudo(s,password):
rootprompt = re.compile('.*[$#]')
s.sendline('sudo -s')
i = s.expect([rootprompt,'assword.*: '])
if i==0:
print "didnt need password!"
pass
elif i==1:
print "sending password"
s.sendline(password)
j = s.expect([rootprompt,'Sorry, try again'])
if j == 0:
pass
elif j == 1:
raise Exception("bad password")
else:
raise Exception("unexpected output")
s.set_unique_promp