Normalize whitespace. (quixote: TemplateIO.py, __init__.py, config.py, html.py, http_request.py, ...)
Greg Ward <gward-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Wed, 20 Nov 2002 14:43:24 -0500
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /home/cvs/quixote
In directory hewson:/tmp/cvs-serv18744
Modified Files:
TemplateIO.py __init__.py config.py html.py http_request.py
http_response.py mod_python_handler.py ptl_compile.py
ptl_import.py publish.py sendmail.py session.py setup.py
upload.py util.py
Log Message:
Normalize whitespace.
Index: TemplateIO.py
===================================================================
RCS file: /home/cvs/quixote/TemplateIO.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- TemplateIO.py 14 Oct 2002 22:58:01 -0000 1.7
+++ TemplateIO.py 20 Nov 2002 19:43:22 -0000 1.8
@@ -4,7 +4,7 @@
class TemplateIO:
"""Collect output for PTL scripts.
-
+
Behaves similar to the StringIO class except that str() is called on
input and None objects are not added to the output.
"""
@@ -22,13 +22,13 @@
result.data = self.data[:]
result.data.append(other)
return result
-
+
def __radd__(self, other):
result = TemplateIO()
result.data = [other]
result.data.extend(self.data)
return result
-
+
def __str__(self):
return ''.join(map(str, self.data))
Index: __init__.py
===================================================================
RCS file: /home/cvs/quixote/__init__.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- __init__.py 3 Oct 2002 15:06:37 -0000 1.22
+++ __init__.py 20 Nov 2002 19:43:22 -0000 1.23
@@ -10,7 +10,7 @@
__all__ = ['Publisher',
'get_publisher', 'get_request', 'get_session', 'get_user',
'get_path', 'enable_ptl', 'redirect']
-
+
# These are frequently needed by Quixote applications, so make them easy
# to get at.
Index: config.py
===================================================================
RCS file: /home/cvs/quixote/config.py,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- config.py 3 Oct 2002 14:36:18 -0000 1.43
+++ config.py 20 Nov 2002 19:43:22 -0000 1.44
@@ -184,7 +184,7 @@
config_vars = [
'error_email',
- 'access_log',
+ 'access_log',
'debug_log',
'display_exceptions',
'secure_errors',
@@ -263,8 +263,8 @@
def read_file (self, filename):
"""Read configuration from a file. Any variables already
- defined in this Config instance, but not in the file, are
- unchanged, so you can use this to build up a configuration
+ defined in this Config instance, but not in the file, are
+ unchanged, so you can use this to build up a configuration
by accumulating data from several config files.
"""
# The config file is Python code -- makes life easy.
Index: html.py
===================================================================
RCS file: /home/cvs/quixote/html.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- html.py 20 Nov 2002 19:36:41 -0000 1.20
+++ html.py 20 Nov 2002 19:43:22 -0000 1.21
@@ -12,7 +12,7 @@
Use for quoting data that will be used within attribute values or as
element contents. Examples:
-
+
'<title>%s</title>' % html_quote(title)
'<input type="hidden" value="%s" />' % html_quote(data)
'<a href="%s">something</a>' % html_quote(url)
@@ -33,7 +33,7 @@
using html_quote. For example:
url = 'http://example.com/?a=1©=0'
- ...
+ ...
'<a href="%s">do something</a>' % html_quote(url)
If html_quote is not used, old browsers would treat "©" as an entity
@@ -50,9 +50,7 @@
import re
if sys.hexversion < 0x20200b1:
-
# inefficient 2.2 compatibility hacks
-
class object:
pass
@@ -70,7 +68,6 @@
return type(o)
else:
-
classof = type
_format_codes = 'diouxXeEfFgGcrs%'
@@ -201,7 +198,7 @@
else:
new = self.quote(new)
return self.__class__(self.s.replace(old, new))
-
+
def lower(self):
return self.__class__(self.s.lower())
@@ -334,7 +331,7 @@
def value_quote(value):
"""Quote HTML attribute values. This function is of marginal
utility since html_quote can be used.
-
+
XHTML 1.0 requires that all values be quoted. weblint claims
that some clients don't understand single quotes. For compatibility
with HTML, XHTML 1.0 requires that ampersands be encoded.
Index: http_request.py
===================================================================
RCS file: /home/cvs/quixote/http_request.py,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- http_request.py 30 Oct 2002 20:59:10 -0000 1.53
+++ http_request.py 20 Nov 2002 19:43:22 -0000 1.54
@@ -10,14 +10,14 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
-#
+#
##############################################################################
__revision__ = "$Id$"
@@ -125,7 +125,7 @@
# IIS breaks PATH_INFO because it leaves in the path to
# the script, so SCRIPT_NAME is "/cgi-bin/q.py" and PATH_INFO
- # is "/cgi-bin/q.py/foo/bar". The following code fixes
+ # is "/cgi-bin/q.py/foo/bar". The following code fixes
# PATH_INFO to the expected value "/foo/bar".
web_server = environ.get('SERVER_SOFTWARE', 'unknown')
if web_server.find('Microsoft-IIS') != -1:
@@ -134,7 +134,7 @@
if path.startswith(script):
path = path[len(script):]
self.environ['PATH_INFO'] = path
-
+
def add_form_value (self, key, value):
if self.form.has_key(key):
found = self.form[key]
@@ -145,7 +145,7 @@
self.form[key] = found
else:
self.form[key] = value
-
+
def process_inputs (self):
"""Process request inputs.
"""
@@ -168,7 +168,7 @@
if fs.list:
for item in fs.list:
self.add_form_value(item.name, item.value)
-
+
def get_header (self, name, default=None):
"""get_header(name : string, default : string = None) -> string
@@ -268,7 +268,7 @@
def get_encoding (self, encodings):
"""get_encoding(encodings : [string]) -> string
-
+
Parse the "Accept-encoding" header. 'encodings' is a list of
encodings supported by the server sorted in order of preference.
The return value is one of 'encodings' or None if the client
@@ -290,7 +290,7 @@
accept_types = self.environ.get('HTTP_ACCEPT', "")
return self._parse_pref_header(accept_types)
-
+
def _parse_pref_header (self, S):
"""_parse_pref_header(S:string) : {string:float}
Parse a list of HTTP preferences (content types, encodings) and
@@ -314,8 +314,8 @@
if q > 0:
found[encoding] = q
return found
-
-
+
+
def dump_html (self):
row_fmt=('<tr valign="top"><th align="left">%s</th><td>%s</td></tr>')
lines = ["<h3>form</h3>",
@@ -328,7 +328,7 @@
"<table>"]
for k,v in self.cookies.items():
lines.append(row_fmt % (html_quote(k), html_quote(v)))
-
+
lines += ["</table>",
"<h3>environ</h3>"
"<table>"]
@@ -429,7 +429,7 @@
return (name, version)
# guess_browser_version ()
-
+
def redirect (self, location, permanent=0):
"""redirect(location : string, permanent : boolean = false)
-> string
Index: http_response.py
===================================================================
RCS file: /home/cvs/quixote/http_response.py,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- http_response.py 3 Oct 2002 15:21:17 -0000 1.34
+++ http_response.py 20 Nov 2002 19:43:22 -0000 1.35
@@ -9,14 +9,14 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
-#
+#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
-#
+#
##############################################################################
__revision__ = "$Id$"
@@ -79,7 +79,7 @@
class HTTPResponse:
"""
An object representation of an HTTP response.
-
+
The Response type encapsulates all possible responses to HTTP
requests. Responses are normally created by the Quixote publisher
or by the HTTPRequest class (every request must have a response,
@@ -98,7 +98,7 @@
them, but that would be foolish).
body : string
the response body, None by default. If the body is never
- set (ie. left as None), the response will not include
+ set (ie. left as None), the response will not include
"Content-type" or "Content-length" headers. These headers
are set as soon as the body is set (with set_body()), even
if the body is an empty string.
@@ -124,7 +124,7 @@
"""
self.set_status(status)
self.headers = {}
-
+
if body is not None:
self.set_body(body)
else:
@@ -188,7 +188,7 @@
def set_body (self, body):
"""set_body(body : string)
-
+
Sets the return body equal to the (string) argument "body". Also
updates the "Content-length" return header. If the
"Content-type" header has not yet been set, it is set to
@@ -205,7 +205,7 @@
def expire_cookie (self, name, **attrs):
"""
Cause an HTTP cookie to be removed from the browser
-
+
The response will include an HTTP header that will remove the cookie
corresponding to "name" on the client, if one exists. This is
accomplished by sending a new cookie with an expiration date
@@ -302,8 +302,8 @@
# 'chunks' is a list of "name=val" chunks; will be joined
# with "; " to create the "Set-cookie" header.
- chunks = ['%s="%s"' % (name, attrs['value'])]
-
+ chunks = ['%s="%s"' % (name, attrs['value'])]
+
for (name, val) in attrs.items():
name = name.lower()
if val is None:
@@ -318,7 +318,7 @@
cookie_list.append(cookie)
# Should really check size of cookies here!
-
+
return cookie_list
def write (self, file):
Index: mod_python_handler.py
===================================================================
RCS file: /home/cvs/quixote/mod_python_handler.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mod_python_handler.py 13 Nov 2001 16:28:31 -0000 1.7
+++ mod_python_handler.py 20 Nov 2002 19:43:22 -0000 1.8
@@ -15,7 +15,7 @@
class ModPythonPublisher(Publisher):
def publish_modpython(self, req):
"""publish_modpython() -> None
-
+
Entry point from mod_python.
"""
self.publish(apache.CGIStdin(req),
Index: ptl_compile.py
===================================================================
RCS file: /home/cvs/quixote/ptl_compile.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- ptl_compile.py 21 Oct 2002 17:31:44 -0000 1.26
+++ ptl_compile.py 20 Nov 2002 19:43:22 -0000 1.27
@@ -81,7 +81,7 @@
args = nodelist[2][2]
if not re.match('_q_((html|plain)_)?template_', name):
- # just a normal function, let base class handle it
+ # just a normal function, let base class handle it
self.__template_type.append(None)
n = transformer.Transformer.funcdef(self, nodelist)
@@ -184,13 +184,13 @@
Since we can't modify the parser in the builtin parser module we
must do token translation here. Luckily it does not affect line
numbers.
-
+
template foo(...): -> def _q_template__foo(...):
def foo [plain] (...): -> def _q_plain_template__foo(...):
def foo [html] (...): -> def _q_html_template__foo(...):
-
+
XXX This parser is too stupid. For example, it doesn't understand
triple quoted strings.
"""
@@ -269,7 +269,7 @@
def compile_template(input, filename, output=None):
"""compile_template(input, filename, output=None) -> code
-
+
Compile an open file. If output is not None then the code is written
with the magic template header. The code object is returned.
"""
@@ -282,7 +282,7 @@
def compile(inputname, outputname):
"""compile(inputname, outputname)
-
+
Compile a template file. The new template is writen to outputname.
"""
input = open(inputname)
@@ -298,7 +298,7 @@
def compile_dir(dir, maxlevels=10, force=False):
"""Byte-compile all PTL modules in the given directory tree.
(Adapted from compile_dir in Python module: compileall.py)
-
+
Arguments (only dir is required):
dir: the directory to byte-compile
Index: ptl_import.py
===================================================================
RCS file: /home/cvs/quixote/ptl_import.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- ptl_import.py 11 Mar 2002 21:18:28 -0000 1.25
+++ ptl_import.py 20 Nov 2002 19:43:22 -0000 1.26
@@ -54,7 +54,7 @@
return _load_ptl(name, ptl_filename)
code = marshal.load(file)
return _new_module(code, name, filename)
-
+
def _load_ptl(name, filename, file=None):
if not file:
try:
@@ -90,7 +90,7 @@
return L + [(PTLC_EXT, 'rb', PTLC_FILE), (PTL_EXT, 'r', PTL_FILE)]
class PTLLoader (ihooks.ModuleLoader):
-
+
def load_module (self, name, stuff):
file, filename, info = stuff
(suff, mode, type) = info
Index: publish.py
===================================================================
RCS file: /home/cvs/quixote/publish.py,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -d -r1.139 -r1.140
--- publish.py 17 Oct 2002 15:08:10 -0000 1.139
+++ publish.py 20 Nov 2002 19:43:22 -0000 1.140
@@ -29,7 +29,7 @@
__import__(name)
module = sys.modules[name]
return module
-
+
# Error message to dispay when DISPLAY_EXCEPTIONS in config file is not
# true. Note that SERVER_ADMIN must be fetched from the environment and
# plugged in here -- we can't do it now because the environment isn't
@@ -154,7 +154,7 @@
try:
self.access_log = open(self.config.access_log, 'a', 1)
except IOError, exc:
- sys.stderr.write("error opening access log %s: %s\n"
+ sys.stderr.write("error opening access log %s: %s\n"
% (`self.config.access_log`, exc.strerror))
if self.config.error_log is not None:
@@ -173,7 +173,7 @@
except IOError, exc:
sys.stderr.write("error opening debug log %s: %s\n"
% (`self.config.debug_log`, exc.strerror))
-
+
def shutdown_logs (self):
"""
@@ -308,7 +308,7 @@
if self.config.secure_errors and exc.private_msg:
exc.private_msg = None # hide it
-
+
# walk up stack and find handler for the exception
stack = self.namespace_stack[:]
while 1:
@@ -320,7 +320,7 @@
break
if handler is None:
handler = errors.default_exception_handler
-
+
try:
return handler(request, exc)
except errors.PublishError:
@@ -375,7 +375,7 @@
request.response.set_status(500)
return user_error_msg
-
+
def _generate_internal_error (self, request):
admin = request.environ.get('SERVER_ADMIN',
@@ -397,7 +397,7 @@
return error_file.getvalue()
-
+
def _generate_cgitb_error (self, request, original_response,
exc_type, exc_value, tb):
error_file = cStringIO.StringIO()
@@ -410,7 +410,7 @@
error_file.write('</pre>')
return error_file.getvalue()
-
+
def mail_error (self, msg, error_summary):
"""Send an email notifying someone of a traceback."""
@@ -438,7 +438,7 @@
if hasattr(container, '_q_access'):
# will raise AccessError if access failed
container._q_access(request)
-
+
# Third security check: make sure the current name component is
# in the export list or is _q_index.
if (component == "_q_index") or (component in container._q_exports):
@@ -456,7 +456,7 @@
elif has_component:
object = getattr(container, component)
- else:
+ else:
# not a module, doesn't have 'component'
raise errors.TraversalError(
private_msg="object %r has no attribute %r" % (
@@ -478,7 +478,7 @@
private_msg="%r not in _q_exports list for %r" % (
component,
container))
-
+
self.namespace_stack.append(object)
return object
@@ -502,7 +502,7 @@
having _q_exports be an empty list is OK. If a component of the path
isn't in _q_exports, that also produces an error.
"""
-
+
# If someone accesses a Quixote driver script without a trailing
# slash, we'll wind up here with an empty path. This won't
# work; relative references in the page generated by the root
@@ -565,10 +565,10 @@
def try_publish (self, request, path):
"""try_publish(request : HTTPRequest, path : string) -> string
-
+
The master method that does all the work for a single request. Uses
traverse_url() to get a callable object. The object is called and
- the output is returned. Exceptions are handled by the caller.
+ the output is returned. Exceptions are handled by the caller.
"""
self.start_request(request)
@@ -626,7 +626,7 @@
co.flush(),
struct.pack("<ll", zlib.crc32(output), len(output))]
output = "".join(chunks)
- #self.log("gzip (original size %d, ratio %.1f)" %
+ #self.log("gzip (original size %d, ratio %.1f)" %
# (n, float(n)/len(output)))
request.response.set_header("Content-Encoding", encoding)
return output
@@ -671,7 +671,7 @@
request.response.write(stdout)
self._clear_request()
-
+
def publish_cgi (self):
"""publish_cgi() -> None
@@ -696,7 +696,7 @@
class SessionPublisher (Publisher):
-
+
def __init__ (self, root_namespace, config=None, session_mgr=None):
from quixote.session import SessionManager
Publisher.__init__(self, root_namespace, config)
@@ -734,7 +734,7 @@
# why this would be necessary), you'll have to abort the
# current transaction, make your session changes, and then
# raise the PublishError.
- #
+ #
# XXX We should really be able to commit session changes and
# database changes separately, but that requires ZODB
# incantations that we currently don't know.
Index: sendmail.py
===================================================================
RCS file: /home/cvs/quixote/sendmail.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- sendmail.py 19 Aug 2002 23:37:44 -0000 1.8
+++ sendmail.py 20 Nov 2002 19:43:22 -0000 1.9
@@ -26,7 +26,7 @@
"Smith, John" <[email protected]>
Dick & Jane <[email protected]>
"Tom, Dick, & Harry" <[email protected]>
-
+
This class represents an (addr_spec, real_name) pair and takes care
of quoting the real_name according to RFC 822's rules for you.
Just use the format() method and it will spit out a properly-
@@ -117,7 +117,7 @@
headers.append("%s: (long recipient list suppressed) : ;" % field_name)
-def sendmail (subject, msg_body, to_addrs,
+def sendmail (subject, msg_body, to_addrs,
from_addr=None, cc_addrs=None,
extra_headers=None,
smtp_sender=None, smtp_recipients=None,
@@ -131,7 +131,7 @@
smtp_sender : email_address = (derived from from_addr)
smtp_recipients : [email_address] = (derived from to_addrs),
config : quixote.config.Config = (current publisher's config)):
-
+
Send an email message to a list of recipients via a local SMTP
server. In normal use, you supply a list of primary recipient
e-mail addresses in 'to_addrs', an optional list of secondary
@@ -194,7 +194,7 @@
This is so useful that it's a Quixote configuration option: just set
MAIL_DEBUG_ADDR to (eg.) "[email protected]", and every message
that sendmail() would send out is diverted to the debug address.
-
+
Generally raises an exception on any SMTP errors; see smtplib (in
the standard library documentation) for details.
"""
@@ -241,7 +241,7 @@
sep = ("-"*72) + "\n"
msg_body = debug1 + debug2 + sep + msg_body
-
+
smtp_recipients = [config.mail_debug_addr]
if smtp_sender is None:
@@ -290,4 +290,4 @@
p.config.mail_debug_addr = "gward-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]"
sendmail(["[email protected]"], s, b,
smtp_recipients=["[email protected]", "[email protected]"])
-
+
Index: session.py
===================================================================
RCS file: /home/cvs/quixote/session.py,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- session.py 25 Oct 2002 17:31:39 -0000 1.59
+++ session.py 20 Nov 2002 19:43:22 -0000 1.60
@@ -241,7 +241,7 @@
return None
else:
return id
-
+
def _make_session_id (self):
# Generate a session ID, which is just the value of the session
# cookie we are about to drop on the user. (It's also the key
@@ -471,7 +471,7 @@
Return true if this session has changed since it was last saved
such that it needs to be saved again.
-
+
Default implementation always returns false since the default
storage mechanism is an in-memory dictionary, and you don't have
to put the same object into the same slot of a dictionary twice.
@@ -500,7 +500,7 @@
def start_request (self, request):
"""start_request(request : HTTPRequest)
-
+
Called near the beginning of each request: after the HTTPRequest
object has been built and this Session object has been fetched
or built, but before we traverse the URL or call the callable
@@ -584,7 +584,7 @@
Return true if 'token' is in the queue of outstanding tokens.
"""
return token in self._form_tokens
-
+
def remove_form_token (self, token):
"""remove_form_token(token : string)
Index: setup.py
===================================================================
RCS file: /home/cvs/quixote/setup.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- setup.py 3 Oct 2002 15:06:37 -0000 1.23
+++ setup.py 20 Nov 2002 19:43:22 -0000 1.24
@@ -22,4 +22,4 @@
cmdclass = {'build_py': qx_build_py},
)
-
+
Index: upload.py
===================================================================
RCS file: /home/cvs/quixote/upload.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- upload.py 7 Nov 2002 17:47:47 -0000 1.6
+++ upload.py 20 Nov 2002 19:43:22 -0000 1.7
@@ -53,7 +53,7 @@
# Hit EOF -- nothing more to read. (This should *not* happen
# in a well-formed MIME message, but let's assume the worst.)
- if not line:
+ if not line:
return 1
# Strip (but remember) line ending.
@@ -121,7 +121,7 @@
def __init__ (self, orig_filename):
if orig_filename:
- self.orig_filename = orig_filename
+ self.orig_filename = orig_filename
bspos = orig_filename.rfind("\\")
cpos = orig_filename.rfind(":")
spos = orig_filename.rfind("/")
Index: util.py
===================================================================
RCS file: /home/cvs/quixote/util.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- util.py 16 Oct 2002 01:21:32 -0000 1.3
+++ util.py 20 Nov 2002 19:43:22 -0000 1.4
@@ -14,16 +14,16 @@
"""xmlrpc(request:Request, func:callable) : string
Processes the body of an XML-RPC request, and calls 'func' with
- two arguments, a string containing the method name and a tuple of
- parameters.
+ two arguments, a string containing the method name and a tuple of
+ parameters.
"""
-
+
# Get contents of POST body
- method = request.environ['REQUEST_METHOD']
+ method = request.environ['REQUEST_METHOD']
if method != 'POST':
request.response.set_status(405, "Only the POST method is accepted")
return "XML-RPC handlers only accept the POST method."
-
+
length = int(request.environ['CONTENT_LENGTH'])
data = request.stdin.read(length)
@@ -42,6 +42,6 @@
else:
result = (result,)
result = xmlrpclib.dumps(result, methodresponse=1)
-
+
request.response.set_header('content-type', 'text/xml')
return result