Skip to content

Commit acb204e

Browse files
authored
Used compiled RegEx (#95)
1 parent b8e93d3 commit acb204e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

laterpay/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
_logger = logging.getLogger(__name__)
2626

27+
_PRICING_RE = re.compile(r'[A-Z]{3}\d+')
28+
_EXPIRY_RE = re.compile(r'^(\+?\d+)$')
29+
2730

2831
class InvalidTokenException(Exception):
2932
"""
@@ -62,10 +65,10 @@ class ItemDefinition(object):
6265
def __init__(self, item_id, pricing, url, title, expiry=None):
6366

6467
for price in pricing.split(','):
65-
if not re.match('[A-Z]{3}\d+', price):
68+
if not _PRICING_RE.match(price):
6669
raise InvalidItemDefinition('Pricing is not valid: %s' % pricing)
6770

68-
if expiry is not None and not re.match('^(\+?\d+)$', expiry):
71+
if expiry is not None and not _EXPIRY_RE.match(expiry):
6972
raise InvalidItemDefinition("Invalid expiry value %s, it should be '+3600' or UTC-based "
7073
"epoch timestamp in seconds of type int" % expiry)
7174

0 commit comments

Comments
 (0)