[python-docutils/f17] Fix for https://bugzilla.redhat.com/show_bug.cgi?id=786867

Toshio くらとみ toshio at fedoraproject.org
Sat Jul 21 03:08:22 UTC 2012


commit 6e603ebf38f00589fcc1bf38584824e80f4e4397
Author: Toshio Kuratomi <toshio at fedoraproject.org>
Date:   Fri Jul 20 20:08:02 2012 -0700

    Fix for https://bugzilla.redhat.com/show_bug.cgi?id=786867

 docutils-0.8.1-unicode.patch                       |   30 ++++
 ...ckport-0.9.1-py2.7.3-prettyprint-test-fix.patch |  184 ++++++++++++++++++++
 python-docutils.spec                               |   12 ++-
 3 files changed, 225 insertions(+), 1 deletions(-)
---
diff --git a/docutils-0.8.1-unicode.patch b/docutils-0.8.1-unicode.patch
new file mode 100644
index 0000000..7b311e1
--- /dev/null
+++ b/docutils-0.8.1-unicode.patch
@@ -0,0 +1,30 @@
+Index: docutils-0.8.1/docutils/parsers/rst/directives/misc.py
+===================================================================
+--- docutils-0.8.1.orig/docutils/parsers/rst/directives/misc.py
++++ docutils-0.8.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
+@@ -426,6 +427,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)]
+ 
+ 
diff --git a/docutils-backport-0.9.1-py2.7.3-prettyprint-test-fix.patch b/docutils-backport-0.9.1-py2.7.3-prettyprint-test-fix.patch
new file mode 100644
index 0000000..1632c74
--- /dev/null
+++ b/docutils-backport-0.9.1-py2.7.3-prettyprint-test-fix.patch
@@ -0,0 +1,184 @@
+--- docutils/test/test_writers/test_docutils_xml.py	2009/04/01 20:00:21	5889
++++ docutils/test/test_writers/test_docutils_xml.py	2011/12/20 09:36:10	7266
+@@ -10,24 +10,44 @@
+ 
+ from __init__ import DocutilsTestSupport
+ 
++import sys
+ import docutils
+ import docutils.core
+-from docutils._compat import b
+ 
++# sample strings:
+ 
+-class DocutilsXMLTestCase(DocutilsTestSupport.StandardTestCase):
+-
+-    input = b("""\
++source = u"""\
+ Test
+ 
+ ----------
+ 
+-Test. \xc3\xa4\xc3\xb6\xc3\xbc\xe2\x82\xac""")
+-    xmldecl = b('<?xml version="1.0" encoding="iso-8859-1"?>\n')
+-    doctypedecl = b('<!DOCTYPE document PUBLIC "+//IDN docutils.sourceforge.net//DTD Docutils Generic//EN//XML" "http://docutils.sourceforge.net/docs/ref/docutils.dtd">\n')
+-    generatedby = b('<!-- Generated by Docutils %s -->\n' % docutils.__version__)
+-    bodynormal = b('<document source="&lt;string&gt;"><paragraph>Test</paragraph><transition/><paragraph>Test. \xe4\xf6\xfc&#8364;</paragraph></document>')
+-    bodynewlines = b("""\
++Test. \xe4\xf6\xfc\u20ac"""
++
++xmldecl = u"""<?xml version="1.0" encoding="iso-8859-1"?>
++"""
++
++doctypedecl = u"""\
++<!DOCTYPE document PUBLIC "+//IDN docutils.sourceforge.net\
++//DTD Docutils Generic//EN//XML"\
++ "http://docutils.sourceforge.net/docs/ref/docutils.dtd">
++"""
++
++generatedby = u'<!-- Generated by Docutils %s -->\n' % docutils.__version__
++
++bodynormal = u"""\
++<document source="&lt;string&gt;"><paragraph>Test</paragraph>\
++<transition/><paragraph>Test. \xe4\xf6\xfc&#8364;</paragraph>\
++</document>"""
++
++bodynewlines = u"""\
++<document source="&lt;string&gt;">
++<paragraph>Test</paragraph>
++<transition/>
++<paragraph>Test. \xe4\xf6\xfc&#8364;</paragraph>
++</document>
++"""
++
++bodynewlines_old = u"""\
+ <document source="&lt;string&gt;">
+ <paragraph>
+ Test
+@@ -37,8 +57,17 @@
+ Test. \xe4\xf6\xfc&#8364;
+ </paragraph>
+ </document>
+-""")
+-    bodyindents = b("""\
++"""
++
++bodyindents = u"""\
++<document source="&lt;string&gt;">
++    <paragraph>Test</paragraph>
++    <transition/>
++    <paragraph>Test. \xe4\xf6\xfc&#8364;</paragraph>
++</document>
++"""
++
++bodyindents_old = u"""\
+ <document source="&lt;string&gt;">
+     <paragraph>
+         Test
+@@ -48,36 +77,78 @@
+         Test. \xe4\xf6\xfc&#8364;
+     </paragraph>
+ </document>
+-""")
++"""
++
++# New formatting introduced in versions 2.7.3 and 3.2.3 on 2011-11-18
++# to fix http://bugs.python.org/issue4147
++# (Some distributions ship also earlier versions with this patch.)
++if (sys.version_info < (2, 7, 3) or
++    sys.version_info[0] == 3 and sys.version_info < (3, 2, 3)):
++    whitespace_fix = False
++else:
++    whitespace_fix = True
++
++def publish_xml(settings):
++    return docutils.core.publish_string(source=source.encode('utf8'),
++                                        reader_name='standalone',
++                                        writer_name='docutils_xml',
++                                        settings_overrides=settings)
++
++
++class DocutilsXMLTestCase(DocutilsTestSupport.StandardTestCase):
++
++    settings = {'input_encoding': 'utf8',
++                'output_encoding': 'iso-8859-1',
++                '_disable_config': 1}
+ 
+     def test_publish(self):
+-        settings = {'input_encoding': 'utf8',
+-                    'output_encoding': 'iso-8859-1',
+-                    '_disable_config': 1}
+-        for settings['newlines'] in 0, 1:
+-            for settings['indents'] in 0, 1:
+-                for settings['xml_declaration'] in 0, 1:
+-                    for settings['doctype_declaration'] in 0, 1:
+-
+-                        expected = b('')
+-                        if settings['xml_declaration']:
+-                            expected += self.xmldecl
+-                        if settings['doctype_declaration']:
+-                            expected += self.doctypedecl
+-                        expected += self.generatedby
+-                        if settings['indents']:
+-                            expected += self.bodyindents
+-                        elif settings['newlines']:
+-                            expected += self.bodynewlines
+-                        else:
+-                            expected += self.bodynormal
+-
+-                        self.assertEqual(docutils.core.publish_string
+-                                         (source=self.input,
+-                                          reader_name='standalone',
+-                                          writer_name='docutils_xml',
+-                                          settings_overrides=settings),
+-                                         expected)
++        for self.settings['xml_declaration'] in True, False:
++            for self.settings['doctype_declaration'] in True, False:
++                expected = u''
++                if self.settings['xml_declaration']:
++                    expected += xmldecl
++                if self.settings['doctype_declaration']:
++                    expected += doctypedecl
++                expected += generatedby
++                expected += bodynormal
++                result = publish_xml(self.settings)
++                self.assertEqual(result, expected.encode('latin1'))
++
++    def test_publish_indents(self):
++        self.settings['indents'] = True
++        self.settings['newlines'] = False
++        self.settings['xml_declaration'] = False
++        self.settings['doctype_declaration'] = False
++        result = publish_xml(self.settings)
++
++        # New formatting introduced in versions 2.7.3 and 3.2.3
++        if whitespace_fix:
++            expected = (generatedby + bodyindents).encode('latin1')
++        else:
++            expected = (generatedby + bodyindents_old).encode('latin1')
++        # Some distributions patch also earlier versions:
++        if (result != expected and not whitespace_fix):
++            expected = (generatedby + bodyindents).encode('latin1')
++
++        self.assertEqual(result, expected)
++
++    def test_publish_newlines(self):
++        self.settings['newlines'] = True
++        self.settings['indents'] = False
++        self.settings['xml_declaration'] = False
++        self.settings['doctype_declaration'] = False
++        result = publish_xml(self.settings)
++
++        # New formatting introduced in versions 2.7.3 and 3.2.3
++        if whitespace_fix:
++            expected = (generatedby + bodynewlines).encode('latin1')
++        else:
++            expected = (generatedby + bodynewlines_old).encode('latin1')
++        # Some distributions patch also earlier versions:
++        if (result != expected and not whitespace_fix):
++            expected = (generatedby + bodynewlines).encode('latin1')
++
++        self.assertEqual(result, expected)
+ 
+ 
+ if __name__ == '__main__':
diff --git a/python-docutils.spec b/python-docutils.spec
index 7ff7990..9a70c38 100644
--- a/python-docutils.spec
+++ b/python-docutils.spec
@@ -11,7 +11,7 @@
 
 Name:           python-%{srcname}
 Version:        0.8.1
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        System for processing plaintext documentation
 
 Group:          Development/Languages
@@ -29,6 +29,11 @@ Source0:        http://downloads.sourceforge.net/docutils/%{srcname}-%{version}.
 Patch0: docutils-missing-import.patch
 # Submitted upstream
 Patch1: docutils-unicode-traceback.patch
+# Another patch -- submitted against 0.9.1
+Patch2: docutils-0.8.1-unicode.patch
+# Backport 0.9.1 fix for unittest w/ py-2.7.3
+Patch3: docutils-backport-0.9.1-py2.7.3-prettyprint-test-fix.patch
+
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildArch:       noarch
 
@@ -80,6 +85,8 @@ This package contains the module, ported to run under python3.
 
 %patch0 -p0 -b .exc
 %patch1 -p1 -b .enc
+%patch2 -p1 -b .unic
+%patch3 -p1 -b py2.7.3
 
 # Remove shebang from library files
 for file in docutils/_string_template_compat.py docutils/math/{__init__.py,latex2mathml.py}; do
@@ -181,6 +188,9 @@ rm -rf %{buildroot}
 %{python3_sitelib}/*
 
 %changelog
+* Fri Jul 20 2012 Toshio Kuratomi <toshio at fedoraproject.org> - 0.8.1-3
+- Fix for https://bugzilla.redhat.com/show_bug.cgi?id=786867
+
 * Mon Jan 30 2012 Toshio Kuratomi <toshio at fedoraproject.org> - 0.8.1-2
 - Fix a unicode traceback https://bugzilla.redhat.com/show_bug.cgi?id=785622
 


More information about the scm-commits mailing list