[csw-devel] [PATCH] Add support for reading password from a file by default

Ben Walton bwalton at opencsw.org
Fri Apr 22 13:47:32 CEST 2011


Excerpts from Maciej Bliziński's message of Fri Apr 22 02:03:34 -0400 2011:
> 2011/4/22 Ben Walton <bwalton at opencsw.org>:
> > +  try:
> > +    af = open(authfile, 'r')
> > +    password = af.readline().rstrip()
> 
> Try using the 'with' syntax:
> 
> try:
>   with open(authfile, 'r') as af:
>     password = af...

Ah, ok.  This forces the close() which is only implicit with the end
of the script as it stands.  WIll do.

> To get the password, you can:
> 
> password = af.read() # reads the whole file
> 
> and with stripping:
> 
> password = af.read().strip()
> 
> (strips ws from both sides)

Do we want that though?  It shouldn't hurt, but it also shouldn't be
necessary.  I'm only looking for strip()-like functionality to mimick
chomp() from perl/ruby.

> > +  except:
> 
> Add an exception class, I suppose it'll be an IOError; let other
> exceptions propagate.  Add a warning that the file couldn't be found
> (logging.warning(...)).

Ok, I wasn't sure what the best thing to catch was.  I thought that
catching everything around this small block was the way to go.

Update pending.

Thanks
-Ben

--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302



More information about the devel mailing list