python-docutils/docutils-0.9.1-unicode.patch
Toshio Kuratomi e3712d3cab New update from upstream
- Fixes for previous patches incorporated there
- roman.py has been moved into a docutils submodule
- docutils doesn't work with PyXML.  before I poke around for the bug in PyXML,
  seeing if we're going to go through with deprecating it or if we can sanitize
  our python stdlib's handling of it.
- Fix for traceback in https://bugzilla.redhat.com/show_bug.cgi?id=786867
2012-07-20 18:24:04 -07:00

31 lines
1.2 KiB
Diff

Index: docutils-0.9.1/docutils/parsers/rst/directives/misc.py
===================================================================
--- docutils-0.9.1.orig/docutils/parsers/rst/directives/misc.py
+++ docutils-0.9.1/docutils/parsers/rst/directives/misc.py
@@ -10,6 +10,7 @@ import sys
import os.path
import re
import time
+import locale
from docutils import io, nodes, statemachine, utils
from docutils.error_reporting import SafeString, ErrorString
from docutils.parsers.rst import Directive, convert_directive_function
@@ -474,6 +475,17 @@ class Date(Directive):
'a substitution definition.' % self.name)
format = '\n'.join(self.content) or '%Y-%m-%d'
text = time.strftime(format)
+ if sys.version_info< (3, 0):
+ try:
+ text = unicode(text, locale.getpreferredencoding())
+ except UnicodeError:
+ try:
+ text = unicode(text, 'utf-8')
+ except UnicodeError:
+ # Fallback to something that can decode all bytes to
+ # something. Alternative fallback would be to decode
+ # with errors='replace'
+ text = unicode(text, 'latin-1')
return [nodes.Text(text)]