2
2
from sipay .catalogs .currency import CURRENCIES
3
3
import re
4
4
5
+ THOUSAND_SEPARATORS = (',' , ' ' , '\' ' , '.' , '' )
6
+ DECIMAL_SEPARATORS = (',' , '.' )
7
+
5
8
6
9
class Amount :
7
10
"""Amount class."""
@@ -13,15 +16,13 @@ def __init__(self, amount, currency, separator='', decimal_separator='.'):
13
16
self .decimal_separator = decimal_separator
14
17
15
18
if isinstance (amount , str ):
16
- if not isinstance (separator , str ) or len ( separator ) >= 2 or \
17
- re . match ( r'[0-9]' , separator ) :
18
- raise TypeError ('separator must be a string with length 0,1 .' )
19
+ if not isinstance (separator , str ) or \
20
+ separator not in THOUSAND_SEPARATORS :
21
+ raise TypeError ('separator must be [ , \' .] .' )
19
22
20
23
if not isinstance (decimal_separator , str ) or \
21
- len (decimal_separator ) != 1 or \
22
- re .match (r'[0-9]' , decimal_separator ):
23
- raise TypeError ('decimal_separator must be a string with '
24
- 'length 1.' )
24
+ decimal_separator not in DECIMAL_SEPARATORS :
25
+ raise TypeError ('decimal_separator must be [,.]' )
25
26
26
27
if decimal_separator == separator :
27
28
raise TypeError ('separators are equals.' )
0 commit comments