|
114 | 114 | import docutils.parsers.rst |
115 | 115 | from docutils.parsers.rst import directives, languages, tableparser, roles |
116 | 116 | from docutils.utils import escape2null, column_width |
117 | | -from docutils.utils import punctuation_chars, roman, urischemes |
| 117 | +from docutils.utils import punctuation_chars, urischemes |
118 | 118 | from docutils.utils import split_escaped_whitespace |
| 119 | +from docutils.utils._roman_numerals import ( |
| 120 | + InvalidRomanNumeralError, |
| 121 | + RomanNumeral, |
| 122 | +) |
119 | 123 |
|
120 | 124 |
|
121 | 125 | class MarkupError(DataError): pass |
@@ -1067,10 +1071,6 @@ def _upperalpha_to_int(s, _zero=(ord('A')-1)): |
1067 | 1071 | return ord(s) - _zero |
1068 | 1072 |
|
1069 | 1073 |
|
1070 | | -def _lowerroman_to_int(s): |
1071 | | - return roman.fromRoman(s.upper()) |
1072 | | - |
1073 | | - |
1074 | 1074 | class Body(RSTState): |
1075 | 1075 |
|
1076 | 1076 | """ |
@@ -1098,8 +1098,8 @@ class Body(RSTState): |
1098 | 1098 | enum.converters = {'arabic': int, |
1099 | 1099 | 'loweralpha': _loweralpha_to_int, |
1100 | 1100 | 'upperalpha': _upperalpha_to_int, |
1101 | | - 'lowerroman': _lowerroman_to_int, |
1102 | | - 'upperroman': roman.fromRoman} |
| 1101 | + 'lowerroman': RomanNumeral.from_string, |
| 1102 | + 'upperroman': RomanNumeral.from_string} |
1103 | 1103 |
|
1104 | 1104 | enum.sequenceregexps = {} |
1105 | 1105 | for sequence in enum.sequences: |
@@ -1382,8 +1382,8 @@ def parse_enumerator(self, match, expected_sequence=None): |
1382 | 1382 | ordinal = 1 |
1383 | 1383 | else: |
1384 | 1384 | try: |
1385 | | - ordinal = self.enum.converters[sequence](text) |
1386 | | - except roman.InvalidRomanNumeralError: |
| 1385 | + ordinal = int(self.enum.converters[sequence](text)) |
| 1386 | + except InvalidRomanNumeralError: |
1387 | 1387 | ordinal = None |
1388 | 1388 | return format, sequence, text, ordinal |
1389 | 1389 |
|
@@ -1433,8 +1433,8 @@ def make_enumerator(self, ordinal, sequence, format): |
1433 | 1433 | enumerator = chr(ordinal + ord('a') - 1) |
1434 | 1434 | elif sequence.endswith('roman'): |
1435 | 1435 | try: |
1436 | | - enumerator = roman.toRoman(ordinal) |
1437 | | - except roman.RomanError: |
| 1436 | + enumerator = RomanNumeral(ordinal).to_uppercase() |
| 1437 | + except TypeError: |
1438 | 1438 | return None |
1439 | 1439 | else: # shouldn't happen |
1440 | 1440 | raise ParserError('unknown enumerator sequence: "%s"' |
|
0 commit comments