[Python-checkins] CVS: python/dist/src/Lib site.py,1.19,1.20

Guido van Rossum python-dev@python.org
Tue, 3 Oct 2000 10:11:40 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv22509

Modified Files:
	site.py 
Log Message:
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.


Index: site.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/site.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** site.py	2000/09/28 16:52:36	1.19
--- site.py	2000/10/03 17:11:37	1.20
***************
*** 146,154 ****
      MAXLINES = 23
  
!     def __init__(self, s):
!         self.__lines = s.split('\n')
          self.__linecnt = len(self.__lines)
  
      def __repr__(self):
          prompt = 'Hit Return for more, or q (and Return) to quit: '
          lineno = 0
--- 146,186 ----
      MAXLINES = 23
  
!     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
***************
*** 168,194 ****
                  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
  
  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')
  
  
--- 200,212 ----
                  if key == 'q':
                      break
  
+ __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__)
! __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])