added __all__ lists to a number of Python modules

added test script and expected output file as well
this closes patch 103297.
__all__ attributes will be added to other modules without first submitting
a patch, just adding the necessary line to the test script to verify
more-or-less correct implementation.
This commit is contained in:
Skip Montanaro 2001-01-20 19:54:20 +00:00
parent c955f89225
commit e99d5ea25b
39 changed files with 138 additions and 0 deletions

View file

@ -63,6 +63,7 @@
__version__ = "0.2"
__all__ = ["HTTPServer", "BaseHTTPRequestHandler"]
import sys
import time

View file

@ -26,6 +26,7 @@
"""
__all__ = ["BastionClass", "Bastion"]
from types import MethodType

View file

@ -19,6 +19,7 @@
__version__ = "0.4"
__all__ = ["CGIHTTPRequestHandler"]
import os
import sys

View file

@ -89,6 +89,11 @@
import string
import re
__all__ = ["NoSectionError","DuplicateSectionError","NoOptionError",
"InterpolationError","InterpolationDepthError","ParsingError",
"MissingSectionHeaderError","ConfigParser",
"MAX_INTERPOLATION_DEPTH"]
DEFAULTSECT = "DEFAULT"
MAX_INTERPOLATION_DEPTH = 10

View file

@ -228,6 +228,8 @@
except ImportError:
raise ImportError, "Cookie.py requires 're' from Python 1.5 or later"
__all__ = ["CookieError","BaseCookie","SimpleCookie","SerialCookie",
"SmartCookie","Cookie"]
#
# Define an exception visible to External modules

View file

@ -10,6 +10,7 @@
import string
import mimetools
__all__ = ["MimeWriter"]
class MimeWriter:

View file

@ -1,5 +1,7 @@
"""A multi-producer, multi-consumer queue."""
__all__ = ["Queue","Empty","Full"]
class Empty(Exception):
"Exception raised by Queue.get(block=0)/get_nowait()."
pass

View file

@ -8,6 +8,7 @@
__version__ = "0.6"
__all__ = ["SimpleHTTPRequestHandler"]
import os
import string

View file

@ -127,6 +127,13 @@ class will essentially render the service "deaf" while one request is
import sys
import os
__all__ = ["TCPServer","UDPServer","ForkingUDPServer","ForkingTCPServer",
"ThreadingUDPServer","ThreadingTCPServer","BaseRequestHandler",
"StreamRequestHandler","DatagramRequestHandler"]
if hasattr(socket, "AF_UNIX"):
__all__.extend(["UnixStreamServer","UnixDatagramServer",
"ThreadingUnixStreamServer",
"ThreadingUnixDatagramServer"])
class BaseServer:

View file

@ -34,6 +34,8 @@
except ImportError:
EINVAL = 22
__all__ = ["StringIO"]
EMPTYSTRING = ''
class StringIO:

View file

@ -1,5 +1,7 @@
"""A more or less complete user-defined wrapper around dictionary objects."""
__all__ = ["UserDict"]
class UserDict:
def __init__(self, dict=None):
self.data = {}

View file

@ -1,5 +1,7 @@
"""A more or less complete user-defined wrapper around list objects."""
__all__ = ["UserList"]
class UserList:
def __init__(self, initlist=None):
self.data = []

View file

@ -8,6 +8,8 @@
from types import StringType, UnicodeType
import sys
__all__ = ["UserString","MutableString"]
class UserString:
def __init__(self, seq):
if isinstance(seq, StringType) or isinstance(seq, UnicodeType):

View file

@ -137,6 +137,8 @@
import struct
import __builtin__
__all__ = ["Error","open","openfp"]
class Error(Exception):
pass

View file

@ -42,6 +42,8 @@
"""
__all__ = ["error","open"]
try:
class error(Exception):
pass

View file

@ -5,6 +5,8 @@
One public function, register, is defined.
"""
__all__ = ["register"]
_exithandlers = []
def _run_exitfuncs():
"""run any registered exit functions

View file

@ -1,5 +1,7 @@
"""Classes for manipulating audio devices (currently only for Sun and SGI)"""
__all__ = ["error","AudioDev"]
class error(Exception):
pass

View file

@ -6,6 +6,8 @@
import binascii
__all__ = ["encode","decode","encodestring","decodestring"]
MAXLINESIZE = 76 # Excluding the CRLF
MAXBINSIZE = (MAXLINESIZE/4)*3

View file

@ -4,6 +4,8 @@
import os
import types
__all__ = ["BdbQuit","Bdb","Breakpoint"]
BdbQuit = 'bdb.BdbQuit' # Exception to give up completely

View file

@ -27,6 +27,8 @@
import string
import binascii
__all__ = ["binhex","hexbin","Error"]
class Error(Exception):
pass

View file

