diff options
author | Guido van Rossum <guido@python.org> | 2000-10-03 17:11:37 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-10-03 17:11:37 (GMT) |
commit | f19a7ac220178bbe6bfdf88561dea355392aec24 (patch) | |
tree | 40c378ecb4fc165518e8012b02438a1df6f6e014 | |
parent | 12e1595e2820a1f6651cbd2cf938ce31d9e3ea84 (diff) | |
download | cpython-f19a7ac220178bbe6bfdf88561dea355392aec24.zip cpython-f19a7ac220178bbe6bfdf88561dea355392aec24.tar.gz cpython-f19a7ac220178bbe6bfdf88561dea355392aec24.tar.bz2 |
Fix a few problems with the _Printer class and the license variable.
1. repr(license) will no longer print to stdout and read from stdin;
you have to use license(). `license` is a short message explaining
this.
2. Use lazy initialization so that startup isn't slowed down by the
search for the LICENSE file.
3. repr(license) actually returns the desired string, rather than
printing to stdout and returning ''. (Why didn't we think of this
before?)
4. Use the pythonlabs license URL as the license fallback instead of
the CNRI license handle.
-rw-r--r-- | Lib/site.py | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/Lib/site.py b/Lib/site.py index c92e98d..dc1b614 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -145,11 +145,43 @@ del exit class _Printer: MAXLINES = 23 - def __init__(self, s): - self.__lines = s.split('\n') + def __init__(self, name, data, files=(), dirs=()): + self.__name = name + self.__data = data + self.__files = files + self.__dirs = dirs + self.__lines = None + + def __setup(self): + if self.__lines: + return + data = None + for dir in self.__dirs: + for file in self.__files: + file = os.path.join(dir, file) + try: + fp = open(file) + data = fp.read() + fp.close() + break + except IOError: + pass + if data: + break + if not data: + data = self.__data + self.__lines = data.split('\n') self.__linecnt = len(self.__lines) def __repr__(self): + self.__setup() + if len(self.__lines) <= self.MAXLINES: + return "\n".join(self.__lines) + else: + return "Type %s() to see the full %s text" % ((self.__name,)*2) + + def __call__(self): + self.__setup() prompt = 'Hit Return for more, or q (and Return) to quit: ' lineno = 0 while 1: @@ -167,29 +199,15 @@ class _Printer: key = None if key == 'q': break - return '' - -__builtin__.copyright = _Printer(sys.copyright) -__builtin__.credits = _Printer( - '''Python development is led by BeOpen PythonLabs (www.pythonlabs.com).''') - -def make_license(filename): - try: - return _Printer(open(filename).read()) - except IOError: - return None +__builtin__.copyright = _Printer("copyright", sys.copyright) +__builtin__.credits = _Printer("credits", + "Python development is led by BeOpen PythonLabs (www.pythonlabs.com).") here = os.path.dirname(os.__file__) -for dir in here, os.path.join(here, os.pardir), os.curdir: - for file in "LICENSE.txt", "LICENSE": - lic = make_license(os.path.join(dir, file)) - if lic: - break - if lic: - __builtin__.license = lic - break -else: - __builtin__.license = _Printer('See http://hdl.handle.net/1895.22/1012') +__builtin__.license = _Printer( + "license", "See http://www.pythonlabs.com/products/python2.0/license.html", + ["LICENSE.txt", "LICENSE"], + [here, os.path.join(here, os.pardir), os.curdir]) # Set the string encoding used by the Unicode implementation. The |