Discussion:
(forward: melkjug r2045 - in melkjug/branches/opt: . melkjug/controllers)
Luke Tucker
2009-02-12 22:27:30 UTC
Permalink
The problem here was that it modified the value it was trying to
validate. When you posted the result back in next time, it wouldn't
validate because it would have lost the operator. I think the thing
to do if you don't want to copy (and you can't mutate) is to use an
iterator.

ll = iter(value)
operator = ll.next()
do_something(ll)

- Luke
---------- Forwarded message ----------
Date: Tue, Feb 10, 2009 at 11:34 AM
Subject: Re: [Melkjug SVN Commits] melkjug r2045 - in melkjug/
branches/opt: . melkjug/controllers
hey luke,
thanks for tuning this up. the recursive call in the for loop rather
than the len(..) == 1 check is much nicer. wanted to ask about the
- operator, operands = value.pop(0), value
+ operator, operands = value[0], value[1:]
I had actually originally written it the second way, but then
realized that the first way is more space-efficient and equally time-
efficient. did you change it because the second way is clearer and
it won't matter with small lists?
Author: ltucker
Date: 2009-02-10 11:23:45 -0500 (Tue, 10 Feb 2009)
New Revision: 2045
melkjug/branches/opt/development.ini
melkjug/branches/opt/melkjug/controllers/composite.py
tune up mixing spec validator
Modified: melkjug/branches/opt/development.ini
===================================================================
--- melkjug/branches/opt/development.ini 2009-02-10 15:53:32
UTC (rev 2044)
+++ melkjug/branches/opt/development.ini 2009-02-10 16:23:45
UTC (rev 2045)
@@ -139,7 +139,7 @@
# Logging configuration
[loggers]
-keys = root, melkjug, minibrain, spider, filter, monolith
+keys = root, melkjug, minibrain, spider, filter, monolith, eval
[handlers]
keys = console
@@ -166,6 +166,11 @@
handlers =
qualname = melk.silo.monolith.lith
+[logger_eval]
+level = INFO
+handlers =
+qualname = melk.model.evaluator
+
[logger_spider]
level = DEBUG
handlers =
@@ -173,7 +178,7 @@
[logger_filter]
level = DEBUG
-handlers =
+handlers =
qualname = minibrain.workers.filterrunner
[handler_console]
Modified: melkjug/branches/opt/melkjug/controllers/composite.py
===================================================================
--- melkjug/branches/opt/melkjug/controllers/composite.py
2009-02-10 15:53:32 UTC (rev 2044)
+++ melkjug/branches/opt/melkjug/controllers/composite.py
2009-02-10 16:23:45 UTC (rev 2045)
@@ -104,26 +104,36 @@
MinLength(2),
MaxLength(128))
-
messages = {
- 'notlist': 'expected a list with at least two elements',
+ 'badlist': 'expected a list with at least two elements',
'badop': 'Invalid operator "%(op)s',
}
url = URL()
+
+ # could be just a URL.
- self.url.to_python(value)
+ self.url.validate_python(value, state)
return
+
+ # otherwise it must be a list starting with an operation,
+ # followed by a bunch of filterfuncs.
- raise Invalid(self.message('notlist', state), value,
state)
- operator, operands = value.pop(0), value
+ raise Invalid(self.message('badlist', state), value,
state)
+
+ operator, operands = value[0], value[1:]
+
+ # validate the operation...
if not isinstance(operator, basestring) or not
raise Invalid(self.message('badop', state, op=operator),
value, state)
- operands = operands[0]
- self.validate_python(operands, state)
+
+ # and each of the operands....
+ self.validate_python(operand, state)
+ # sounds good to me....
+
title = ScrubbedString()
type = URL()
@@ -137,7 +147,7 @@
# MaxLength(128),
# )
revision = Int()
- feeds = ForEach(URL())
+ feeds = ForEach(String())
filters = ForEach(FilterSchema())
allow_extra_fields = True
@@ -232,6 +242,8 @@
MixingSpecSchema.to_python(mixing_spec)
+ import traceback
+ log.error("Bad mixing spec: [%s]: %s" % (mixing_spec,
traceback.format_exc()))
abort(400)
# Extract feed info and convert into subscriptions...
--
for questions.
Loading...