@ -1,5 +1,6 @@
"""Bisection algorithms."""
__all__ = ["bisect_right","insort_right","bisect_left","insort_left"]
def insort_right(a, x, lo=0, hi=None):
"""Insert item x in list a, and keep it sorted assuming a is sorted.

View file

@ -10,6 +10,10 @@
# Import functions and variables from time module
from time import localtime, mktime
__all__ = ["error","setfirstweekday","firstweekday","isleap",
"leapdays","weekday","monthrange","monthcalendar",
"prmonth","month","prcal","calendar","timegm"]
# Exception raised for bad input (with string parameter for details)
error = ValueError

View file

@ -34,6 +34,8 @@
import UserDict
from StringIO import StringIO
__all__ = ["MiniFieldStorage","FieldStorage","FormContentDict",
"SvFormContentDict","InterpFormContentDict","FormContent"]
# Logging support
# ===============

View file

@ -48,6 +48,8 @@
default is 1, i.e. aligned.
"""
__all__ = ["Chunk"]
class Chunk:
def __init__(self, file, align = 1, bigendian = 1, inclheader = 0):
import struct

View file

@ -37,6 +37,8 @@
import string
__all__ = ["Cmd"]
PROMPT = '(Cmd) '
IDENTCHARS = string.letters + string.digits + '_'

View file

@ -10,6 +10,9 @@
import traceback
from codeop import compile_command
__all__ = ["InteractiveInterpreter","InteractiveConsole","interact",
"compile_command"]
def softspace(file, newvalue):
oldvalue = 0
try:

View file

@ -17,6 +17,9 @@
raise SystemError,\
'Failed to load the builtin codecs: %s' % why
__all__ = ["register","lookup","open","EncodedFile","BOM","BOM_BE",
"BOM_LE","BOM32_BE","BOM32_LE","BOM64_BE","BOM64_LE"]
### Constants
#

View file

@ -4,6 +4,8 @@
import string
import traceback
__all__ = ["compile_command"]
def compile_command(source, filename="<input>", symbol="single"):
r"""Compile a command and determine whether it is incomplete.

View file

@ -17,6 +17,8 @@
# References:
# XXX Where's the literature?
__all__ = ["rgb_to_yiq","yiq_to_rgb","rgb_to_hls","hls_to_rgb",
"rgb_to_hsv","hsv_to_rgb"]
# Some floating point constants

View file

@ -19,6 +19,8 @@
[Note: it would be nice to add functions to interpret the exit status.]
"""
__all__ = ["getstatusoutput","getoutput","getstatus"]
# Module 'commands'
#
# Various tools for executing commands and looking at their output and status.

View file

@ -17,6 +17,8 @@
import sys
import py_compile
__all__ = ["compile_dir","compile_path"]
def compile_dir(dir, maxlevels=10, ddir=None, force=0):
"""Byte-compile all modules in the given directory tree.

View file

@ -61,6 +61,8 @@ class Error(Exception):
except ImportError:
PyStringMap = None
__all__ = ["Error","error","copy","deepcopy"]
def copy(x):
"""Shallow copy operation on arbitrary Python objects.

View file

@ -6,6 +6,8 @@
from types import ClassType as _ClassType
__all__ = ["pickle","constructor"]
dispatch_table = {}
safe_constructors = {}

View file

@ -2,6 +2,8 @@
import bsddb
__all__ = ["error","open"]
error = bsddb.error # Exported for anydbm
def open(file, flag, mode=0666):

View file

@ -6,6 +6,8 @@
import os
__all__ = ["listdir","opendir","annotate"]
cache = {}
def listdir(path):

View file

@ -4,6 +4,10 @@
import string
import types
__all__ = ["dis","disassemble","distb","disco","opname","cmp_op",
"hasconst","hasname","hasjrel","hasjabs","haslocal",
"hascompare"]
def dis(x=None):
"""Disassemble classes, methods, functions, or code.

View file

@ -11,6 +11,8 @@
"""
import re,string,urlparse,urllib
__all__ = ["RobotFileParser"]
debug = 0
def _debug(msg):

View file

@ -0,0 +1 @@
test___all__

55
Lib/test/test___all__.py Normal file
View file

@ -0,0 +1,55 @@
from test_support import verify, verbose, TestFailed
import sys
def check_all(_modname):
exec "import %s" % _modname
verify(hasattr(sys.modules[_modname],"__all__"),
"%s has no __all__ attribute" % _modname)
exec "del %s" % _modname
exec "from %s import *" % _modname
_keys = locals().keys()
_keys.remove("_modname")
_keys.sort()
all = list(sys.modules[_modname].__all__) # in case it's a tuple
all.sort()
verify(_keys==all,"%s != %s" % (_keys,all))
check_all("BaseHTTPServer")
check_all("Bastion")
check_all("CGIHTTPServer")
check_all("ConfigParser")
check_all("Cookie")
check_all("MimeWriter")
check_all("Queue")
check_all("SimpleHTTPServer")
check_all("SocketServer")
check_all("StringIO")
check_all("UserDict")
check_all("UserList")
check_all("UserString")
check_all("aifc")
check_all("anydbm")
check_all("atexit")
check_all("audiodev")
check_all("base64")
check_all("bdb")
check_all("binhex")
check_all("bisect")
check_all("calendar")
check_all("cgi")
check_all("chunk")
check_all("cmd")
check_all("code")
check_all("codecs")
check_all("codeop")
check_all("colorsys")
check_all("commands")
check_all("compileall")
check_all("copy")
check_all("copy_reg")
check_all("dbhash")
check_all("dircache")
check_all("dis")
check_all("robotparser")