[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha8-901-gaa6dc21
Jelmer Vernooij
jelmer at samba.org
Tue Sep 22 05:41:26 MDT 2009
Hi Matthias,
I would expect it to be "KeyError". This is easy to verify using Python:
ganieda:~% python
Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ldb
>>> x = ldb.Message()
>>> x["foo"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'No such element'
Cheers,
Jelmer
Matthias Dieter Wallnöfer wrote:
> What exception should I use if an attribute doesn't exist?
>
> Matthias
>
> Jelmer Vernooij schrieb:
>> Hi Matthias,
>>
>> Matthias Dieter Wallnöfer wrote:
>>
>>> +try:
>>> + pwd_props = int(res[0]["pwdProperties"][0])
>>> + pwd_hist_len = int(res[0]["pwdHistoryLength"][0])
>>> + min_pwd_len = int(res[0]["minPwdLength"][0])
>>> + min_pwd_age = int(res[0]["minPwdAge"][0])
>>> + max_pwd_age = int(res[0]["maxPwdAge"][0])
>>> +except:
>>>
>> ^^^ Please don't use "catch-all" exception handling but rather
>> explicitly catch the exception you want to handle (ValueError?).
>> Catch-all exception handling makes it very easy to miss bugs that would
>> otherwise cause an exception.
>>
>>
>>> + if args[0] == "show":
>>> + print "ERROR: Password informations missing in your AD
>>> domain object!"
>>> + print "So no settings can be displayed!"
>>> + sys.exit(1)
>>> + else:
>>> + if pwd_props is None:
>>> + pwd_props = 0
>>> + print "WARNING: Assuming previous password properties 0
>>> (used for password complexity setting)"
>>> +
>>>
More information about the samba-cvs
mailing list