Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-plivo committed May 18, 2011
1 parent 6d8e0e4 commit 903b332
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/plivo/rest/freeswitch/grammar.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class GetDigits(Grammar):
invalidDigitsSound: Sound played when invalid digit pressed invalidDigitsSound: Sound played when invalid digit pressed
""" """
DEFAULT_MAX_DIGITS = 99 DEFAULT_MAX_DIGITS = 99
DEFAULT_TIMEOUT = 5


def __init__(self): def __init__(self):
Grammar.__init__(self) Grammar.__init__(self)
Expand All @@ -369,25 +370,34 @@ def parse_grammar(self, element, uri=None):
num_digits = int(self.extract_attribute_value("numDigits")) num_digits = int(self.extract_attribute_value("numDigits"))
if num_digits > self.DEFAULT_MAX_DIGITS: if num_digits > self.DEFAULT_MAX_DIGITS:
num_digits = self.DEFAULT_MAX_DIGITS num_digits = self.DEFAULT_MAX_DIGITS
timeout = int(self.extract_attribute_value("timeout")) if num_digits < 1:
raise RESTFormatException("GetDigits 'numDigits' must be greater than 0")
try:
timeout = int(self.extract_attribute_value("timeout"))
except ValueError:
timeout = self.DEFAULT_TIMEOUT * 1000
if timeout < 0:
raise RESTFormatException("GetDigits 'timeout' must be a positive integer")

finish_on_key = self.extract_attribute_value("finishOnKey") finish_on_key = self.extract_attribute_value("finishOnKey")
play_beep = self.extract_attribute_value("playBeep") play_beep = self.extract_attribute_value("playBeep")
self.invalid_digits_sound = \ self.invalid_digits_sound = \
self.extract_attribute_value("invalidDigitsSound") self.extract_attribute_value("invalidDigitsSound")
self.valid_digits = self.extract_attribute_value("validDigits") self.valid_digits = self.extract_attribute_value("validDigits")
action = self.extract_attribute_value("action") action = self.extract_attribute_value("action")
retries = int(self.extract_attribute_value("retries"))
try:
retries = int(self.extract_attribute_value("retries"))
except ValueError:
retries = 1
if retries < 0:
raise RESTFormatException("GetDigits 'retries' must be greater than 0")

method = self.extract_attribute_value("method") method = self.extract_attribute_value("method")
if method != 'GET' and method != 'POST': if method != 'GET' and method != 'POST':
raise RESTAttributeException("Method, must be 'GET' or 'POST'") raise RESTAttributeException("Method, must be 'GET' or 'POST'")
self.method = method self.method = method


if num_digits < 1:
raise RESTFormatException("GetDigits 'numDigits' must be greater than 1")
if retries < 0:
raise RESTFormatException("GetDigits 'retries' must be greater than 0")
if timeout < 0:
raise RESTFormatException("GetDigits 'timeout' must be a positive integer")
if play_beep == 'true': if play_beep == 'true':
self.play_beep = True self.play_beep = True
else: else:
Expand All @@ -397,7 +407,7 @@ def parse_grammar(self, element, uri=None):
else: else:
self.action = uri self.action = uri
self.num_digits = num_digits self.num_digits = num_digits
self.timeout = (timeout * 1000) self.timeout = timeout * 1000
self.finish_on_key = finish_on_key self.finish_on_key = finish_on_key
self.retries = retries self.retries = retries


Expand Down

0 comments on commit 903b332

Please sign in to comment.