I think you are duplicating what shlex does

http://docs.python.org/2/library/shlex.html