B
    ç<[
  ã               @   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   ú3lib/python3.7/site-packages/docutils/utils/roman.pyr      s    r   c               @   s   e Zd ZdS )ÚOutOfRangeErrorN)r   r   r   r   r   r   r   r      s    r   c               @   s   e Zd ZdS )ÚNotIntegerErrorN)r   r   r   r   r   r   r   r	      s    r	   c               @   s   e Zd ZdS )ÚInvalidRomanNumeralErrorN)r   r   r   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   sj   d|   k rdk sn t dƒ‚t| ƒ| kr2tdƒ‚d}x.tD ]&\}}x| |kr`||7 }| |8 } qFW q<W |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   sr   | st dƒ‚t | ¡s"t d|  ƒ‚d}d}xBtD ]:\}}x0| ||t|ƒ … |krh||7 }|t|ƒ7 }q:W q0W |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   Ú	fromRomanC   s    
r(   )Ú__doc__Ú
__author__Ú__version__Z__date__Z__copyright__ÚreÚ	Exceptionr   r   r	   r
   r   r"   ÚcompileÚVERBOSEr#   r(   r   r   r   r   Ú<module>   s   


