Kaydet (Commit) e99d5ea2 authored tarafından Skip Montanaro's avatar Skip Montanaro

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.
üst c955f892
...@@ -63,6 +63,7 @@ XXX To do: ...@@ -63,6 +63,7 @@ XXX To do:
__version__ = "0.2" __version__ = "0.2"
__all__ = ["HTTPServer", "BaseHTTPRequestHandler"]
import sys import sys
import time import time
......
...@@ -26,6 +26,7 @@ bastion is created. ...@@ -26,6 +26,7 @@ bastion is created.
""" """
__all__ = ["BastionClass", "Bastion"]
from types import MethodType from types import MethodType
......
...@@ -19,6 +19,7 @@ SECURITY WARNING: DON'T USE THIS CODE UNLESS YOU ARE INSIDE A FIREWALL ...@@ -19,6 +19,7 @@ SECURITY WARNING: DON'T USE THIS CODE UNLESS YOU ARE INSIDE A FIREWALL
__version__ = "0.4" __version__ = "0.4"
__all__ = ["CGIHTTPRequestHandler"]
import os import os
import sys import sys
......
...@@ -89,6 +89,11 @@ import sys ...@@ -89,6 +89,11 @@ import sys
import string import string
import re import re
__all__ = ["NoSectionError","DuplicateSectionError","NoOptionError",
"InterpolationError","InterpolationDepthError","ParsingError",
"MissingSectionHeaderError","ConfigParser",
"MAX_INTERPOLATION_DEPTH"]
DEFAULTSECT = "DEFAULT" DEFAULTSECT = "DEFAULT"
MAX_INTERPOLATION_DEPTH = 10 MAX_INTERPOLATION_DEPTH = 10
......
...@@ -228,6 +228,8 @@ try: ...@@ -228,6 +228,8 @@ try:
except ImportError: except ImportError:
raise ImportError, "Cookie.py requires 're' from Python 1.5 or later" 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 # Define an exception visible to External modules
......
...@@ -10,6 +10,7 @@ MimeWriter - the only thing here. ...@@ -10,6 +10,7 @@ MimeWriter - the only thing here.
import string import string
import mimetools import mimetools
__all__ = ["MimeWriter"]
class MimeWriter: class MimeWriter:
......
"""A multi-producer, multi-consumer queue.""" """A multi-producer, multi-consumer queue."""
__all__ = ["Queue","Empty","Full"]
class Empty(Exception): class Empty(Exception):
"Exception raised by Queue.get(block=0)/get_nowait()." "Exception raised by Queue.get(block=0)/get_nowait()."
pass pass
......
...@@ -8,6 +8,7 @@ and HEAD requests in a fairly straightforward manner. ...@@ -8,6 +8,7 @@ and HEAD requests in a fairly straightforward manner.
__version__ = "0.6" __version__ = "0.6"
__all__ = ["SimpleHTTPRequestHandler"]
import os import os
import string import string
......
...@@ -127,6 +127,13 @@ import socket ...@@ -127,6 +127,13 @@ import socket
import sys import sys
import os 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: class BaseServer:
......
...@@ -34,6 +34,8 @@ try: ...@@ -34,6 +34,8 @@ try:
except ImportError: except ImportError:
EINVAL = 22 EINVAL = 22
__all__ = ["StringIO"]
EMPTYSTRING = '' EMPTYSTRING = ''
class StringIO: class StringIO:
......
"""A more or less complete user-defined wrapper around dictionary objects.""" """A more or less complete user-defined wrapper around dictionary objects."""
__all__ = ["UserDict"]
class UserDict: class UserDict:
def __init__(self, dict=None): def __init__(self, dict=None):
self.data = {} self.data = {}
......
"""A more or less complete user-defined wrapper around list objects.""" """A more or less complete user-defined wrapper around list objects."""
__all__ = ["UserList"]
class UserList: class UserList:
def __init__(self, initlist=None): def __init__(self, initlist=None):
self.data = [] self.data = []
......
...@@ -8,6 +8,8 @@ This module requires Python 1.6 or later. ...@@ -8,6 +8,8 @@ This module requires Python 1.6 or later.
from types import StringType, UnicodeType from types import StringType, UnicodeType
import sys import sys
__all__ = ["UserString","MutableString"]
class UserString: class UserString:
def __init__(self, seq): def __init__(self, seq):
if isinstance(seq, StringType) or isinstance(seq, UnicodeType): if isinstance(seq, StringType) or isinstance(seq, UnicodeType):
......
...@@ -137,6 +137,8 @@ writeframesraw. ...@@ -137,6 +137,8 @@ writeframesraw.
import struct import struct
import __builtin__ import __builtin__
__all__ = ["Error","open","openfp"]
class Error(Exception): class Error(Exception):
pass pass
......
...@@ -42,6 +42,8 @@ only if it doesn't exist; and 'n' always creates a new database. ...@@ -42,6 +42,8 @@ only if it doesn't exist; and 'n' always creates a new database.
""" """
__all__ = ["error","open"]
try: try:
class error(Exception): class error(Exception):
pass pass
......
...@@ -5,6 +5,8 @@ upon normal program termination. ...@@ -5,6 +5,8 @@ upon normal program termination.
One public function, register, is defined. One public function, register, is defined.
""" """
__all__ = ["register"]
_exithandlers = [] _exithandlers = []
def _run_exitfuncs(): def _run_exitfuncs():
"""run any registered exit functions """run any registered exit functions
......
"""Classes for manipulating audio devices (currently only for Sun and SGI)""" """Classes for manipulating audio devices (currently only for Sun and SGI)"""
__all__ = ["error","AudioDev"]
class error(Exception): class error(Exception):
pass pass
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
import binascii import binascii
__all__ = ["encode","decode","encodestring","decodestring"]
MAXLINESIZE = 76 # Excluding the CRLF MAXLINESIZE = 76 # Excluding the CRLF
MAXBINSIZE = (MAXLINESIZE/4)*3 MAXBINSIZE = (MAXLINESIZE/4)*3
......
...@@ -4,6 +4,8 @@ import sys ...@@ -4,6 +4,8 @@ import sys
import os import os
import types import types
__all__ = ["BdbQuit","Bdb","Breakpoint"]
BdbQuit = 'bdb.BdbQuit' # Exception to give up completely BdbQuit = 'bdb.BdbQuit' # Exception to give up completely
......
...@@ -27,6 +27,8 @@ import struct ...@@ -27,6 +27,8 @@ import struct
import string import string
import binascii import binascii
__all__ = ["binhex","hexbin","Error"]
class Error(Exception): class Error(Exception):
pass pass
......
"""Bisection algorithms.""" """Bisection algorithms."""
__all__ = ["bisect_right","insort_right","bisect_left","insort_left"]
def insort_right(a, x, lo=0, hi=None): def insort_right(a, x, lo=0, hi=None):
"""Insert item x in list a, and keep it sorted assuming a is sorted. """Insert item x in list a, and keep it sorted assuming a is sorted.
......
...@@ -10,6 +10,10 @@ set the first day of the week (0=Monday, 6=Sunday).""" ...@@ -10,6 +10,10 @@ set the first day of the week (0=Monday, 6=Sunday)."""
# Import functions and variables from time module # Import functions and variables from time module
from time import localtime, mktime 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) # Exception raised for bad input (with string parameter for details)
error = ValueError error = ValueError
......
...@@ -34,6 +34,8 @@ import rfc822 ...@@ -34,6 +34,8 @@ import rfc822
import UserDict import UserDict
from StringIO import StringIO from StringIO import StringIO
__all__ = ["MiniFieldStorage","FieldStorage","FormContentDict",
"SvFormContentDict","InterpFormContentDict","FormContent"]
# Logging support # Logging support
# =============== # ===============
......
...@@ -48,6 +48,8 @@ specifies whether or not chunks are aligned on 2-byte boundaries. The ...@@ -48,6 +48,8 @@ specifies whether or not chunks are aligned on 2-byte boundaries. The
default is 1, i.e. aligned. default is 1, i.e. aligned.
""" """
__all__ = ["Chunk"]
class Chunk: class Chunk:
def __init__(self, file, align = 1, bigendian = 1, inclheader = 0): def __init__(self, file, align = 1, bigendian = 1, inclheader = 0):
import struct import struct
......
...@@ -37,6 +37,8 @@ they automatically support Emacs-like command history and editing features. ...@@ -37,6 +37,8 @@ they automatically support Emacs-like command history and editing features.
import string import string
__all__ = ["Cmd"]
PROMPT = '(Cmd) ' PROMPT = '(Cmd) '
IDENTCHARS = string.letters + string.digits + '_' IDENTCHARS = string.letters + string.digits + '_'
......
...@@ -10,6 +10,9 @@ import string ...@@ -10,6 +10,9 @@ import string
import traceback import traceback
from codeop import compile_command from codeop import compile_command
__all__ = ["InteractiveInterpreter","InteractiveConsole","interact",
"compile_command"]
def softspace(file, newvalue): def softspace(file, newvalue):
oldvalue = 0 oldvalue = 0
try: try:
......
...@@ -17,6 +17,9 @@ except ImportError,why: ...@@ -17,6 +17,9 @@ except ImportError,why:
raise SystemError,\ raise SystemError,\
'Failed to load the builtin codecs: %s' % why '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 ### Constants
# #
......
...@@ -4,6 +4,8 @@ import sys ...@@ -4,6 +4,8 @@ import sys
import string import string
import traceback import traceback
__all__ = ["compile_command"]
def compile_command(source, filename="<input>", symbol="single"): def compile_command(source, filename="<input>", symbol="single"):
r"""Compile a command and determine whether it is incomplete. r"""Compile a command and determine whether it is incomplete.
......
...@@ -17,6 +17,8 @@ HSV: Hue, Saturation, Value ...@@ -17,6 +17,8 @@ HSV: Hue, Saturation, Value
# References: # References:
# XXX Where's the literature? # 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 # Some floating point constants
......
...@@ -19,6 +19,8 @@ Encapsulates the basic operation: ...@@ -19,6 +19,8 @@ Encapsulates the basic operation:
[Note: it would be nice to add functions to interpret the exit status.] [Note: it would be nice to add functions to interpret the exit status.]
""" """
__all__ = ["getstatusoutput","getoutput","getstatus"]
# Module 'commands' # Module 'commands'
# #
# Various tools for executing commands and looking at their output and status. # Various tools for executing commands and looking at their output and status.
......
...@@ -17,6 +17,8 @@ import stat ...@@ -17,6 +17,8 @@ import stat
import sys import sys
import py_compile import py_compile
__all__ = ["compile_dir","compile_path"]
def compile_dir(dir, maxlevels=10, ddir=None, force=0): def compile_dir(dir, maxlevels=10, ddir=None, force=0):
"""Byte-compile all modules in the given directory tree. """Byte-compile all modules in the given directory tree.
......
...@@ -61,6 +61,8 @@ try: ...@@ -61,6 +61,8 @@ try:
except ImportError: except ImportError:
PyStringMap = None PyStringMap = None
__all__ = ["Error","error","copy","deepcopy"]
def copy(x): def copy(x):
"""Shallow copy operation on arbitrary Python objects. """Shallow copy operation on arbitrary Python objects.
......
...@@ -6,6 +6,8 @@ C, not for instances of user-defined classes. ...@@ -6,6 +6,8 @@ C, not for instances of user-defined classes.
from types import ClassType as _ClassType from types import ClassType as _ClassType
__all__ = ["pickle","constructor"]
dispatch_table = {} dispatch_table = {}
safe_constructors = {} safe_constructors = {}
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
import bsddb import bsddb
__all__ = ["error","open"]
error = bsddb.error # Exported for anydbm error = bsddb.error # Exported for anydbm
def open(file, flag, mode=0666): def open(file, flag, mode=0666):
......
...@@ -6,6 +6,8 @@ The annotate() routine appends slashes to directories.""" ...@@ -6,6 +6,8 @@ The annotate() routine appends slashes to directories."""
import os import os
__all__ = ["listdir","opendir","annotate"]
cache = {} cache = {}
def listdir(path): def listdir(path):
......
...@@ -4,6 +4,10 @@ import sys ...@@ -4,6 +4,10 @@ import sys
import string import string
import types import types
__all__ = ["dis","disassemble","distb","disco","opname","cmp_op",
"hasconst","hasname","hasjrel","hasjabs","haslocal",
"hascompare"]
def dis(x=None): def dis(x=None):
"""Disassemble classes, methods, functions, or code. """Disassemble classes, methods, functions, or code.
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
""" """
import re,string,urlparse,urllib import re,string,urlparse,urllib
__all__ = ["RobotFileParser"]
debug = 0 debug = 0
def _debug(msg): def _debug(msg):
......
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")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment