Whitespace normalization.

This commit is contained in:
Tim Peters 2003-01-29 03:49:43 +00:00
parent c0c12b5707
commit 2c60f7a136
11 changed files with 98 additions and 98 deletions

View File

@ -32,7 +32,7 @@ def _listMethods(self):
['string.' + method for method in list_public_methods(self.string)]
def pow(self, x, y): return pow(x, y)
def add(self, x, y) : return x + y
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(MyFuncs())
@ -137,7 +137,7 @@ def remove_duplicates(lst):
Returns a copy of a list without duplicates. Every list
item must be hashable and the order of the items in the
resulting list is not defined.
"""
"""
u = {}
for x in lst:
u[x] = 1
@ -151,7 +151,7 @@ class SimpleXMLRPCDispatcher:
and then to dispatch them. There should never be any
reason to instantiate this class directly.
"""
def __init__(self):
self.funcs = {}
self.instance = None
@ -195,7 +195,7 @@ def register_introspection_functions(self):
see http://xmlrpc.usefulinc.com/doc/reserved.html
"""
self.funcs.update({'system.listMethods' : self.system_listMethods,
'system.methodSignature' : self.system_methodSignature,
'system.methodHelp' : self.system_methodHelp})
@ -205,28 +205,28 @@ def register_multicall_functions(self):
namespace.
see http://www.xmlrpc.com/discuss/msgReader$1208"""
self.funcs.update({'system.multicall' : self.system_multicall})
def _marshaled_dispatch(self, data, dispatch_method = None):
"""Dispatches an XML-RPC method from marshalled (XML) data.
XML-RPC methods are dispatched from the marshalled (XML) data
using the _dispatch method and the result is returned as
marshalled data. For backwards compatibility, a dispatch
function can be provided as an argument (see comment in
function can be provided as an argument (see comment in
SimpleXMLRPCRequestHandler.do_POST) but overriding the
existing method through subclassing is the prefered means
of changing method dispatch behavior.
"""
params, method = xmlrpclib.loads(data)
# generate response
try:
if dispatch_method is not None:
response = dispatch_method(method, params)
else:
else:
response = self._dispatch(method, params)
# wrap response in a singleton tuple
response = (response,)
@ -245,7 +245,7 @@ def system_listMethods(self):
"""system.listMethods() => ['add', 'subtract', 'multiple']
Returns a list of the methods supported by the server."""
methods = self.funcs.keys()
if self.instance is not None:
# Instance can implement _listMethod to return a list of
@ -263,7 +263,7 @@ def system_listMethods(self):
)
methods.sort()
return methods
def system_methodSignature(self, method_name):
"""system.methodSignature('add') => [double, int, int]
@ -274,14 +274,14 @@ def system_methodSignature(self, method_name):
This server does NOT support system.methodSignature."""
# See http://xmlrpc.usefulinc.com/doc/sysmethodsig.html
return 'signatures not supported'
def system_methodHelp(self, method_name):
"""system.methodHelp('add') => "Adds two integers together"
Returns a string containing documentation for the specified method."""
method = None
if self.funcs.has_key(method_name):
method = self.funcs[method_name]
@ -314,9 +314,9 @@ def system_multicall(self, call_list):
Allows the caller to package multiple XML-RPC calls into a single
request.
See http://www.xmlrpc.com/discuss/msgReader$1208
See http://www.xmlrpc.com/discuss/msgReader$1208
"""
results = []
for call in call_list:
method_name = call['methodName']
@ -337,7 +337,7 @@ def system_multicall(self, call_list):
'faultString' : "%s:%s" % (sys.exc_type, sys.exc_value)}
)
return results
def _dispatch(self, method, params):
"""Dispatches the XML-RPC method.
@ -382,7 +382,7 @@ def _dispatch(self, method, params):
return func(*params)
else:
raise Exception('method "%s" is not supported' % method)
class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""Simple XML-RPC request handler class.
@ -396,7 +396,7 @@ def do_POST(self):
Attempts to interpret all HTTP POST requests as XML-RPC calls,
which are forwarded to the server's _dispatch method for handling.
"""
try:
# get arguments
data = self.rfile.read(int(self.headers["content-length"]))
@ -423,14 +423,14 @@ def do_POST(self):
# shut down the connection
self.wfile.flush()
self.connection.shutdown(1)
def log_request(self, code='-', size='-'):
"""Selectively log an accepted request."""
if self.server.logRequests:
BaseHTTPServer.BaseHTTPRequestHandler.log_request(self, code, size)
class SimpleXMLRPCServer(SocketServer.TCPServer,
class SimpleXMLRPCServer(SocketServer.TCPServer,
SimpleXMLRPCDispatcher):
"""Simple XML-RPC server.
@ -444,21 +444,21 @@ class SimpleXMLRPCServer(SocketServer.TCPServer,
def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
logRequests=1):
self.logRequests = logRequests
SimpleXMLRPCDispatcher.__init__(self)
SocketServer.TCPServer.__init__(self, addr, requestHandler)
class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):
"""Simple handler for XML-RPC data passed through CGI."""
def __init__(self):
SimpleXMLRPCDispatcher.__init__(self)
def handle_xmlrpc(self, request_text):
"""Handle a single XML-RPC request"""
response = self._marshaled_dispatch(request_text)
print 'Content-Type: text/xml'
print 'Content-Length: %d' % len(response)
print
@ -474,11 +474,11 @@ def handle_get(self):
code = 400
message, explain = \
BaseHTTPServer.BaseHTTPRequestHandler.responses[code]
response = BaseHTTPServer.DEFAULT_ERROR_MESSAGE % \
{
'code' : code,
'message' : message,
'code' : code,
'message' : message,
'explain' : explain
}
print 'Status: %d %s' % (code, message)
@ -486,25 +486,25 @@ def handle_get(self):
print 'Content-Length: %d' % len(response)
print
print response
def handle_request(self, request_text = None):
"""Handle a single XML-RPC request passed through a CGI post method.
If no XML data is given then it is read from stdin. The resulting
XML-RPC response is printed to stdout along with the correct HTTP
headers.
"""
if request_text is None and \
os.environ.get('REQUEST_METHOD', None) == 'GET':
self.handle_get()
else:
# POST data is normally available through stdin
if request_text is None:
request_text = sys.stdin.read()
request_text = sys.stdin.read()
self.handle_xmlrpc(request_text)
if __name__ == '__main__':
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)

