U 3_ @sdZdZdZdZdZddlZGdddeZGd d d eZGd d d eZ Gd ddeZ dZ ddZ e dejZddZdS)z"Convert to and from Roman numeralsz&Mark Pilgrim (f8dy@diveintopython.org)z1.4z 8 August 2001agCopyright (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@s eZdZdS) RomanErrorN__name__ __module__ __qualname__rro/private/var/folders/2d/2jcwkxfx4hj39rq32sgz27wh9m_5lk/T/pip-target-wqqlibfd/lib/python/docutils/utils/roman.pyrsrc@s eZdZdS)OutOfRangeErrorNrrrrrr sr c@s eZdZdS)NotIntegerErrorNrrrrrr sr c@s eZdZdS)InvalidRomanNumeralErrorNrrrrrr sr ) )Mi)ZCMi)Di)ZCDi)Cd)ZXCZ)L2)ZXL()X )ZIX )V)ZIV)IcCsbd|krdksntdt||kr2tdd}tD]"\}}||kr:||7}||8}qBq:|S)z convert integer to Roman numeralriz%number out of range (must be 1..4999)zdecimals can not be converted)r intr romanNumeralMap)nresultnumeralintegerrrrtoRoman(s   r#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 cCsj|s tdt|s"td|d}d}tD]6\}}|||t||kr.||7}|t|7}q6q.|S)z convert Roman numeral to integerzInput can not be blankzInvalid Roman numeral: %sr)r romanNumeralPatternsearchrlen)sr indexr!r"rrr fromRomanCs   r))__doc__ __author__ __version____date__ __copyright__re Exceptionrr r r rr#compileVERBOSEr$r)rrrrs