U
    [Sh
                     @   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   G/root/rtd-docs/venv/lib/python3.8/site-packages/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  )Cd   )ZXCZ   )L2   )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   