View File

@ -499,12 +499,12 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
#populous then just inline calculations. Also might be able to use
#``datetime`` and the methods it provides.
if julian == -1:
julian = julianday(year, month, day)
julian = julianday(year, month, day)
else: # Assuming that if they bothered to include Julian day it will
#be accurate
year, month, day = gregorian(julian, year)
year, month, day = gregorian(julian, year)
if weekday == -1:
weekday = dayofweek(year, month, day)
weekday = dayofweek(year, month, day)
return time.struct_time((year, month, day,
hour, minute, second,
weekday, julian, tz))

View File

@ -4,7 +4,7 @@
not need to be rewritten for when the thread module is not present.
Suggested usage is::
try:
import thread
except ImportError:
@ -67,7 +67,7 @@ def allocate_lock():
class LockType(object):
"""Class implementing dummy implementation of thread.LockType.
Compatibility is maintained by maintaining self.locked_status
which is a boolean that stores the state of the lock. Pickling of
the lock, though, should not be done since if the thread module is
@ -78,7 +78,7 @@ class LockType(object):
def __init__(self):
self.locked_status = False
def acquire(self, waitflag=None):
"""Dummy implementation of acquire().
@ -92,7 +92,7 @@ def acquire(self, waitflag=None):
"""
if waitflag is None:
self.locked_status = True
return None
return None
elif not waitflag:
if not self.locked_status:
self.locked_status = True
@ -101,7 +101,7 @@ def acquire(self, waitflag=None):
return False
else:
self.locked_status = True
return True
return True
def release(self):
"""Release the dummy lock."""

View File

@ -85,10 +85,10 @@ def dirname(s): return split(s)[0]
def basename(s): return split(s)[1]
def ismount(s):
if not isabs(s):
return False
components = split(s)
return len(components) == 2 and components[1] == ''
if not isabs(s):
return False
components = split(s)
return len(components) == 2 and components[1] == ''
def isdir(s):
"""Return true if the pathname refers to an existing directory."""

View File

@ -514,9 +514,9 @@ def replace_paths_in_code(self, co):
if isinstance(consts[i], type(co)):
consts[i] = self.replace_paths_in_code(consts[i])
return new.code(co.co_argcount, co.co_nlocals, co.co_stacksize,
co.co_flags, co.co_code, tuple(consts), co.co_names,
co.co_varnames, new_filename, co.co_name,
return new.code(co.co_argcount, co.co_nlocals, co.co_stacksize,
co.co_flags, co.co_code, tuple(consts), co.co_names,
co.co_varnames, new_filename, co.co_name,
co.co_firstlineno, co.co_lnotab,
co.co_freevars, co.co_cellvars)

View File

@ -415,9 +415,9 @@ def copy(self):
environ = _Environ(environ)
def getenv(key, default=None):
"""Get an environment variable, return None if it doesn't exist.
The optional second argument can specify an alternate default."""
return environ.get(key, default)
"""Get an environment variable, return None if it doesn't exist.
The optional second argument can specify an alternate default."""
return environ.get(key, default)
__all__.append("getenv")
def _exists(name):

View File

@ -1859,10 +1859,10 @@ def dis(pickle, out=None, indentlevel=4):
markmsg = None
if markstack and markobject in opcode.stack_before:
assert markobject not in opcode.stack_after
markpos = markstack.pop()
if markpos is not None:
markmsg = "(MARK at %d)" % markpos
assert markobject not in opcode.stack_after
markpos = markstack.pop()
if markpos is not None:
markmsg = "(MARK at %d)" % markpos
if arg is not None or markmsg:
# make a mild effort to align arguments

View File

@ -92,8 +92,8 @@ def slave_open(tty_name):
except ImportError:
return result
try:
ioctl(result, I_PUSH, "ptem")
ioctl(result, I_PUSH, "ldterm")
ioctl(result, I_PUSH, "ptem")
ioctl(result, I_PUSH, "ldterm")
except IOError:
pass
return result

View File

@ -24,24 +24,24 @@ class PyCompileError(Exception):
raise PyCompileError(exc_type,exc_value,file[,msg])
where
exc_type: exception type to be used in error message
type name can be accesses as class variable
'exc_type_name'
exc_value: exception value to be used in error message
can be accesses as class variable 'exc_value'
file: name of file being compiled to be used in error message
can be accesses as class variable 'file'
msg: string message to be written as error message
If no value is given, a default exception message will be given,
consistent with 'standard' py_compile output.
message (or default) can be accesses as class variable 'msg'
"""
def __init__(self, exc_type, exc_value, file, msg=''):
exc_type_name = exc_type.__name__
if exc_type is SyntaxError:
@ -49,7 +49,7 @@ def __init__(self, exc_type, exc_value, file, msg=''):
errmsg = tbtext.replace('File "<string>"', 'File "%s"' % file)
else:
errmsg = "Sorry: %s: %s" % (exc_type_name,exc_value)
Exception.__init__(self,msg or errmsg,exc_type_name,exc_value,file)
self.exc_type_name = exc_type_name
@ -94,7 +94,7 @@ def compile(file, cfile=None, dfile=None, doraise=False):
and the function will return to the caller. If an
exception occurs and this flag is set to True, a
PyCompileError exception will be raised.
Note that it isn't necessary to byte-compile Python modules for
execution efficiency -- Python itself byte-compiles a module when
it is loaded, and if it can, writes out the bytecode to the
@ -159,6 +159,6 @@ def main(args=None):
compile(filename, doraise=True)
except PyCompileError,err:
sys.stderr.write(err.msg)
if __name__ == "__main__":
main()

