
    )i                     V   S r SrSrSSKrSSKrSSKr " S S\5      r " S S\5      r " S	 S
\5      r	 " S S\5      r
SrS\S\4S jr\R                  " S\R                   5      rSS\S\S\4S jjrS\R(                  4S jrS\4S jr\S:X  a  \R0                  " \" 5       5        gg)z"Convert to and from Roman numeralsz&Mark Pilgrim (f8dy@diveintopython.org)zCopyright (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.
    Nc                       \ rS rSrSrg)
RomanError    N__name__
__module____qualname____firstlineno____static_attributes__r       N/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/roman/__init__.pyr   r          r   r   c                       \ rS rSrSrg)OutOfRangeError"   r   Nr   r   r   r   r   r   "   r   r   r   c                       \ rS rSrSrg)NotIntegerError&   r   Nr   r   r   r   r   r   &   r   r   r   c                       \ rS rSrSrg)InvalidRomanNumeralError*   r   Nr   r   r   r   r   r   *   r   r   r   ))Mi  )CMi  )Di  )CDi  )Cd   )XCZ   )L2   )XL(   )X
   )IX	   )V   )IV   )I   nreturnc                     [        U [        5      (       d  [        S5      eSU s=:  a  S:  d  O  [        S5      eU S:X  a  gSn[         H  u  p#X:  d  M  X-  nX-  n X:  a  M  M     U$ )z convert integer to Roman numeralzdecimals cannot be convertedi  z%number out of range (must be 0..4999)r   N )
isinstanceintr   r   romanNumeralMap)r/   resultnumeralintegers       r   toRomanr;   >   sr    a<==MTMEFF 	AvF+lFLA l , 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
    sspecial_casec                 X   U (       d  [        S5      eU R                  5       n U S:X  a  U(       a  g[        R                  U 5      (       d  [        SU -  5      eSnSn[         HC  u  pEXU[        U5      -    U:X  d  M  X%-  nU[        U5      -  nXU[        U5      -    U:X  a  M(  ME     U$ )a_  
Convert Roman numeral to integer.

Parameters:
    s (str): The Roman numeral string to convert.
    special_case (bool, optional): If True (default),
        interprets 'N' as 0 for the special case of zero.

Returns:
    int: The integer value of the Roman numeral.

Raises:
    InvalidRomanNumeralError: If the input is not a valid Roman numeral.
zInput cannot be blankr3   r   zInvalid Roman numeral: %s)r   upperromanNumeralPatternsearchr7   len)r<   r=   r8   indexr9   r:   s         r   	fromRomanrD   _   s      &'>??		A 	CxL%%a((&'BQ'FGGFE+ec'l*+w6FS\!E ec'l*+w6 , Mr   c                      [         R                  " SSS9n U R                  SSS9  U R                  SSS	S
SS9  U R                  5       nUR                  Ul        U$ )Nromanz)convert between roman and arabic numerals)progdescriptionnumberzthe value to convert)helpz-rz	--reverse
store_trueFz<convert roman to numeral (case insensitive) [default: False])actiondefaultrJ   )argparseArgumentParseradd_argument
parse_argsrI   )parserargss     r   rQ   rQ      sp    $$?F '=>
kK	  M D++DKKr   c                      [        5       n U R                  (       a!  [        U R                  5      n[	        U5        g[        U R                  5      n[        U5      n[	        U5        g)Nr   )rQ   reverserD   rI   printr6   r;   )rS   rir/   s       r   mainrY      sM    <D||dkk"a 	 AJar   __main__)T)__doc__
__author____copyright__rN   resys	Exceptionr   r   r   r   r7   r6   strr;   compileVERBOSEr@   boolrD   	NamespacerQ   rY   r   exitr   r   r   <module>rg      s    )5
  	 
	 		j 		j 		z 	
s s ( jj 
" 

 " "D "C "JH&& "
c 
 zHHTV r   