[Python-checkins] cpython: Improve example for crypt module. No string exceptions..

eric.araujo python-checkins at python.org
Sun May 29 18:14:27 CEST 2011


http://hg.python.org/cpython/rev/a4fcdeefa185
changeset:   70489:a4fcdeefa185
user:        Éric Araujo <merwok at netwok.org>
date:        Sun May 29 03:24:45 2011 +0200
summary:
  Improve example for crypt module.  No string exceptions..

files:
  Doc/library/crypt.rst |  12 +++++++-----
  1 files changed, 7 insertions(+), 5 deletions(-)


diff --git a/Doc/library/crypt.rst b/Doc/library/crypt.rst
--- a/Doc/library/crypt.rst
+++ b/Doc/library/crypt.rst
@@ -131,18 +131,20 @@
 
 A simple example illustrating typical use::
 
-   import crypt, getpass, pwd
+   import pwd
+   import crypt
+   import getpass
 
    def login():
-       username = input('Python login:')
+       username = input('Python login: ')
        cryptedpasswd = pwd.getpwnam(username)[1]
        if cryptedpasswd:
            if cryptedpasswd == 'x' or cryptedpasswd == '*':
-               raise "Sorry, currently no support for shadow passwords"
+               raise ValueError('no support for shadow passwords')
            cleartext = getpass.getpass()
            return crypt.crypt(cleartext, cryptedpasswd) == cryptedpasswd
        else:
-           return 1
+           return True
 
 To generate a hash of a password using the strongest available method and
 check it against the original::
@@ -151,4 +153,4 @@
 
    hashed = crypt.crypt(plaintext)
    if hashed != crypt.crypt(plaintext, hashed):
-      raise "Hashed version doesn't validate against original"
+      raise ValueError("hashed version doesn't validate against original")

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list