diff --git a/README.md b/README.md index 8728177..bdd3270 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,7 @@ as "say". In some cases, you'll want to build a class object directly such as in ## Note on Python versions -This module is for python 2.x and requires python 2.5 or higher. -There is a separate version available for python 3.x at: - - http://github.com/tropo/python-webapi/tree/python3 +This module is for Python 3 and 2.5 or higher. ## License diff --git a/build/lib/tropo.py b/build/lib/tropo.py index 6f5e748..d13420a 100644 --- a/build/lib/tropo.py +++ b/build/lib/tropo.py @@ -31,6 +31,8 @@ """ +from __future__ import print_function + try: import cjson as jsonlib jsonlib.dumps = jsonlib.encode diff --git a/samples/gh-12-test_voice.py b/samples/gh-12-test_voice.py index 54b3d9f..0123921 100644 --- a/samples/gh-12-test_voice.py +++ b/samples/gh-12-test_voice.py @@ -8,6 +8,8 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function + from itty import * from tropo import Tropo, Session, TropoAction, Choices @@ -35,7 +37,7 @@ def index(request): json = t.RenderJson() - print json + print(json) return json diff --git a/samples/gh-14.test_call.py b/samples/gh-14.test_call.py index 12d82c9..7b1d255 100644 --- a/samples/gh-14.test_call.py +++ b/samples/gh-14.test_call.py @@ -9,6 +9,8 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function + from itty import * from tropo import Tropo, Session @@ -23,7 +25,7 @@ def index(request): t.call(to='tel:+' + TO_NUMBER, _from='tel:+' + FROM_NUMBER) t.say('This is your mother. Did you brush your teeth today?') json = t.RenderJson() - print json + print(json) return json diff --git a/samples/gh-14.test_message.py b/samples/gh-14.test_message.py index ad24a18..f1570cc 100644 --- a/samples/gh-14.test_message.py +++ b/samples/gh-14.test_message.py @@ -9,6 +9,8 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function + from itty import * from tropo import Tropo, Session @@ -20,9 +22,9 @@ def index(request): t = Tropo() t.message("Hello World", TO_NUMBER, channel='VOICE', _from='tel:+' + FROM_NUMBER) - json = t.RenderJson() - print json - return json + json = t.RenderJson() + print(json) + return json #retest diff --git a/samples/gh-14.test_say.py b/samples/gh-14.test_say.py index 019c02d..41e05f7 100644 --- a/samples/gh-14.test_say.py +++ b/samples/gh-14.test_say.py @@ -8,6 +8,8 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function + from itty import * from tropo import Tropo, Session @@ -17,7 +19,7 @@ def index(request): t = Tropo() t.say('12345', _as='DIGITS', voice='dave') json = t.RenderJson() - print json + print(json) return json diff --git a/samples/gh-14.test_transfer.py b/samples/gh-14.test_transfer.py index a033ad9..2e5cfef 100644 --- a/samples/gh-14.test_transfer.py +++ b/samples/gh-14.test_transfer.py @@ -10,6 +10,8 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function + from itty import * from tropo import Tropo, Session @@ -25,7 +27,7 @@ def index(request): t.transfer(TO_NUMBER, _from="tel:+" + FROM_NUMBER) t.say("Hi. I am a robot") json = t.RenderJson() - print json + print(json) return json diff --git a/samples/gh-14_test.py b/samples/gh-14_test.py index e24822d..e7cca0a 100644 --- a/samples/gh-14_test.py +++ b/samples/gh-14_test.py @@ -5,6 +5,8 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function + from itty import * from tropo import Tropo, Session @@ -14,7 +16,7 @@ def index(request): t = Tropo() t.say('12345', _as='DIGITS', voice='allison') json = t.RenderJson() - print json + print(json) return json run_itty() diff --git a/samples/gh-17.test.py b/samples/gh-17.test.py index 9c9f1ad..8cef269 100644 --- a/samples/gh-17.test.py +++ b/samples/gh-17.test.py @@ -1,3 +1,5 @@ +from __future__ import print_function + from itty import * from tropo import Tropo, Result @@ -11,7 +13,7 @@ def index(request): t.on(event = "continue", next ="/continue") t.on(event = "incomplete", next ="/incomplete") json = t.RenderJson() - print json + print(json) return json @post("/continue") @@ -29,7 +31,7 @@ def index(request): t.say("What are you waiting for?") json = t.RenderJson() - print json + print(json) return json @post("/incomplete") @@ -37,7 +39,7 @@ def index(request): t = Tropo() t.say("Sorry, that wasn't on of the options.") json = t.RenderJson() - print json + print(json) return json run_itty() diff --git a/samples/gh-20-test_ask.py b/samples/gh-20-test_ask.py index 4a44d08..44822d0 100644 --- a/samples/gh-20-test_ask.py +++ b/samples/gh-20-test_ask.py @@ -6,6 +6,8 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function + from itty import * from tropo import Tropo, Session, Result @@ -19,16 +21,16 @@ def index(request): t.on(event = "continue", next ="/continue") - json = t.RenderJson() + json = t.RenderJson() - print json + print(json) return json @post("/continue") def index(request): r = Result(request.body) - print "Result : %s" % r + print("Result : %s" % r) t = Tropo() @@ -37,8 +39,8 @@ def index(request): t.say("You said " + answer + ", which is a " + value) - json = t.RenderJson() - print json + json = t.RenderJson() + print(json) return json run_itty() diff --git a/samples/gh-21.choices.py b/samples/gh-21.choices.py index dbd795c..9c2c0a6 100644 --- a/samples/gh-21.choices.py +++ b/samples/gh-21.choices.py @@ -11,6 +11,8 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function + from itty import * from tropo import Tropo, Session, Result, Choices @@ -20,21 +22,21 @@ def index(request): t = Tropo() - choices = Choices("[4-5 DIGITS]", mode="dtmf", terminator = "#") + choices = Choices("[4-5 DIGITS]", mode="dtmf", terminator = "#") t.ask(choices, timeout=15, name="digit", say = "What's your four or five digit pin? Press pound when finished.") t.on(event = "continue", next ="/continue") - json = t.RenderJson() + json = t.RenderJson() - print json + print(json) return json @post("/continue") def index(request): r = Result(request.body) - print "Result : %s" % r + print("Result : %s" % r) # dump(r) t = Tropo() @@ -43,8 +45,8 @@ def index(request): t.say("You said ") t.say (answer, _as="DIGITS") - json = t.RenderJson() - print json + json = t.RenderJson() + print(json) return json run_itty() diff --git a/samples/gh-22.transfer.py b/samples/gh-22.transfer.py index 87aa97a..4a782e3 100644 --- a/samples/gh-22.transfer.py +++ b/samples/gh-22.transfer.py @@ -9,6 +9,7 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function from itty import * from tropo-webapi-python/tropo import Tropo, Session @@ -30,7 +31,7 @@ def index(request): t.transfer(TO_NUMBER, headers={"x-callername":"Kevin Bond"}) json = t.RenderJson() - print json + print(json) return json diff --git a/samples/gh-23.ask_timeout.py b/samples/gh-23.ask_timeout.py index fc48ba4..8eb75a1 100644 --- a/samples/gh-23.ask_timeout.py +++ b/samples/gh-23.ask_timeout.py @@ -1,6 +1,7 @@ # tests example clarifying gh-23 . How to use timeout, and nomatch parameters # in "say" within "ask" +from __future__ import print_function from itty import * from tropo import Tropo, Session, Result @@ -25,7 +26,7 @@ def index (request): ]) json = t.RenderJson() - print json + print(json) return json @@ -67,7 +68,7 @@ def index_straight_json (request): } """ - print json + print(json) return json diff --git a/samples/gh-5.hello_cgi.py b/samples/gh-5.hello_cgi.py index 57a7ece..816d1df 100644 --- a/samples/gh-5.hello_cgi.py +++ b/samples/gh-5.hello_cgi.py @@ -16,6 +16,8 @@ # 3. Place this file in examples folder and chmod it executable # 4. Dial up Tropo app, and hear "Hello, World ..." +from __future__ import print_function + import cgi from tropo import Tropo @@ -23,14 +25,14 @@ def hello(): t = Tropo() t.say(['hello world! I am a C G I script.']) json = t.RenderJson() - print json + print(json) return json -print "Content-type: text/json" -print -print +print("Content-type: text/json") +print() +print() hello() diff --git a/samples/itty_hello_world.py b/samples/itty_hello_world.py index 7d1f55f..eaed80b 100755 --- a/samples/itty_hello_world.py +++ b/samples/itty_hello_world.py @@ -3,6 +3,8 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function + from itty import * from tropo import Tropo, Session diff --git a/samples/itty_session_api.py b/samples/itty_session_api.py index 4b48603..8c25a4b 100755 --- a/samples/itty_session_api.py +++ b/samples/itty_session_api.py @@ -9,6 +9,8 @@ # Sample application using the itty-bitty python web framework from: # http://github.com/toastdriven/itty +from __future__ import print_function + from itty import * from tropo import Tropo, Session from urllib import urlencode diff --git a/samples/record_test.py b/samples/record_test.py index f5f4513..e695d00 100644 --- a/samples/record_test.py +++ b/samples/record_test.py @@ -1,3 +1,5 @@ +from __future__ import print_function + from itty import * from tropo import Tropo, Session, Result @@ -11,4 +13,4 @@ def index(request): return t.RenderJson() -run_itty(server='wsgiref', port=8888) \ No newline at end of file +run_itty(server='wsgiref', port=8888) diff --git a/test/test.py b/test/test.py index 37ad766..e3d92bc 100755 --- a/test/test.py +++ b/test/test.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function try: import cjson as jsonlib @@ -40,12 +41,12 @@ def test_ask(self): say = Say("Please enter a 5 digit zip code").json) rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_ask=================" - print "render json: %s" % pretty_rendered + print("===============test_ask=================") + print("render json: %s" % pretty_rendered) rendered_obj = jsonlib.loads(rendered) wanted_json = '{"tropo": [{"ask": {"say": {"value": "Please enter a 5 digit zip code"}, "choices": {"value": "[5 digits]"}}}]}' wanted_obj = jsonlib.loads(wanted_json) - # print "test_ask: %s" % tropo.RenderJson() + # print("test_ask: %s" % tropo.RenderJson()) self.assertEqual(rendered_obj, wanted_obj) def test_call(self): @@ -58,13 +59,13 @@ def test_call(self): tropo.say ("Wish you were here") rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print ("============test_call=============") - print "render json: %s" % pretty_rendered + print("============test_call=============") + print("render json: %s" % pretty_rendered) rendered_obj = jsonlib.loads(rendered) wanted_json = '{"tropo": [{"call": {"to": "%s", "network": "SMS", "channel": "TEXT"}}, {"say": {"value": "Wish you were here"}}]}' % self.MY_PHONE wanted_obj = jsonlib.loads(wanted_json) - # print "test_call: %s" % tropo.RenderJson() + # print("test_call: %s" % tropo.RenderJson()) self.assertEqual(rendered_obj, wanted_obj) def test_conference(self): @@ -77,14 +78,14 @@ def test_conference(self): name="Staff Meeting") rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_conference=================" - print "render json: %s" % pretty_rendered + print("===============test_conference=================") + print("render json: %s" % pretty_rendered) rendered_obj = jsonlib.loads(rendered) wanted_json = '{"tropo": [{"conference": {"playTones": true, "mute": false, "name": "Staff Meeting", "id": "foo"}}]}' - print "wanted_json: %s" % wanted_json + print("wanted_json: %s" % wanted_json) wanted_obj = jsonlib.loads(wanted_json) - # print "test_conference: %s" % tropo.RenderJson() + # print("test_conference: %s" % tropo.RenderJson()) self.assertEqual(rendered_obj, wanted_obj) def test_hangup(self): @@ -96,10 +97,10 @@ def test_hangup(self): tropo.hangup() rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_hangup=================" - print "render json: %s" % pretty_rendered + print("===============test_hangup=================") + print("render json: %s" % pretty_rendered) - # print "test_hangup: %s" % tropo.RenderJson() + # print("test_hangup: %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = '{"tropo": [{"hangup": {}}]}' wanted_obj = jsonlib.loads(wanted_json) @@ -114,10 +115,10 @@ def test_message(self): tropo.message("Hello World", self.MY_PHONE, channel='TEXT', network='SMS', timeout=5) rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_message=================" - print "render json: %s" % pretty_rendered + print("===============test_message=================") + print("render json: %s" % pretty_rendered) - # print "test_message: %s" % tropo.RenderJson() + # print("test_message: %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = ' {"tropo": [{"message": {"to": "%s", "say": {"value": "Hello World"}, "network": "SMS", "timeout": 5, "channel": "TEXT"}}]}' % self.MY_PHONE wanted_obj = jsonlib.loads(wanted_json) @@ -135,10 +136,10 @@ def test_on(self): say="Please hold.") rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_on=================" - print "render json: %s" % pretty_rendered + print("===============test_on=================") + print("render json: %s" % pretty_rendered) - # print "test_on: %s" % tropo.RenderJson() + # print("test_on: %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = ' {"tropo": [{"on": {"say": {"value": "Please hold."}, "event": "continue", "next": "/weather.py?uri=end"}}]}' wanted_obj = jsonlib.loads(wanted_json) @@ -156,10 +157,10 @@ def test_record(self): choices=choices_obj) rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_record=================" - print "render json: %s" % pretty_rendered + print("===============test_record=================") + print("render json: %s" % pretty_rendered) - # print "test_record: %s" % tropo.RenderJson() + # print("test_record: %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = ' {"tropo": [{"record": {"url": "/receive_recording.py", "say": {"value": "Tell us about yourself"}, "choices": {"terminator": "#", "value": ""}}}]}' wanted_obj = jsonlib.loads(wanted_json) @@ -174,14 +175,14 @@ def test_redirect(self): tropo.redirect(self.MY_PHONE) rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_redirect=================" - print "render json: %s" % pretty_rendered + print("===============test_redirect=================") + print("render json: %s" % pretty_rendered) - print "Wanted_Json %s" % tropo.RenderJson() + print("Wanted_Json %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = '{"tropo": [{"redirect": {"to": "%s"}}]}' % self.MY_PHONE wanted_obj = jsonlib.loads(wanted_json) - # print "test_redirect: %s" % tropo.RenderJson() + # print("test_redirect: %s" % tropo.RenderJson()) self.assertEqual(rendered_obj, wanted_obj) def test_reject(self): @@ -193,14 +194,14 @@ def test_reject(self): tropo.reject() rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_reject=================" - print "render json: %s" % pretty_rendered + print("===============test_reject=================") + print("render json: %s" % pretty_rendered) - print "Want %s" % tropo.RenderJson() + print("Want %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = '{"tropo": [{"reject": {}}]}' wanted_obj = jsonlib.loads(wanted_json) - # print "test_reject: %s" % tropo.RenderJson() + # print("test_reject: %s" % tropo.RenderJson()) self.assertEqual(rendered_obj, wanted_obj) def test_say(self): @@ -212,10 +213,10 @@ def test_say(self): tropo.say("Hello, World") rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_say=================" - print "render json: %s" % pretty_rendered + print("===============test_say=================") + print("render json: %s" % pretty_rendered) - # print "test_say: %s" % tropo.RenderJson() + # print("test_say: %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = '{"tropo": [{"say": {"value": "Hello, World"}}]}' wanted_obj = jsonlib.loads(wanted_json) @@ -230,10 +231,10 @@ def test_list_say(self): tropo.say(["Hello, World", "How ya doing?"]) rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_list_say=================" - print "render json: %s" % pretty_rendered + print("===============test_list_say=================") + print("render json: %s" % pretty_rendered) - # print "test_say: %s" % tropo.RenderJson() + # print("test_say: %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = '{"tropo": [{"say": [{"value": "Hello, World"}, {"value": "How ya doing?"}]}]}' wanted_obj = jsonlib.loads(wanted_json) @@ -248,10 +249,10 @@ def test_startRecording(self): tropo.startRecording(self.RECORDING_URL) rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_startRecording=================" - print "render json: %s" % pretty_rendered + print("===============test_startRecording=================") + print("render json: %s" % pretty_rendered) - # print "test_startRecording: %s" % tropo.RenderJson() + # print("test_startRecording: %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = '{"tropo": [{"startRecording": {"url": "/receive_recording.py"}}]}' wanted_obj = jsonlib.loads(wanted_json) @@ -266,10 +267,10 @@ def test_stopRecording(self): tropo.stopRecording() rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_stopRecording=================" - print "render json: %s" % pretty_rendered + print("===============test_stopRecording=================") + print("render json: %s" % pretty_rendered) - # print "test_stopRecording: %s" % tropo.RenderJson() + # print("test_stopRecording: %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = ' {"tropo": [{"stopRecording": {}}]}' wanted_obj = jsonlib.loads(wanted_json) @@ -286,10 +287,10 @@ def test_transfer(self): tropo.say("Hi. I am a robot") rendered = tropo.RenderJson() pretty_rendered = tropo.RenderJson(pretty=True) - print "===============test_transfer=================" - print "render json: %s" % pretty_rendered + print("===============test_transfer=================") + print("render json: %s" % pretty_rendered) - # print "test_transfer: %s" % tropo.RenderJson() + # print("test_transfer: %s" % tropo.RenderJson()) rendered_obj = jsonlib.loads(rendered) wanted_json = '{"tropo": [{"say": {"value": "One moment please."}}, {"transfer": {"to": "6021234567"}}, {"say": {"value": "Hi. I am a robot"}}]}' wanted_obj = jsonlib.loads(wanted_json) diff --git a/test/test1.py b/test/test1.py index f484cad..44af001 100644 --- a/test/test1.py +++ b/test/test1.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys sys.path = ['..'] + sys.path from tropo import Choices, MachineDetection, JoinPrompt, LeavePrompt, On, Ask, Say, Tropo diff --git a/test/tropoTestMachineDetection.py b/test/tropoTestMachineDetection.py index db647d4..99cc1e2 100644 --- a/test/tropoTestMachineDetection.py +++ b/test/tropoTestMachineDetection.py @@ -1,3 +1,5 @@ +from __future__ import print_function + from itty import * from tropo import Tropo, Result, MachineDetection @@ -25,4 +27,4 @@ def index(request): return t.RenderJson() -run_itty(server='wsgiref', host='0.0.0.0', port=8888) \ No newline at end of file +run_itty(server='wsgiref', host='0.0.0.0', port=8888) diff --git a/tropo.py b/tropo.py index 6f5e748..1f13d8b 100644 --- a/tropo.py +++ b/tropo.py @@ -31,6 +31,8 @@ """ +from __future__ import print_function + try: import cjson as jsonlib jsonlib.dumps = jsonlib.encode @@ -44,6 +46,18 @@ except ImportError: import json as jsonlib + +import sys + +if sys.version_info < (3,): + # In Python 2, we are loosey-goosey with whether we're dealing with + # bytestrings or unicode. + stringish = basestring +else: + # In Python 3, we require unicode as the deities intended. + stringish = str + + class TropoAction(object): """ Class representing the base Tropo action. @@ -72,18 +86,18 @@ class Ask(TropoAction): "allowSignals": String or Array, "bargein": Boolean, "choices": Object, #Required - "interdigitTimeout": Float, - "minConfidence": Integer, + "interdigitTimeout": Float, + "minConfidence": Integer, "name": String, "recognizer": String, "required": Boolean, "say": Object, - "sensitivity": Float, - "speechCompleteTimeout": Float, + "sensitivity": Float, + "speechCompleteTimeout": Float, "speechIncompleteTimeout": Float, "timeout": Float, "voice": String, - + } } """ @@ -92,14 +106,14 @@ class Ask(TropoAction): def __init__(self, choices, **options): self._dict = {} - if (isinstance(choices, basestring)): + if (isinstance(choices, stringish)): self._dict['choices'] = Choices(choices).json else: # self._dict['choices'] = choices['choices'] self._dict['choices'] = choices.json for opt in self.options_array: if opt in options: - if ((opt == 'say') and (isinstance(options['say'], basestring))): + if ((opt == 'say') and (isinstance(options['say'], stringish))): self._dict['say'] = Say(options['say']).json else: self._dict[opt] = options[opt] @@ -139,7 +153,7 @@ def __init__(self, to, **options): else: self._dict[opt] = options[opt] - + class Choices(TropoAction): """ @@ -312,30 +326,30 @@ def __init__(self, event, **options): self._dict = {} for opt in self.options_array: if opt in options: - if ((opt == 'say') and (isinstance(options['say'], basestring))): + if ((opt == 'say') and (isinstance(options['say'], stringish))): if('voice' in options): self._dict['say'] = Say(options['say'], voice=options['voice']).json else: self._dict['say'] = Say(options['say']).json - - elif ((opt == 'ask') and (isinstance(options['ask'], basestring))): + + elif ((opt == 'ask') and (isinstance(options['ask'], stringish))): if('voice' in options): self._dict['ask'] = Ask(options['ask'], voice=options['voice']).json else: self._dict['ask'] = Ask(options['ask']).json - - elif ((opt == 'message') and (isinstance(options['message'], basestring))): + + elif ((opt == 'message') and (isinstance(options['message'], stringish))): if('voice' in options): self._dict['message'] = Message(options['message'], voice=options['voice']).json else: self._dict['message'] = Message(options['message']).json - - elif ((opt == 'wait') and (isinstance(options['wait'], basestring))): + + elif ((opt == 'wait') and (isinstance(options['wait'], stringish))): self._dict['wait'] = Wait(options['wait']).json - + elif(opt != 'voice'): self._dict[opt] = options[opt] - + self._dict['event'] = event class Record(TropoAction): @@ -365,7 +379,7 @@ class Record(TropoAction): "say": Object, "timeout": Float, "transcription": Array or Object, - "url": String, #Required + "url": String, #Required "username": String, "voice": String} } """ @@ -375,7 +389,7 @@ def __init__(self, url, **options): self._dict = {'url': url} for opt in self.options_array: if opt in options: - if ((opt == 'say') and (isinstance(options['say'], basestring))): + if ((opt == 'say') and (isinstance(options['say'], stringish))): self._dict['say'] = Say(options['say']).json else: self._dict[opt] = options[opt] @@ -482,7 +496,7 @@ class StartRecording(TropoAction): "method": String, "url": String,#Required "username": String, - "password": String, + "password": String, "transcriptionID": String "transcriptionEmailFormat":String "transcriptionOutURI": String} } @@ -544,7 +558,7 @@ def __init__(self, to, **options): if opt in options: if opt == "on": whisper = [] - for key, val in options['on'].iteritems(): + for key, val in options['on'].items(): newDict = {} if(key == "ask"): @@ -562,7 +576,7 @@ def __init__(self, to, **options): elif(key == "message"): newDict['message'] = val newDict['event'] = 'connect' - + elif(key == "ring"): newDict['say'] = val newDict['event'] = 'ring' @@ -589,7 +603,7 @@ class Wait(TropoAction): "milliseconds": Integer,#Required "allowSignals": String or Array """ - + action = 'wait' options_array = ['allowSignals'] @@ -670,7 +684,7 @@ class Session(object): """ Session is the payload sent as an HTTP POST to your web application when a new session arrives. (See https://www.tropo.com/docs/webapi/session) - + Because 'from' is a reserved word in Python, the session object's 'from' property is called fromaddress in the Python library """ @@ -683,7 +697,7 @@ def __init__(self, session_json): setattr(self, "fromaddress", val) else: setattr(self, key, val) - setattr(self, 'dict', session_dict) + setattr(self, 'dict', session_dict) class Tropo(object): @@ -716,12 +730,12 @@ def ask(self, choices, **options): # # **Sun May 15 21:21:29 2011** -- egilchri # Settng the voice in this method call has priority. - # Otherwise, we can pick up the voice from the Tropo object, - # if it is set there. + # Otherwise, we can pick up the voice from the Tropo object, + # if it is set there. if hasattr (self, 'voice'): if (not 'voice' in options): options['voice'] = self.voice - + # # **Sun May 15 21:21:29 2011** -- egilchri self._steps.append(Ask(choices, **options).obj) @@ -761,7 +775,7 @@ def message (self, say_obj, to, **options): Argument: **options is a set of optional keyword arguments. See https://www.tropo.com/docs/webapi/message """ - if isinstance(say_obj, basestring): + if isinstance(say_obj, stringish): say = Say(say_obj).obj else: say = say_obj @@ -818,8 +832,8 @@ def say(self, message, **options): # # **Sun May 15 21:21:29 2011** -- egilchri # Settng the voice in this method call has priority. - # Otherwise, we can pick up the voice from the Tropo object, - # if it is set there. + # Otherwise, we can pick up the voice from the Tropo object, + # if it is set there. if hasattr (self, 'voice'): if (not 'voice' in options): options['voice'] = self.voice @@ -851,7 +865,7 @@ def transfer(self, to, **options): See https://www.tropo.com/docs/webapi/transfer """ self._steps.append(Transfer(to, **options).obj) - + def wait(self, milliseconds, **options): """ Allows the thread to sleep for a given amount of time in milliseconds @@ -860,7 +874,7 @@ def wait(self, milliseconds, **options): See https://www.tropo.com/docs/webapi/wait """ self._steps.append(Wait(milliseconds, **options).obj) - + def RenderJson(self, pretty=False): """ Render a Tropo object into a Json string. @@ -878,16 +892,15 @@ def RenderJson(self, pretty=False): return json if __name__ == '__main__': - print """ + print(""" This is the Python web API for http://www.tropo.com/ To run the test suite, please run: cd test - python test.py - - -""" + python2 test.py + python3 test.py +""")