Dc㱈 d Z dZdZdZdZddlZ G d de Z G d d
e Z G d de Z G d
de Z
dZd Z ej
dej Zd ZdS )z"Convert to and from Roman numeralsz&Mark Pilgrim (f8dy@diveintopython.org)z1.4z
8 August 2001ag Copyright (c) 2001 Mark Pilgrim
This program is part of "Dive Into Python", a free Python tutorial for
experienced programmers. Visit http://diveintopython.org/ for the
latest version.
This program is free software; you can redistribute it and/or modify
it under the terms of the Python 2.1.1 license, available at
http://www.python.org/2.1.1/license.html
Nc e Zd ZdS )
RomanErrorN__name__
__module____qualname__ t/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib/python3.11/site-packages/docutils/utils/roman.pyr r r
r c e Zd ZdS )OutOfRangeErrorNr r r
r r r r r
r c e Zd ZdS )NotIntegerErrorNr r r
r r r r r
r c e Zd ZdS )InvalidRomanNumeralErrorNr r r
r r r r r
r )
)Mi )CMi )Di )CDi )Cd )XCZ )L2 )XL( )X
)IX )V )IV )I c d| cxk rdk sn t d t | | k rt d d}t D ]\ }}| |k r||z
}| |z } | |k |S )z convert integer to Roman numeralr i z%number out of range (must be 1..4999)zdecimals can not be converted )r intr romanNumeralMap)nresultnumeralintegers r toRomanr1 + s
LLLLDLLLLEFFF
1vv{{=>>>
F+ 7llgF
LA 7ll Mr
a8
^ # beginning of string
M{0,4} # thousands - 0 to 4 M's
(CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's),
# or 500-800 (D, followed by 0 to 3 C's)
(XC|XL|L?X{0,3}) # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 X's),
# or 50-80 (L, followed by 0 to 3 X's)
(IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's),
# or 5-8 (V, followed by 0 to 3 I's)
$ # end of string
c H | st d t | st d| z d}d}t D ]X\ }}| ||t | z |k r5||z
}|t | z
}| ||t | z |k 5Y|S )z convert Roman numeral to integerzInput can not be blankzInvalid Roman numeral: %sr )r romanNumeralPatternsearchr, len)sr. indexr/ r0 s r fromRomanr8 H s A&'?@@@%%a(( H&'BQ'FGGG
F
E+ " "eCLL(()W44gFS\\!E eCLL(()W44 Mr
)__doc__
__author____version____date__
__copyright__re Exceptionr r r r r, r1 compileVERBOSEr3 r8 r r
r