re.sub( r"&#([0-9]+);", repl, replacement_string)

Should be

    re.sub(r'&#([0-9]+);', repl, replacement_string)

Because

* There shouldn't be a space before args as per pep8.
* String literals in the file are using single quote `'` instead of `"`.