The normal tty behavior is to send \r\n instead of \n. This can interact badly with some systems - in particular, if using pexpect from a buildbot with logfile set to stdout, everything is double-spaced in the logs.
It's useful to strip these out. On most systems you could probably do that by masking out termios.ONLCR during tty setup. That's not an option on my system for complicated reasons I won't get into, so this patch instead works by removing all carriage returns by regular expression on input from the tty.