
    "*_P                     *   d dl mZ 	 dZdZdZdZd dlZd dlZd dlZd dl	Z	 G d de
      Z G d	 d
e      Z G d de      Z G d de      ZdZd Z ej"                  dej$                        Zd Zd Zd Zedk(  r e	j0                   e              yy)    )print_functionz&Mark Pilgrim (f8dy@diveintopython.org)z1.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 Zd Zy)
RomanErrorN__name__
__module____qualname__     '/usr/lib/python3/dist-packages/roman.pyr   r          r   r   c                       e Zd Zy)OutOfRangeErrorNr   r
   r   r   r   r      r   r   r   c                       e Zd Zy)NotIntegerErrorNr   r
   r   r   r   r   #   r   r   r   c                       e Zd Zy)InvalidRomanNumeralErrorNr   r
   r   r   r   r   '   r   r   r   ))Mi  )CMi  )Di  )CDi  )Cd   )XCZ   )L2   )XL(   )X
   )IX	   )V   )IV   )I   c                     t        | t              st        d      d| cxk  rdk  st        d       t        d      | dk(  ryd}t        D ]  \  }}| |k\  s||z  }| |z  } | |k\  r |S )z convert integer to Roman numeralzdecimals can not be convertedi  z%number out of range (must be 0..4999)r   N )
isinstanceintr   r   romanNumeralMap)nresultnumeralintegers       r   toRomanr5   ;   s    a=>>MTMEFF EFF 	AvF+ 7lgFLA 7l 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                    | st        d      | dk(  ryt        j                  |       st        d| z        d}d}t        D ]B  \  }}| ||t	        |      z    |k(  s||z  }|t	        |      z  }| ||t	        |      z    |k(  r(D |S )z convert Roman numeral to integerzInput can not be blankr,   r   zInvalid Roman numeral: %s)r   romanNumeralPatternsearchr0   len)sr2   indexr3   r4   s        r   	fromRomanr<   \   s    &'?@@ 	Cx%%a(&'BQ'FGGFE+ "ec'l*+w6gFS\!E ec'l*+w6" Mr   c                      t        j                  dd      } | j                  dd       | j                  ddd	d
d       | j                         }|j                  |_        |S )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defaultrB   )argparseArgumentParseradd_argument
parse_argsrA   )parserargss     r   rI   rI   q   sp    $$?F '=>
kK	  M D++DKKr   c                  $   t               } | j                  r@| j                  j                         }t	        |      }t        |       t        j                  S t        | j                        }t        |      }t        |       t        j                  S )N)
rI   reverserA   upperr<   printr/   r5   osEX_OK)rK   urir1   s        r   mainrU      sf    <D||KKaLa 88O	 AJa88Or   __main__)
__future__r   
__author____version____date____copyright__rF   rP   resys	Exceptionr   r   r   r   r0   r5   compileVERBOSEr7   r<   rI   rU   r   exitr
   r   r   <module>rb      s    % )5
	  	 	 
	 		j 		j 		z 	
( !bjj 
" 

 *" zCHHTV r   