SVN: r25337 - in trunk/quixote: . demo form2
Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Thu, 14 Oct 2004 13:09:07 -0400
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: nascheme
Date: 2004-10-14 13:08:56 -0400 (Thu, 14 Oct 2004)
New Revision: 25337
Modified:
trunk/quixote/_py_htmltext.py
trunk/quixote/config.py
trunk/quixote/demo/__init__.py
trunk/quixote/demo/forms.ptl
trunk/quixote/form2/compatibility.py
trunk/quixote/form2/form.py
trunk/quixote/form2/widget.py
trunk/quixote/http_request.py
trunk/quixote/http_response.py
trunk/quixote/ptl_import.py
trunk/quixote/publish.py
trunk/quixote/session.py
trunk/quixote/upload.py
trunk/quixote/util.py
Log:
use bool objects where appropriate
Modified: trunk/quixote/_py_htmltext.py
===================================================================
--- trunk/quixote/_py_htmltext.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/_py_htmltext.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -71,11 +71,11 @@
def __mod__(self, args):
codes = []
- usedict = 0
+ usedict = False
for format in _format_re.findall(self.s):
if format[-1] != '%':
if format[1] == '(':
- usedict = 1
+ usedict = True
codes.append(format[-1])
if usedict:
args = _DictWrapper(args)
@@ -208,7 +208,7 @@
__slots__ = ['html', 'data']
- def __init__(self, html=0):
+ def __init__(self, html=False):
self.html = html
self.data = []
Modified: trunk/quixote/config.py
===================================================================
--- trunk/quixote/config.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/config.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -65,34 +65,34 @@
# If true, then any "resource not found" errors will result in a
# consistent, terse, mostly-useless message. If false, then the
# exact cause of failure will be returned.
-SECURE_ERRORS = 1
+SECURE_ERRORS = True
# If true, Quixote will service exactly one request at a time, and
# then exit. This makes no difference when you're running as a
# straight CGI script, but it makes it easier to debug while running
# as a FastCGI script.
-RUN_ONCE = 0
+RUN_ONCE = False
# Automatically redirect paths referencing non-callable objects to a path
# with a trailing slash. This is convienent for external users of the
# site but should be disabled for development. Internal links on the
# site should not require redirects. They are costly, especially on high
# latency links like dialup lines.
-FIX_TRAILING_SLASH = 1
+FIX_TRAILING_SLASH = True
# Compress large pages using gzip if the client accepts that encoding.
-COMPRESS_PAGES = 0
+COMPRESS_PAGES = False
# If true, then a cryptographically secure token will be inserted into forms
# as a hidden field. The token will be checked when the form is submitted.
# This prevents cross-site request forgeries (CSRF). It is off by default
# since it doesn't work if sessions are not persistent across requests.
-FORM_TOKENS = 0
+FORM_TOKENS = False
# If true, the remote IP address of requests will be checked against the
# IP address that created the session; this is a defense against playback
# attacks. It will frustrate mobile laptop users, though.
-CHECK_SESSION_ADDR = 0
+CHECK_SESSION_ADDR = False
# Session-related variables
# =========================
@@ -210,7 +210,7 @@
]
- def __init__(self, read_defaults=1):
+ def __init__(self, read_defaults=True):
for var in self.config_vars:
setattr(self, var, None)
if read_defaults:
Modified: trunk/quixote/demo/__init__.py
===================================================================
--- trunk/quixote/demo/__init__.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/demo/__init__.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -37,5 +37,5 @@
import os
from quixote.demo import forms
curdir = os.path.dirname(forms.__file__)
-srcdir = StaticDirectory(curdir, list_directory=1)
+srcdir = StaticDirectory(curdir, list_directory=True)
q_ico = StaticFile(os.path.join(curdir, 'q.ico'))
Modified: trunk/quixote/demo/forms.ptl
===================================================================
--- trunk/quixote/demo/forms.ptl 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/demo/forms.ptl 2004-10-14 17:08:56 UTC (rev 25337)
@@ -34,9 +34,9 @@
# build form
Form.__init__(self)
self.add_widget("string", "name", title="Your Name",
- size=20, required=1)
+ size=20, required=True)
self.add_widget("password", "password", title="Password",
- size=20, maxlength=20, required=1)
+ size=20, maxlength=20, required=True)
self.add_widget("checkbox", "confirm",
title="Are you sure?")
self.add_widget("radiobuttons", "color", title="Eye color",
Modified: trunk/quixote/form2/compatibility.py
===================================================================
--- trunk/quixote/form2/compatibility.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/form2/compatibility.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -35,7 +35,7 @@
self.cancel_url = None
def add_widget(self, widget_class, name, value=None,
- title=None, hint=None, required=0, **kwargs):
+ title=None, hint=None, required=False, **kwargs):
try:
widget_class = _widget_names[widget_class]
except KeyError:
Modified: trunk/quixote/form2/form.py
===================================================================
--- trunk/quixote/form2/form.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/form2/form.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -13,15 +13,6 @@
IntWidget
-try:
- True, False, bool
-except NameError:
- True = 1
- False = 0
- def bool(v):
- return not not v
-
-
class FormTokenWidget(HiddenWidget):
def _parse(self, request):
Modified: trunk/quixote/form2/widget.py
===================================================================
--- trunk/quixote/form2/widget.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/form2/widget.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -11,13 +11,6 @@
from quixote.html import htmltext, htmlescape, htmltag, TemplateIO
from quixote.upload import Upload
-try:
- True, False
-except NameError:
- True = 1
- False = 0
-
-
def subname(prefix, name):
"""Create a unique name for a sub-widget or sub-component."""
# $ is nice because it's valid as part of a Javascript identifier
Modified: trunk/quixote/http_request.py
===================================================================
--- trunk/quixote/http_request.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/http_request.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -450,7 +450,7 @@
# guess_browser_version ()
- def redirect(self, location, permanent=0):
+ def redirect(self, location, permanent=False):
"""redirect(location : string, permanent : boolean = false)
-> string
Modified: trunk/quixote/http_response.py
===================================================================
--- trunk/quixote/http_response.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/http_response.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -140,7 +140,7 @@
self.cookies = {}
self.cache = 0
- self.buffered = 1
+ self.buffered = True
self.javascript_code = None
def set_status(self, status, reason=None):
@@ -269,7 +269,7 @@
elif not self.javascript_code.has_key(code_id):
self.javascript_code[code_id] = code
- def redirect(self, location, permanent=0):
+ def redirect(self, location, permanent=False):
"""Cause a redirection without raising an error"""
if not isinstance(location, StringType):
raise TypeError, "location must be a string (got %s)" % `location`
Modified: trunk/quixote/ptl_import.py
===================================================================
--- trunk/quixote/ptl_import.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/ptl_import.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -136,7 +136,7 @@
__builtin__.reload = cimport.reload_module
__builtin__.unload = self.unload
-_installed = 0
+_installed = False
def install():
global _installed
@@ -148,7 +148,7 @@
else:
importer = ihooks.ModuleImporter(loader)
ihooks.install(importer)
- _installed = 1
+ _installed = True
if __name__ == '__main__':
Modified: trunk/quixote/publish.py
===================================================================
--- trunk/quixote/publish.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/publish.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -117,7 +117,7 @@
# for PublishError exception handling
self.namespace_stack = [self.root_namespace]
- self.exit_now = 0
+ self.exit_now = False
self.access_log = None
self.error_log = sys.stderr # possibly overridden in setup_logs()
sys.stdout = self.error_log # print is handy for debugging
@@ -459,7 +459,7 @@
except SystemExit:
output = "SystemExit exception caught, shutting down"
self.log(output)
- self.exit_now = 1
+ self.exit_now = True
if output is None:
raise RuntimeError, 'callable %s returned None' % repr(object)
@@ -674,7 +674,7 @@
# we'll wind up here again with path == '/'.
if (not path and fix_trailing_slash):
request.redirect(request.environ['SCRIPT_NAME'] + '/' ,
- permanent=1)
+ permanent=True)
return None
# replace repeated slashes with a single slash
@@ -706,7 +706,7 @@
# This is for the convenience of users who type in paths.
# Repair the path and redirect. This should not happen for
# URLs within the site.
- request.redirect(request.get_path() + "/", permanent=1)
+ request.redirect(request.get_path() + "/", permanent=True)
return None
else:
@@ -869,7 +869,7 @@
global _publisher
return _publisher.get_request().get_path(n)
-def redirect(location, permanent=0):
+def redirect(location, permanent=False):
global _publisher
return _publisher.get_request().redirect(location, permanent)
Modified: trunk/quixote/session.py
===================================================================
--- trunk/quixote/session.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/session.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -365,7 +365,7 @@
pass
request.session = None
- def has_session_cookie(self, request, must_exist=0):
+ def has_session_cookie(self, request, must_exist=False):
"""has_session_cookie(request : HTTPRequest,
must_exist : boolean = false)
-> boolean
@@ -379,11 +379,11 @@
config = get_publisher().config
id = request.cookies.get(config.session_cookie_name)
if id is None:
- return 0
+ return False
if must_exist:
return self.has_session(id)
else:
- return 1
+ return True
# SessionManager
@@ -460,9 +460,9 @@
a hash file, is_dirty() should probably be an alias or wrapper
for has_info(). See doc/session-mgmt.txt.
"""
- return 0
+ return False
- def dump(self, file=None, header=1, deep=1):
+ def dump(self, file=None, header=True, deep=True):
time_fmt = "%Y-%m-%d %H:%M:%S"
ctime = strftime(time_fmt, localtime(self._creation_time))
atime = strftime(time_fmt, localtime(self._access_time))
Modified: trunk/quixote/upload.py
===================================================================
--- trunk/quixote/upload.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/upload.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -57,7 +57,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:
- return 1
+ return True
# Strip (but remember) line ending.
if line[-2:] == CRLF:
@@ -75,9 +75,9 @@
# comes after an uploaded file's contents and the following
# boundary line.
if line == next: # hit boundary, but more to come
- return 0
+ return False
elif line == last: # final boundary -- no more to read
- return 1
+ return True
if lines is not None:
lines.append(line)
@@ -326,7 +326,7 @@
def parse_body(self, file, boundary):
total_bytes = 0 # total bytes read from 'file'
- done = 0
+ done = False
while not done:
headers = Message(file)
cdisp = headers.get('content-disposition')
Modified: trunk/quixote/util.py
===================================================================
--- trunk/quixote/util.py 2004-10-14 17:05:37 UTC (rev 25336)
+++ trunk/quixote/util.py 2004-10-14 17:08:56 UTC (rev 25337)
@@ -126,7 +126,7 @@
Wrapper for a static file on the filesystem.
"""
- def __init__(self, path, follow_symlinks=0,
+ def __init__(self, path, follow_symlinks=False,
mime_type=None, encoding=None, cache_time=None):
"""StaticFile(path:string, follow_symlinks:bool)
@@ -154,7 +154,7 @@
# Decide the Content-Type of the file
guess_mime, guess_enc = mimetypes.guess_type(os.path.basename(path),
- strict=0)
+ strict=False)
self.mime_type = mime_type or guess_mime or 'text/plain'
self.encoding = encoding or guess_enc or None
self.cache_time = cache_time
@@ -196,11 +196,12 @@
FILE_CLASS = StaticFile
- def __init__(self, path, use_cache=0, list_directory=0, follow_symlinks=0,
- cache_time=None, file_class=None, index_filenames=None):
- """StaticDirectory(path:string, use_cache:bool, list_directory:bool,
- follow_symlinks:bool, cache_time:int,
- file_class=None, index_filenames:[string])
+ def __init__(self, path, use_cache=False, list_directory=False,
+ follow_symlinks=0, cache_time=None, file_class=None,
+ index_filenames=None):
+ """(path:string, use_cache:bool, list_directory:bool,
+ follow_symlinks:bool, cache_time:int,
+ file_class=None, index_filenames:[string])
Initialize instance with the absolute path to the file.
If 'use_cache' is true, StaticFile instances will be cached in memory.
@@ -316,7 +317,7 @@
_q_exports = []
- def __init__(self, location, permanent=0):
+ def __init__(self, location, permanent=False):
self.location = location
self.permanent = permanent
@@ -330,7 +331,7 @@
def dump_request(request):
"""Dump an HTTPRequest object as HTML."""
row_fmt = htmltext('<tr><th>%s</th><td>%s</td></tr>')
- r = TemplateIO(html=1)
+ r = TemplateIO(html=True)
r += htmltext('<h3>form</h3>'
'<table>')
for k, v in self.form.items():