U
    O’“e‡
  ã                   @   s‚   d Z dZdZdZdZddlZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZ	G dd„ deƒZ
dZdd„ Ze dej¡Zdd„ ZdS )z"Convert to and from Roman numeralsz&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                   @   s   e Zd ZdS )Ú
RomanErrorN©Ú__name__Ú
__module__Ú__qualname__© r   r   ú8/tmp/pip-unpacked-wheel-rro3auwd/docutils/utils/roman.pyr      s    r   c                   @   s   e Zd ZdS )ÚOutOfRangeErrorNr   r   r   r   r   r	      s    r	   c                   @   s   e Zd ZdS )ÚNotIntegerErrorNr   r   r   r   r   r
      s    r
   c                   @   s   e Zd ZdS )ÚInvalidRomanNumeralErrorNr   r   r   r   r   r      s    r   ))ÚMiè  )ZCMi„  )ÚDiô  )ZCDi  )ÚCéd   )ZXCéZ   )ÚLé2   )ZXLé(   )ÚXé
   )ZIXé	   )ÚVé   )ZIVé   )ÚIé   c                 C   sb   d|   k rdk sn t dƒ‚t| ƒ| kr2tdƒ‚d}tD ]"\}}| |kr:||7 }| |8 } qBq:|S )z convert integer to Roman numeralr   iˆ  z%number out of range (must be 1..4999)zdecimals can not be convertedÚ )r	   Úintr
   ÚromanNumeralMap)ÚnÚresultÚnumeralÚintegerr   r   r   ÚtoRoman+   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
    c                 C   sj   | st dƒ‚t | ¡s"t d|  ƒ‚d}d}tD ]6\}}| ||t|ƒ … |kr.||7 }|t|ƒ7 }q6q.|S )z convert Roman numeral to integerzInput can not be blankzInvalid Roman numeral: %sr   )r   ÚromanNumeralPatternÚsearchr   Úlen)Úsr    Úindexr!   r"   r   r   r   Ú	fromRomanH   s    
r)   )Ú__doc__Ú
__author__Ú__version__Ú__date__Ú__copyright__ÚreÚ	Exceptionr   r	   r
   r   r   r#   ÚcompileÚVERBOSEr$   r)   r   r   r   r   Ú<module>   s   
ö