'Converts roman numerals up to 39 to integers'

def roman_to_int(self, roman):

    roman_map = [(u'X', 10), (u'IX', 9), (u'V', 5), (u'IV', 4), (u'I', 1)]
    roman = roman.upper()
    for char in roman:
        if (char not in u'XVI'):
            raise ValueError((u'`%s`    is    not    a    valid    roman    numeral' % roman))
    i = result = 0
    for (numeral, integer) in roman_map:
        while (roman[i:(i + len(numeral))] == numeral):
            result += integer
            i += len(numeral)
    return result
