Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Generally, you should indicate errors that propagate by using exceptions. If you discover an error by something you just checked and you can deal with it immediately, there is no need to raise an exception. </p> <p>In the particular case of a setter, of example, returning <code>False</code> or anything else won't help. Setting instance variables you have to check is very suboptimal, since then you could miss an error on accident.</p> <p><code>print</code> is not usually a good response to an error. In this case, it sounds like you want to tell the end user they need to use a different password. It sounds like you should call a method that causes the webpage with the form to explain to the user what went wrong; you could call the method that does that in your class or raise an exception that will propagate and eventually be caught and used for that purpose. (This is general advice. I don't know enough about Pylons to tell you how it wants you to do this.)</p> <p>You should not raise your own <code>NameError</code> exceptions. <code>NameError</code> prettymuch always indicates a typo in your program, and as such you usually do not want to catch it. By catching it, you introduce unnecessary uncertainty into a program. This looks like it might be something more like <code>ValueError</code> or a subclass thereof (<code>class InvalidPasswordError(ValueError): pass</code>).</p> <p>I do not understand why you check <code>TypeError</code>. You should always understand what would have caused an exception you caught. If you do in this case, that's great; I can't figure out what error would raise <code>TypeError</code> that you could sanely deal with by prompting the user.</p> <p>Your technique of receiving the password in plaintext and storing its md5 hash is not very secure. You should look into something like AuthKit that could make this process more secure and abstracted.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload