def _errordetails(self, exception_class, default=xmlrpc.XMLRPC.FAILURE): """ Returns an error code for a given exception by looking it up in the sibling module called 'constants' using the uppercased class name as identifier. Example: the exception:: smac.api.errors.UnknownMimetype causes the following lookup:: smac.api.constants.UNKNOWN_MIMETYPE # Error code smac.api.constants.UNKNOWN_MIMETYPE_MSG # Error message A value of default is retuned in no definition is found. """ const_name = text.camelcase_to_uppercase(exception_class.__name__) module_name = exception_class.__module__.replace('ttypes', 'constants') __import__(module_name) errno = getattr(sys.modules[module_name], const_name, default) errmsg = getattr(sys.modules[module_name], const_name + '_MSG', "") return errno, errmsg
def test_camelcase_to_uppercase(self): for key, value in self.VALUES: self.assertEqual(value.upper(), camelcase_to_uppercase(key))