Skip to content

Commit c2fc9b0

Browse files
fix
1 parent 697b89c commit c2fc9b0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

sipay/amount.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from sipay.catalogs.currency import CURRENCIES
33
import re
44

5+
THOUSAND_SEPARATORS = (',', ' ', '\'', '.', '')
6+
DECIMAL_SEPARATORS = (',', '.')
7+
58

69
class Amount:
710
"""Amount class."""
@@ -13,15 +16,13 @@ def __init__(self, amount, currency, separator='', decimal_separator='.'):
1316
self.decimal_separator = decimal_separator
1417

1518
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 [ ,\'.].')
1922

2023
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 [,.]')
2526

2627
if decimal_separator == separator:
2728
raise TypeError('separators are equals.')

0 commit comments

Comments
 (0)