View File

@ -1249,7 +1249,7 @@ def addfile(self, tarinfo, fileobj=None):
if self.posix:
prefix = tarinfo.name[:LENGTH_PREFIX + 1]
while prefix and prefix[-1] != "/":
prefix = prefix[:-1]
prefix = prefix[:-1]
name = tarinfo.name[len(prefix):]
prefix = prefix[:-1]

View File

@ -74,7 +74,7 @@ def find_library_file(compiler, libname, std_dirs, paths):
return [p]
else:
assert False, "Internal error: Path not found in std_dirs or paths"
def module_enabled(extlist, modname):
"""Returns whether the module 'modname' is present in the list
of extensions 'extlist'."""
@ -159,7 +159,7 @@ def build_extensions(self):
line = line.split()
remove_modules.append( line[0] )
input.close()
for ext in self.extensions[:]:
if ext.name in remove_modules:
self.extensions.remove(ext)
@ -323,7 +323,7 @@ def detect_modules(self):
exts.append( Extension('datetime', ['datetimemodule.c'],
libraries=math_libs) )
# random number generator implemented in C
exts.append( Extension("_random", ["_randommodule.c"]) )
exts.append( Extension("_random", ["_randommodule.c"]) )
# operator.add() and similar goodies
exts.append( Extension('operator', ['operator.c']) )
# Python C API test module
@ -347,9 +347,9 @@ def detect_modules(self):
exts.append( Extension('fcntl', ['fcntlmodule.c']) )
if platform not in ['mac']:
# pwd(3)
exts.append( Extension('pwd', ['pwdmodule.c']) )
# grp(3)
exts.append( Extension('grp', ['grpmodule.c']) )
exts.append( Extension('pwd', ['pwdmodule.c']) )
# grp(3)
exts.append( Extension('grp', ['grpmodule.c']) )
# select(2); not on ancient System V
exts.append( Extension('select', ['selectmodule.c']) )
@ -380,8 +380,8 @@ def detect_modules(self):
# enigma-inspired encryption
exts.append( Extension('rotor', ['rotormodule.c']) )
if platform not in ['mac']:
# syslog daemon interface
exts.append( Extension('syslog', ['syslogmodule.c']) )
# syslog daemon interface
exts.append( Extension('syslog', ['syslogmodule.c']) )
# George Neville-Neil's timing module:
exts.append( Extension('timing', ['timingmodule.c']) )
@ -419,12 +419,12 @@ def detect_modules(self):
libraries=readline_libs) )
if platform not in ['mac']:
# crypt module.
if self.compiler.find_library_file(lib_dirs, 'crypt'):
libs = ['crypt']
else:
libs = []
exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
if self.compiler.find_library_file(lib_dirs, 'crypt'):
libs = ['crypt']
else:
libs = []
exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
# socket(2)
exts.append( Extension('_socket', ['socketmodule.c'],
@ -501,7 +501,7 @@ def detect_modules(self):
db_search_order = db_try_this.keys()
db_search_order.sort()
db_search_order.reverse()
class found(Exception): pass
try:
# See whether there is a Sleepycat header in the standard
@ -602,7 +602,7 @@ class found(Exception): pass
# Steen Lumholt's termios module
exts.append( Extension('termios', ['termios.c']) )
# Jeremy Hylton's rlimit interface
if platform not in ['atheos']:
if platform not in ['atheos']:
exts.append( Extension('resource', ['resource.c']) )
# Sun yellow pages. Some systems have the functions in libc.
@ -625,7 +625,7 @@ class found(Exception): pass
iconv_libraries = ['iconv']
else:
iconv_libraries = [] # in libc
exts.append( Extension('_iconv_codec',
['_iconv_codec.c'],
include_dirs = iconv_incs,
@ -726,7 +726,7 @@ class found(Exception): pass
('XML_CONTEXT_BYTES','1024'),
],
include_dirs = [expatinc]
))
))
# Dynamic loading module
if sys.maxint == 0x7fffffff:
@ -821,7 +821,7 @@ class found(Exception): pass
# should put a symlink to your Waste installation in the
# same folder as your python source tree. Or modify the
# next few lines:-)
waste_incs = find_file("WASTE.h", [],
waste_incs = find_file("WASTE.h", [],
['../'*n + 'waste/C_C++ Headers' for n in (0,1,2,3,4)])
waste_libs = find_library_file(self.compiler, "WASTE", [],
["../"*n + "waste/Static Libraries" for n in (0,1,2,3,4)])
@ -829,7 +829,7 @@ class found(Exception): pass
(srcdir,) = sysconfig.get_config_vars('srcdir')
exts.append( Extension('waste',
['waste/wastemodule.c'] + [
os.path.join(srcdir, d) for d in
os.path.join(srcdir, d) for d in
'Mac/Wastemods/WEObjectHandlers.c',
'Mac/Wastemods/WETabHooks.c',
'Mac/Wastemods/WETabs.c'
@ -852,8 +852,8 @@ def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
# different the UNIX search logic is not sharable.
from os.path import join, exists
framework_dirs = [
'/System/Library/Frameworks/',
'/Library/Frameworks',
'/System/Library/Frameworks/',
'/Library/Frameworks',
join(os.getenv('HOME'), '/Library/Frameworks')
]
@ -861,9 +861,9 @@ def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
# bundles.
# XXX distutils should support -F!
for F in framework_dirs:
# both Tcl.framework and Tk.framework should be present
# both Tcl.framework and Tk.framework should be present
for fw in 'Tcl', 'Tk':
if not exists(join(F, fw + '.framework')):
if not exists(join(F, fw + '.framework')):
break
else:
# ok, F is now directory with both frameworks. Continure
@ -873,18 +873,18 @@ def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
# Tk and Tcl frameworks not found. Normal "unix" tkinter search
# will now resume.
return 0
# For 8.4a2, we must add -I options that point inside the Tcl and Tk
# frameworks. In later release we should hopefully be able to pass
# the -F option to gcc, which specifies a framework lookup path.
# the -F option to gcc, which specifies a framework lookup path.
#
include_dirs = [
join(F, fw + '.framework', H)
join(F, fw + '.framework', H)
for fw in 'Tcl', 'Tk'
for H in 'Headers', 'Versions/Current/PrivateHeaders'
]
# For 8.4a2, the X11 headers are not included. Rather than include a
# For 8.4a2, the X11 headers are not included. Rather than include a
# complicated search, this is a hard-coded path. It could bail out
# if X11 libs are not found...
include_dirs.append('/usr/X11R6/include')
@ -900,7 +900,7 @@ def detect_tkinter_darwin(self, inc_dirs, lib_dirs):
self.extensions.append(ext)
return 1
def detect_tkinter(self, inc_dirs, lib_dirs):
# The _tkinter module.
@ -910,7 +910,7 @@ def detect_tkinter(self, inc_dirs, lib_dirs):
platform = self.get_platform()
if platform == 'darwin' and \
self.detect_tkinter_darwin(inc_dirs, lib_dirs):
return
return
# Set platform specific library prefix, if any
if platform == 'cygwin':