Calls to clevercss.convert(source, context) mutate context, replacing
string values with clevercss internal objects. This is surprising
behavior, makes context unusable for passing into subsequent calls to
convert(), and results in obtuse error messages. Here's an example:
>>> import clevercss
>>> template = """
... .highlight:
... background-color: $highlight_color
... """
>>> context = {'highlight_color': '#FFFF00'}
>>> print clevercss.convert(template, context)
.highlight {
background-color: #FFFF00;
}
>>> print context
{'highlight_color': Color(from_name=False, lineno=1, value=(255, 255,
0))}
>>> print clevercss.convert(template, context)
Traceback (most recent call last):
...
s = s.rstrip(';')
AttributeError: 'Color' object has no attribute 'rstrip'
Rather than wrapping my contexts in dict() each time, here is a patch
that does a shallow copy of context (and fixes the previously reported
missing None check that prevents context from being evaluated at all):
Change Engine.evaluate() from
def evaluate(self, context=None):
"""Evaluate code."""
expr = None
context = {}
...
to
def evaluate(self, context=None):
"""Evaluate code."""
expr = None
if context is None:
context = {}
else:
context = context.copy()
...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---