1""" 2:copyright: Copyright since 2006 by Oliver Schoenborn, all rights reserved. 3:license: BSD, see LICENSE_BSD_Simple.txt for details. 4""" 5 6 7 8class TopicNameError(ValueError): 9 """Raised when the topic name is not properly formatted or 10 no corresponding Topic object found. """ 11 def __init__(self, name, msg): 12 ValueError.__init__(self, 'Topic name "%s": %s' % (name, msg)) 13 14 15class TopicDefnError(RuntimeError): 16 """ 17 Raised when an operation requires a topic have an MDS, but it doesn't. 18 See also pub.setTopicUnspecifiedFatal(). 19 """ 20 def __init__(self, topicNameTuple): 21 msg = "No topic specification for topic '%s'." \ 22 % '.'.join(topicNameTuple) 23 RuntimeError.__init__(self, msg + 24 " See pub.addTopicDefnProvider() and/or pub.setTopicUnspecifiedFatal()") 25 26 27class MessageDataSpecError(RuntimeError): 28 """ 29 Raised when an attempt is made to define a topic's Message Data 30 Specification (MDS) to something that is not valid. 31 32 The keyword names for invalid data go in the 'args' list, 33 and the msg should state the problem and contain "%s" for the 34 args, such as MessageDataSpecError('duplicate args %s', ('arg1', 'arg2')). 35 """ 36 37 def __init__(self, msg, args): 38 argsMsg = msg % ','.join(args) 39 RuntimeError.__init__(self, 'Invalid message data spec: ' + argsMsg) 40 41 42class ExcHandlerError(RuntimeError): 43 """ 44 Raised when a listener exception handler (see pub.setListenerExcHandler()) 45 raises an exception. The original exception is contained. 46 """ 47 48 def __init__(self, badExcListenerID, topicObj, origExc=None): 49 """The badExcListenerID is the name of the listener that raised 50 the original exception that handler was attempting to handle. 51 The topicObj is the Topic object for the topic of the 52 sendMessage that had an exception raised. 53 The origExc is currently not used. """ 54 self.badExcListenerID = badExcListenerID 55 import traceback 56 self.exc = traceback.format_exc() 57 msg = 'The exception handler registered with pubsub raised an ' \ 58 + 'exception, *while* handling an exception raised by listener ' \ 59 + ' "%s" of topic "%s"):\n%s' \ 60 % (self.badExcListenerID, topicObj.getName(), self.exc) 61 RuntimeError.__init__(self, msg) 62 63 64class UnrecognizedSourceFormatError(ValueError): 65 """ 66 Raised when a topic definition provider doesn't recognize the format 67 of source input it was given. 68 """ 69 def __init__(self): 70 ValueError.__init__(self, 'Source format not recognized') 71 72 73