diff options
author | Mark Spruiell <mes@zeroc.com> | 2012-04-24 14:16:15 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2012-04-24 14:16:15 -0700 |
commit | 943a48fc5c0a59b892eb746073c71b8dd88815e7 (patch) | |
tree | 421cfedbc60603d02e0b314d9204e9f85dd781c5 /py/demo/IceStorm/clock/Subscriber.py | |
parent | minor fix to IcePHP getLogger (diff) | |
download | ice-943a48fc5c0a59b892eb746073c71b8dd88815e7.tar.bz2 ice-943a48fc5c0a59b892eb746073c71b8dd88815e7.tar.xz ice-943a48fc5c0a59b892eb746073c71b8dd88815e7.zip |
python 3 support
Diffstat (limited to 'py/demo/IceStorm/clock/Subscriber.py')
-rwxr-xr-x | py/demo/IceStorm/clock/Subscriber.py | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/py/demo/IceStorm/clock/Subscriber.py b/py/demo/IceStorm/clock/Subscriber.py index bc96d09c8e8..f350c0fa7d4 100755 --- a/py/demo/IceStorm/clock/Subscriber.py +++ b/py/demo/IceStorm/clock/Subscriber.py @@ -15,29 +15,29 @@ import Demo class ClockI(Demo.Clock): def tick(self, date, current=None): - print date + print(date) class Subscriber(Ice.Application): def usage(self): - print "Usage: " + self.appName() + \ - " [--batch] [--datagram|--twoway|--ordered|--oneway] [--retryCount count] [--id id] [topic]" + print("Usage: " + self.appName() + \ + " [--batch] [--datagram|--twoway|--ordered|--oneway] [--retryCount count] [--id id] [topic]") def run(self, args): try: opts, args = getopt.getopt(args[1:], '', ['datagram', 'twoway', 'oneway', 'ordered', 'batch', - 'retryCount=', 'id=']) + 'retryCount=', 'id=']) except getopt.GetoptError: self.usage() return 1 - batch = False - option = "None" + batch = False + option = "None" topicName = "time" id = "" retryCount = "" for o, a in opts: - oldoption = option + oldoption = option if o == "--datagram": option = "Datagram" elif o =="--twoway": @@ -45,38 +45,38 @@ class Subscriber(Ice.Application): elif o =="--ordered": option = "Ordered" elif o =="--oneway": - option = "Oneway" + option = "Oneway" elif o =="--batch": batch = True - elif o == "--id": - id = a - elif o == "--retryCount": - retryCount = a - if oldoption != option and oldoption != "None": - self.usage() - return 1 + elif o == "--id": + id = a + elif o == "--retryCount": + retryCount = a + if oldoption != option and oldoption != "None": + self.usage() + return 1 if len(args) > 1: - self.usage() - return 1 + self.usage() + return 1 if len(args) > 0: topicName = args[0] - if len(retryCount) > 0: - if option == "None": - option = "Twoway" - elif option != "Twoway" and option != "Ordered": - print self.appName() + ": retryCount requires a twoway proxy" - return 1 + if len(retryCount) > 0: + if option == "None": + option = "Twoway" + elif option != "Twoway" and option != "Ordered": + print(self.appName() + ": retryCount requires a twoway proxy") + return 1 if batch and (option in ("Twoway", "Ordered")): - print self.appName() + ": batch can only be set with oneway or datagram" + print(self.appName() + ": batch can only be set with oneway or datagram") return 1 manager = IceStorm.TopicManagerPrx.checkedCast(self.communicator().propertyToProxy('TopicManager.Proxy')) if not manager: - print args[0] + ": invalid proxy" + print(args[0] + ": invalid proxy") return 1 # @@ -84,41 +84,41 @@ class Subscriber(Ice.Application): # try: topic = manager.retrieve(topicName) - except IceStorm.NoSuchTopic, e: + except IceStorm.NoSuchTopic as e: try: topic = manager.create(topicName) - except IceStorm.TopicExists, ex: - print self.appName() + ": temporary error. try again" + except IceStorm.TopicExists as ex: + print(self.appName() + ": temporary error. try again") return 1 adapter = self.communicator().createObjectAdapter("Clock.Subscriber") - # - # Add a servant for the Ice object. If --id is used the identity - # comes from the command line, otherwise a UUID is used. - # - # id is not directly altered since it is used below to detect - # whether subscribeAndGetPublisher can raise AlreadySubscribed. - # - - subId = Ice.Identity() - subId.name = id - if len(subId.name) == 0: - subId.name = Ice.generateUUID() + # + # Add a servant for the Ice object. If --id is used the identity + # comes from the command line, otherwise a UUID is used. + # + # id is not directly altered since it is used below to detect + # whether subscribeAndGetPublisher can raise AlreadySubscribed. + # + + subId = Ice.Identity() + subId.name = id + if len(subId.name) == 0: + subId.name = Ice.generateUUID() subscriber = adapter.add(ClockI(), subId) qos = {} - if len(retryCount) > 0: - qos["retryCount"] = retryCount + if len(retryCount) > 0: + qos["retryCount"] = retryCount - # - # Set up the proxy. - # + # + # Set up the proxy. + # if option == "Datagram": - if batch: - subscriber = subscriber.ice_batchDatagram() - else: - subscriber = subscriber.ice_datagram() + if batch: + subscriber = subscriber.ice_batchDatagram() + else: + subscriber = subscriber.ice_datagram() elif option == "Twoway": # Do nothing to the subscriber proxy. Its already twoway. pass @@ -126,18 +126,18 @@ class Subscriber(Ice.Application): # Do nothing to the subscriber proxy. Its already twoway. qos["reliability"] = "ordered" elif option == "Oneway" or option == "None": - if batch: - subscriber = subscriber.ice_batchOneway() - else: - subscriber = subscriber.ice_oneway() - - try: - topic.subscribeAndGetPublisher(qos, subscriber) - except IceStorm.AlreadySubscribed, ex: - # If we're manually setting the subscriber id ignore. - if len(id) == 0: - raise - print "reactivating persistent subscriber" + if batch: + subscriber = subscriber.ice_batchOneway() + else: + subscriber = subscriber.ice_oneway() + + try: + topic.subscribeAndGetPublisher(qos, subscriber) + except IceStorm.AlreadySubscribed as ex: + # If we're manually setting the subscriber id ignore. + if len(id) == 0: + raise + print("reactivating persistent subscriber") adapter.activate() @@ -148,7 +148,7 @@ class Subscriber(Ice.Application): # Unsubscribe all subscribed objects. # topic.unsubscribe(subscriber) - + return 0 app = Subscriber() |