SF.net SVN: docutils:[9846 ] trunk/docutils

aa-turner--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9846
          http://sourceforge.net/p/docutils/code/9846
Author:   aa-turner
Date:     2024-08-02 01:36:18 +0000 (Fri, 02 Aug 2024)
Log Message:
-----------
Adopt ``RomanNumeral``

Modified Paths:
--------------
    trunk/docutils/docutils/parsers/rst/states.py
    trunk/docutils/docutils/utils/_roman_numerals.py
    trunk/docutils/docutils/writers/latex2e/__init__.py
    trunk/docutils/docutils/writers/manpage.py
    trunk/docutils/test/test_utils/test__roman_numerals.py

Modified: trunk/docutils/docutils/parsers/rst/states.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/states.py	2024-08-02 01:16:42 UTC (rev 9845)
+++ trunk/docutils/docutils/parsers/rst/states.py	2024-08-02 01:36:18 UTC (rev 9846)
@@ -114,8 +114,12 @@
 import docutils.parsers.rst
 from docutils.parsers.rst import directives, languages, tableparser, roles
 from docutils.utils import escape2null, column_width
-from docutils.utils import punctuation_chars, roman, urischemes
+from docutils.utils import punctuation_chars, urischemes
 from docutils.utils import split_escaped_whitespace
+from docutils.utils._roman_numerals import (
+    InvalidRomanNumeralError,
+    RomanNumeral,
+)
 
 
 class MarkupError(DataError): pass
@@ -1067,10 +1071,6 @@
     return ord(s) - _zero
 
 
-def _lowerroman_to_int(s):
-    return roman.fromRoman(s.upper())
-
-
 class Body(RSTState):
 
     """
@@ -1098,8 +1098,8 @@
     enum.converters = {'arabic': int,
                        'loweralpha': _loweralpha_to_int,
                        'upperalpha': _upperalpha_to_int,
-                       'lowerroman': _lowerroman_to_int,
-                       'upperroman': roman.fromRoman}
+                       'lowerroman': RomanNumeral.from_string,
+                       'upperroman': RomanNumeral.from_string}
 
     enum.sequenceregexps = {}
     for sequence in enum.sequences:
@@ -1382,8 +1382,8 @@
             ordinal = 1
         else:
             try:
-                ordinal = self.enum.converters[sequence](text)
-            except roman.InvalidRomanNumeralError:
+                ordinal = int(self.enum.converters[sequence](text))
+            except InvalidRomanNumeralError:
                 ordinal = None
         return format, sequence, text, ordinal
 
@@ -1433,8 +1433,8 @@
                 enumerator = chr(ordinal + ord('a') - 1)
             elif sequence.endswith('roman'):
                 try:
-                    enumerator = roman.toRoman(ordinal)
-                except roman.RomanError:
+                    enumerator = RomanNumeral(ordinal).to_uppercase()
+                except TypeError:
                     return None
             else:                       # shouldn't happen
                 raise ParserError('unknown enumerator sequence: "%s"'

Modified: trunk/docutils/docutils/utils/_roman_numerals.py
===================================================================
--- trunk/docutils/docutils/utils/_roman_numerals.py	2024-08-02 01:16:42 UTC (rev 9845)
+++ trunk/docutils/docutils/utils/_roman_numerals.py	2024-08-02 01:36:18 UTC (rev 9846)
@@ -1,5 +1,5 @@
 # $Id$
-# Author:  Adam Turner.
+# Author: Adam Turner.
 # Copyright: This module is placed in the public domain
 #            or under the `Zero Clause BSD licence`_,
 #            whichever is more permissive.

Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py	2024-08-02 01:16:42 UTC (rev 9845)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py	2024-08-02 01:36:18 UTC (rev 9846)
@@ -17,13 +17,10 @@
 import string
 from urllib.request import url2pathname
 import warnings
-try:
-    import roman
-except ImportError:
-    import docutils.utils.roman as roman
 
 from docutils import frontend, nodes, languages, writers, utils
 from docutils.transforms import writer_aux
+from docutils.utils._roman_numerals import RomanNumeral
 from docutils.utils.math import pick_math_environment, unichar2tex
 
 LATEX_WRITER_DIR = Path(__file__).parent
@@ -2196,7 +2193,7 @@
         suffix = node.get('suffix', '.')
 
         enum_level = len(self._enumeration_counters)+1
-        counter_name = 'enum' + roman.toRoman(enum_level).lower()
+        counter_name = 'enum' + RomanNumeral(enum_level).to_lowercase()
         label = r'%s\%s{%s}%s' % (prefix, enumtype, counter_name, suffix)
         self._enumeration_counters.append(label)
 
@@ -3139,13 +3136,13 @@
                 # section level not supported by LaTeX
                 if self.settings.legacy_class_functions:
                     self.fallbacks['title'] = PreambleCmds.title_legacy
-                    section_name += '[section%s]' % roman.toRoman(level)
+                    section_name += '[section%s]' % RomanNumeral(level)
                 else:
                     if not self.fallback_stylesheet:
                         self.fallbacks['title'] = PreambleCmds.title
                         self.fallbacks['DUclass'] = PreambleCmds.duclass
                     self.out.append('\\begin{DUclass}{section%s}\n'
-                                    % roman.toRoman(level))
+                                    % RomanNumeral(level))
 
             # System messages heading in red:
             if 'system-messages' in node.parent['classes']:

Modified: trunk/docutils/docutils/writers/manpage.py
===================================================================
--- trunk/docutils/docutils/writers/manpage.py	2024-08-02 01:16:42 UTC (rev 9845)
+++ trunk/docutils/docutils/writers/manpage.py	2024-08-02 01:36:18 UTC (rev 9846)
@@ -47,10 +47,7 @@
 
 import docutils
 from docutils import frontend, nodes, writers, languages
-try:
-    import roman
-except ImportError:
-    from docutils.utils import roman
+from docutils.utils._roman_numerals import RomanNumeral
 
 FIELD_LIST_INDENT = 7
 DEFINITION_LIST_INDENT = 7
@@ -408,10 +405,11 @@
                 if self._style in ('loweralpha', 'upperalpha'):
                     return "%c." % self._cnt
                 if self._style.endswith('roman'):
-                    res = roman.toRoman(self._cnt) + '.'
+                    res = RomanNumeral(self._cnt)
                     if self._style.startswith('upper'):
-                        return res.upper()
-                    return res.lower()
+                        return res.to_uppercase() + '.'
+                    else:
+                        return res.to_lowercase() + '.'
                 # else 'arabic', ...
                 return "%d." % self._cnt
 

Modified: trunk/docutils/test/test_utils/test__roman_numerals.py
===================================================================
--- trunk/docutils/test/test_utils/test__roman_numerals.py	2024-08-02 01:16:42 UTC (rev 9845)
+++ trunk/docutils/test/test_utils/test__roman_numerals.py	2024-08-02 01:36:18 UTC (rev 9846)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python3
 
 # $Id$
-# Author:  Adam Turner.
+# Author: Adam Turner.
 # Copyright: This module is placed in the public domain
 #            or under the `Zero Clause BSD licence`_,
 #            whichever is more permissive.

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.