Author: justi9
Date: 2009-06-17 15:33:19 -0400 (Wed, 17 Jun 2009)
New Revision: 3455
Modified:
mgmt/trunk/wooly/python/wooly/__init__.py
Log:
* Add a ListAttribute class for that fairly common case
* Add a 'test' method to widget for testing assertions and reporting
which widget failures come from
* Refactor debug output on page failure; make it less verbose, with
more of the stuff we care about
Modified: mgmt/trunk/wooly/python/wooly/__init__.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/__init__.py 2009-06-17 17:58:35 UTC (rev 3454)
+++ mgmt/trunk/wooly/python/wooly/__init__.py 2009-06-17 19:33:19 UTC (rev 3455)
@@ -59,6 +59,13 @@
def __repr__(self):
return "%s('%s')" % (self.__class__.__name__, self.path)
+class ListAttribute(Attribute):
+ def get_default(self, session):
+ return list()
+
+ def add(self, session, value, key=None):
+ self.get(session).append(value)
+
class Parameter(Attribute):
def __init__(self, app, name):
super(Parameter, self).__init__(app, name)
@@ -114,10 +121,17 @@
self.__main_tmpl = Template(self, "html")
self.__defer_tmpl = Template(self, "deferred_html")
+ def test(self, expr, message=None):
+ if not expr:
+ if not message:
+ message = "Correctness breached"
+
+ raise Exception("[%s] %s" % (self, message))
+
def init(self):
#print "Initializing %s" % str(self)
- assert not self.sealed
+ self.test(not self.sealed)
ancestors = list()
widget = self.parent
@@ -139,7 +153,7 @@
self.page = self.ancestors[-1]
- assert isinstance(self.page, Page)
+ self.test(isinstance(self.page, Page))
self.page.init_widget(self)
@@ -158,21 +172,25 @@
child.init()
def add_child(self, child):
- assert not self.sealed
- assert child is not None
- assert child is not self
+ self.test(not self.sealed)
+ self.test(isinstance(child, Widget))
+ self.test(child is not self)
self.children.append(child)
self.children_by_name[child.name] = child
child.parent = self
def add_attribute(self, attribute):
- assert not self.sealed
+ self.test(not self.sealed)
+ self.test(isinstance(attribute, Attribute))
+
self.attributes.append(attribute)
attribute.widget = self
def add_parameter(self, parameter):
- assert not self.sealed
+ self.test(not self.sealed)
+ self.test(isinstance(parameter, Parameter))
+
self.parameters.append(parameter)
parameter.widget = self
@@ -206,7 +224,7 @@
return str
def show(self, session):
- assert self.parent
+ self.test(self.parent)
self.parent.show_child(session, self)
self.parent.show(session)
@@ -345,8 +363,8 @@
self.add_attribute(self.redirect)
def init(self):
- assert not self.sealed
- assert self.parent is None
+ self.test(not self.sealed)
+ self.test(self.parent is None)
self.ancestors = ()
self.path = ""
@@ -359,15 +377,15 @@
self.sealed = True
def init_widget(self, widget):
- assert not self.sealed
- assert isinstance(widget, Widget)
+ self.test(not self.sealed)
+ self.test(isinstance(widget, Widget))
self.page_widgets.append(widget)
self.page_widgets_by_path[widget.path] = widget
def init_parameter(self, param):
- assert not self.sealed
- assert isinstance(param, Parameter)
+ self.test(not self.sealed)
+ self.test(isinstance(param, Parameter))
self.page_parameters.append(param)
self.page_parameters_by_path[param.path] = param
@@ -497,14 +515,34 @@
self.processed_list = list()
self.rendered_list = list()
- def print_process_calls(self, out=sys.stdout):
+ def write(self, writer):
+ writer.write(str(self.session))
+ writer.write(os.linesep)
+
+ for item in sorted(self.session.values_by_path.items()):
+ writer.write(" %s = %s" % item)
+ writer.write(os.linesep)
+
if self.process_stack:
- self.process_stack[0].write(out)
+ writer.write(os.linesep)
+ writer.write("process trace:")
+ writer.write(os.linesep)
- def print_render_calls(self, out=sys.stdout):
+ for call in self.process_stack:
+ writer.write(" ")
+ call.write(writer)
+ writer.write(os.linesep)
+
if self.render_stack:
- self.render_stack[0].write(out)
+ writer.write(os.linesep)
+ writer.write("render trace:")
+ writer.write(os.linesep)
+ for call in self.render_stack:
+ writer.write(" ")
+ call.write(writer)
+ writer.write(os.linesep)
+
def print_last_call(self, out=sys.stdout):
if self.render_stack:
self.render_stack[-1].write(out)
@@ -871,7 +909,6 @@
self.widget = widget
self.session = session
self.session_values = copy(session.values_by_path)
- self.object = object
self.caller = None
self.callees = list()
@@ -891,36 +928,19 @@
def close(self):
self.end = clock()
- if len(self.stack) > 1:
- self.stack.pop()
+ #if len(self.stack) > 1:
+ self.stack.pop()
def write(self, writer):
writer.write(str(self.widget))
- writer.write(" (call %i, caller %i)" % (id(self), id(self.caller)))
- writer.write(os.linesep)
+ writer.write(" [%i]" % id(self))
- writer.write(" session: " + str(self.session))
- writer.write(os.linesep)
-
- for item in sorted(self.session_values.items()):
- writer.write(" value: %s = %s" % item)
- writer.write(os.linesep)
-
- writer.write(" object: " + str(self.object))
- writer.write(os.linesep)
-
- writer.write(" times: %f, %f" % (self.start, self.end or -1))
- writer.write(os.linesep)
-
- for call in self.callees:
- call.write(writer)
-
class FullPageNotify(Widget):
def __init__(self, app, name):
super(FullPageNotify, self).__init__(app, name)
self.fullpage = Parameter(app, "fullpage")
- self.add_attribute(self.fullpage)
+ self.add_attribute(self.fullpage)
def get_fullpage(self, session):
return self.fullpage.get(session)