From a4c34000a83a0cccd6d74a1fd719777b8ee445cb Mon Sep 17 00:00:00 2001 From: stroeder Date: Fri, 5 Jun 2015 20:55:05 +0000 Subject: [PATCH] Abandoned old syntax when raising ValueError in module ldif and more information in some exceptions. --- CHANGES | 6 +++++- Lib/ldif.py | 18 +++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGES b/CHANGES index f9366df..0a004b5 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,10 @@ Changes since 2.4.19: * New wrapping of OpenLDAP's function ldap_sasl_bind_s() allows to intercept the SASL handshake (thanks to René Kijewski) +Lib/ +* Abandoned old syntax when raising ValueError in module ldif and + some more information in exceptions. + ---------------------------------------------------------------- Released 2.4.19 2015-01-10 @@ -1152,4 +1156,4 @@ Released 2.0.0pre02 2002-02-01 ---------------------------------------------------------------- Released 1.10alpha3 2000-09-19 -$Id: CHANGES,v 1.339 2015/05/02 16:19:23 stroeder Exp $ +$Id: CHANGES,v 1.340 2015/06/05 20:55:05 stroeder Exp $ diff --git a/Lib/ldif.py b/Lib/ldif.py index 012e908..9ea1139 100644 --- a/Lib/ldif.py +++ b/Lib/ldif.py @@ -3,7 +3,7 @@ See http://www.python-ldap.org/ for details. -$Id: ldif.py,v 1.78 2015/01/10 17:18:13 stroeder Exp $ +$Id: ldif.py,v 1.79 2015/06/05 20:55:06 stroeder Exp $ Python compability note: Tested with Python 2.0+, but should work with Python 1.5.2+. @@ -165,7 +165,7 @@ def _unparseChangeRecord(self,modlist): elif mod_len==3: changetype = 'modify' else: - raise ValueError,"modlist item of wrong length" + raise ValueError("modlist item of wrong length: %d" % (mod_len)) self._unparseAttrTypeandValue('changetype',changetype) for mod in modlist: if mod_len==2: @@ -174,7 +174,7 @@ def _unparseChangeRecord(self,modlist): mod_op,mod_type,mod_vals = mod self._unparseAttrTypeandValue(MOD_OP_STR[mod_op],mod_type) else: - raise ValueError,"Subsequent modlist item of wrong length" + raise ValueError("Subsequent modlist item of wrong length") if mod_vals: for mod_val in mod_vals: self._unparseAttrTypeandValue(mod_type,mod_val) @@ -197,7 +197,7 @@ def unparse(self,dn,record): elif isinstance(record,types.ListType): self._unparseChangeRecord(record) else: - raise ValueError, "Argument record must be dictionary or list" + raise ValueError('Argument record must be dictionary or list instead of %s' % (repr(record))) # Write empty line separating the records self._output_file.write(self._line_sep) # Count records written @@ -354,20 +354,20 @@ def parse(self): if attr_type=='dn': # attr type and value pair was DN of LDIF record if dn!=None: - raise ValueError, 'Two lines starting with dn: in one record.' + raise ValueError('Two lines starting with dn: in one record.') if not is_dn(attr_value): - raise ValueError, 'No valid string-representation of distinguished name %s.' % (repr(attr_value)) + raise ValueError('No valid string-representation of distinguished name %s.' % (repr(attr_value))) dn = attr_value elif attr_type=='version' and dn is None: version = 1 elif attr_type=='changetype': # attr type and value pair was DN of LDIF record if dn is None: - raise ValueError, 'Read changetype: before getting valid dn: line.' + raise ValueError('Read changetype: before getting valid dn: line.') if changetype!=None: - raise ValueError, 'Two lines starting with changetype: in one record.' + raise ValueError('Two lines starting with changetype: in one record.') if not valid_changetype_dict.has_key(attr_value): - raise ValueError, 'changetype value %s is invalid.' % (repr(attr_value)) + raise ValueError('changetype value %s is invalid.' % (repr(attr_value))) changetype = attr_value elif attr_value!=None and \ not self._ignored_attr_types.has_key(attr_type.lower()):