Revision 6396164f lib/compat.py
b/lib/compat.py | ||
---|---|---|
30 | 30 |
except ImportError: |
31 | 31 |
functools = None |
32 | 32 |
|
33 |
try: |
|
34 |
import roman |
|
35 |
except ImportError: |
|
36 |
roman = None |
|
37 |
|
|
33 | 38 |
|
34 | 39 |
def all(seq, pred=bool): # pylint: disable-msg=W0622 |
35 | 40 |
"""Returns True if pred(x) is True for every element in the iterable. |
... | ... | |
82 | 87 |
return newfunc |
83 | 88 |
|
84 | 89 |
|
90 |
def TryToRoman(val, convert=True): |
|
91 |
"""Try to convert a value to roman numerals |
|
92 |
|
|
93 |
If the roman module could be loaded convert the given value to a roman |
|
94 |
numeral. Gracefully fail back to leaving the value untouched. |
|
95 |
|
|
96 |
@type val: integer |
|
97 |
@param val: value to convert |
|
98 |
@type convert: boolean |
|
99 |
@param convert: if False, don't try conversion at all |
|
100 |
@rtype: string or typeof(val) |
|
101 |
@return: roman numeral for val, or val if conversion didn't succeed |
|
102 |
|
|
103 |
""" |
|
104 |
if roman is not None and convert: |
|
105 |
try: |
|
106 |
return roman.toRoman(val) |
|
107 |
except roman.RomanError: |
|
108 |
return val |
|
109 |
else: |
|
110 |
return val |
|
111 |
|
|
112 |
|
|
85 | 113 |
if functools is None: |
86 | 114 |
partial = _partial |
87 | 115 |
else: |
Also available in: Unified diff