commit 7aeed0474852384a0b2bb6e3c70220eafe201226 Author: Florian Best Date: Sat Nov 29 00:02:44 2014 +0100 Bug #30089: remove get_exception_msg in UCS@school diff --git a/ucs-school-4.0/ucs-school-umc-users/umc/python/schoolusers/__init__.py b/ucs-school-4.0/ucs-school-umc-users/umc/python/schoolusers/__init__.py index 789ca70..ac605fe 100644 --- a/ucs-school-4.0/ucs-school-umc-users/umc/python/schoolusers/__init__.py +++ b/ucs-school-4.0/ucs-school-umc-users/umc/python/schoolusers/__init__.py @@ -48,15 +48,6 @@ import notifier.popen _ = Translation( 'ucs-school-umc-schoolusers' ).translate -## FIXME: remove in UCS@school 3.2, replace by str(e): Bug #27940, 30089, 30088 -def get_exception_msg(e): - msg = getattr(e, 'message', '') - if e.args: - if e.args[0] != msg or len(e.args) != 1: - for arg in e.args: - msg += ' %s' % (arg) - return msg - class Instance( SchoolBaseModule ): @LDAP_Connection() def query( self, request, ldap_user_read = None, ldap_position = None, search_base = None ): @@ -108,7 +99,7 @@ class Instance( SchoolBaseModule ): MODULE.process( '_reset_passwords: dn=%s' % ur.dn ) MODULE.process( '_reset_passwords: exception=%s' % str( e.__class__ ) ) MODULE.process( '_reset_passwords: exception=%s' % str( e.message ) ) - return '%s' % (get_exception_msg(e)) + return '%s' % (e,) @LDAP_Connection( USER_READ, USER_WRITE ) def password_reset( self, request, ldap_user_read = None, ldap_user_write = None, ldap_position = None, search_base = None ): diff --git a/ucs-school-4.0/ucs-school-umc-wizards/umc/python/schoolwizards/__init__.py b/ucs-school-4.0/ucs-school-umc-wizards/umc/python/schoolwizards/__init__.py index be9fdbf..9afffeb 100644 --- a/ucs-school-4.0/ucs-school-umc-wizards/umc/python/schoolwizards/__init__.py +++ b/ucs-school-4.0/ucs-school-umc-wizards/umc/python/schoolwizards/__init__.py @@ -52,15 +52,6 @@ _ = Translation('ucs-school-umc-wizards').translate ucr = ConfigRegistry() ucr.load() -# TODO: remove once this is implemented in uexceptions, see Bug #30088 -def get_exception_msg(e): - msg = getattr(e, 'message', '') - if getattr(e, 'args', False): - if e.args[0] != msg or len(e.args) != 1: - for arg in e.args: - msg += ' ' + arg - return msg - def get_user_class(user_type): if user_type == 'student': return Student @@ -198,7 +189,7 @@ class Instance(SchoolBaseModule, SchoolImport): else: ret.append({'result' : {'message' : _('"%s" already exists!') % obj.name}}) except uldapBaseException as exc: - ret.append({'result' : {'message' : get_exception_msg(exc)}}) + ret.append({'result' : {'message' : str(exc)}}) return ret @LDAP_Connection( USER_READ, USER_WRITE ) @@ -218,7 +209,7 @@ class Instance(SchoolBaseModule, SchoolImport): try: obj.modify(ldap_user_write, validate=False) except uldapBaseException as exc: - ret.append({'result' : {'message' : get_exception_msg(exc)}}) + ret.append({'result' : {'message' : str(exc)}}) else: ret.append(True) # no changes? who cares? return ret commit 1a2510fed9bde85b6618181076d95e83ad42d325 Author: Florian Best Date: Fri Nov 28 23:59:10 2014 +0100 Bug #30088: move get_exception_msg() logic into base.__str__ diff --git a/ucs-4.0-0/management/univention-directory-manager-modules/modules/univention/admin/uexceptions.py b/ucs-4.0-0/management/univention-directory-manager-modules/modules/univention/admin/uexceptions.py index 00ac387..7be574c 100644 --- a/ucs-4.0-0/management/univention-directory-manager-modules/modules/univention/admin/uexceptions.py +++ b/ucs-4.0-0/management/univention-directory-manager-modules/modules/univention/admin/uexceptions.py @@ -30,7 +30,6 @@ # /usr/share/common-licenses/AGPL-3; if not, see # . -import exceptions import univention.admin.localization from univention.admin import configRegistry @@ -38,8 +37,17 @@ translation=univention.admin.localization.translation('univention/admin') _=translation.translate -class base(exceptions.Exception): - pass +class base(Exception): + message = '' + + def __str__(self): + msg = self.message + for arg in self.args: + if arg != self.message: + if isinstance(arg, unicode): + arg = arg.encode('utf-8') + msg = '%s %s' % (msg, arg) + return msg class objectExists(base): message=_('Object exists.') diff --git a/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py b/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py index 879d3a6..78d93d3 100644 --- a/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py +++ b/ucs-4.0-0/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py @@ -69,15 +69,6 @@ udm_modules.update() _user_dn = None _password = None - -def get_exception_msg(e): - msg = getattr(e, 'message', '') - if getattr(e, 'args', False): - if e.args[0] != msg or len(e.args) != 1: - for arg in e.args: - msg += ' ' + arg - return msg - def set_credentials( dn, passwd ): global _user_dn, _password _user_dn = dn @@ -382,7 +373,7 @@ class UDM_Module( object ): obj.create() except udm_errors.base, e: MODULE.warn( 'Failed to create LDAP object: %s: %s' % ( e.__class__.__name__, str( e ) ) ) - raise UDM_Error( get_exception_msg(e), obj.dn ) + raise UDM_Error('%s' % (e,), obj.dn ) return obj.dn @@ -401,7 +392,7 @@ class UDM_Module( object ): return dest except udm_errors.base, e: MODULE.warn( 'Failed to move LDAP object %s: %s: %s' % ( ldap_dn, e.__class__.__name__, str( e ) ) ) - raise UDM_Error( get_exception_msg( e ) ) + raise UDM_Error('%s' % (e,)) @LDAP_Connection def remove( self, ldap_dn, cleanup = False, recursive = False, ldap_connection = None, ldap_position = None ): @@ -416,7 +407,7 @@ class UDM_Module( object ): udm_objects.performCleanup( obj ) except udm_errors.base, e: MODULE.warn( 'Failed to remove LDAP object %s: %s: %s' % ( ldap_dn, e.__class__.__name__, str( e ) ) ) - raise UDM_Error( get_exception_msg( e ) ) + raise UDM_Error('%s' % (e,)) @LDAP_Connection def modify( self, ldap_object, ldap_connection = None, ldap_position = None ): @@ -442,7 +433,7 @@ class UDM_Module( object ): obj.modify() except udm_errors.base, e: MODULE.warn( 'Failed to modify LDAP object %s: %s: %s' % ( obj.dn, e.__class__.__name__, str( e ) ) ) - raise UDM_Error( get_exception_msg(e) ) + raise UDM_Error('%s' % (e,) ) @LDAP_Connection def search( self, container = None, attribute = None, value = None, superordinate = None, scope = 'sub', filter = '', simple = False, simple_attrs = None, ldap_connection = None, ldap_position = None, hidden=True ): @@ -479,7 +470,7 @@ class UDM_Module( object ): except ( LDAPError, udm_errors.ldapError ), e: raise e except udm_errors.base, e: - raise UDM_Error( get_exception_msg( e ) ) + raise UDM_Error('%s' % (e,)) # call the garbage collector manually as many parallel request may cause the # process to use too much memory @@ -504,7 +495,7 @@ class UDM_Module( object ): raise e except Exception, e: MODULE.info( 'Failed to retrieve LDAP object: %s' % str( e ) ) - raise UDM_Error( get_exception_msg( e ) ) + raise UDM_Error('%s' % (e,)) return obj def get_property( self, property_name ): @@ -1047,7 +1038,7 @@ def list_objects( container, object_type = None, ldap_connection = None, ldap_po except ( LDAPError, udm_errors.ldapError ), e: raise e except udm_errors.base, e: - raise UDM_Error( get_exception_msg( e ) ) + raise UDM_Error('%s' % (e,)) objects = [] for dn, attrs in result: modules = udm_modules.objectType( None, ldap_connection, dn, attrs ) commit c3771f7036f0449601cc1cfe5339b2177d6b19a5 Author: Florian Best Date: Fri Nov 28 23:28:26 2014 +0100 Bug #35273: fix exception raising diff --git a/ucs-4.0-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py b/ucs-4.0-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py index ebff70a..ae50c21 100644 --- a/ucs-4.0-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py +++ b/ucs-4.0-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/__init__.py @@ -1830,8 +1830,8 @@ class simpleComputer( simpleLdap ): ( 'zoneName', univention.admin.uldap.explodeDn( zoneDn, 1 )[ 0 ]),\ ( 'aAAARecord', [ ip ]),\ ( 'relativeDomainName', [ name ])]) - except univention.admin.uexceptions.objectExists, dn: - raise univention.admin.uexceptions.dnsAliasRecordExists, dn + except univention.admin.uexceptions.objectExists as exc: + raise univention.admin.uexceptions.dnsAliasRecordExists(str(exc)) # TODO: check if zoneDn really a forwardZone, maybe it is a container under a zone zone = univention.admin.handlers.dns.forward_zone.object( self.co, self.lo, self.position, zoneDn ) zone.open() @@ -1856,8 +1856,8 @@ class simpleComputer( simpleLdap ): ( 'zoneName', univention.admin.uldap.explodeDn( zoneDn, 1 )[ 0 ]),\ ( 'ARecord', [ ip ]),\ ( 'relativeDomainName', [ name ])]) - except univention.admin.uexceptions.objectExists, dn: - raise univention.admin.uexceptions.dnsAliasRecordExists, dn + except univention.admin.uexceptions.objectExists as exc: + raise univention.admin.uexceptions.dnsAliasRecordExists(str(exc)) # TODO: check if zoneDn really a forwardZone, maybe it is a container under a zone zone = univention.admin.handlers.dns.forward_zone.object( self.co, self.lo, self.position, zoneDn ) zone.open()