diff -r 097b72d73594 Lib/pydoc.py --- a/Lib/pydoc.py Fri Apr 27 00:20:39 2012 -0700 +++ b/Lib/pydoc.py Fri Apr 27 13:52:05 2012 +0200 @@ -182,6 +182,24 @@ return name, kind, cls, value return map(fixup, inspect.classify_class_attrs(object)) +# ----------------------------------------------------- Unicode support helpers + +try: + unicode +except NameError: + _encoding = 'ascii' + def _encode(text, encoding='ascii'): + return text +else: + import locale + _encoding = locale.getpreferredencoding() + + def _encode(text, encoding=None): + if isinstance(text, unicode): + return text.encode(encoding or _encoding, 'xmlcharrefreplace') + else: + return text + # ----------------------------------------------------- module manipulation def ispackage(path): @@ -424,12 +442,12 @@ def page(self, title, contents): """Format an HTML page.""" - return ''' + return _encode('''