[Python-checkins] python/dist/src/Lib optparse.py,NONE,1.1
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Thu, 14 Nov 2002 14:00:22 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv30642
Added Files:
optparse.py
Log Message:
Checking in Greg Ward's Optik, as optparse.py. This is the most
recent version from Greg's CVS. I've changed the module docstring,
added a copyright notice, and renamed OptikError to OptParseError.
Still to do are documentation and unit tests.
--- NEW FILE: optparse.py ---
"""optparse - a powerful, extensible, and easy-to-use option parser.
By Greg Ward <gward@python.net>
Originally distributed as Optik.
See http://optik.sourceforge.net/
"""
__copyright__ = """
Copyright (c) 2001-2002 Gregory P. Ward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
[...1345 lines suppressed...]
else:
# Isolate all words with s as a prefix.
possibilities = [word for word in wordmap.keys()
if word.startswith(s)]
# No exact match, so there had better be just one possibility.
if len(possibilities) == 1:
return possibilities[0]
elif not possibilities:
raise BadOptionError("no such option: %s" % s)
else:
# More than one possible completion: ambiguous prefix.
raise BadOptionError("ambiguous option: %s (%s?)"
% (s, ", ".join(possibilities)))
# Some day, there might be many Option classes. As of Optik 1.3, the
# preferred way to instantiate Options is indirectly, via make_option(),
# which will become a factory function when there are many Option
# classes.
make_option = Option