1.1 --- a/micropython/data.py Wed Oct 23 18:18:30 2013 +0200
1.2 +++ b/micropython/data.py Thu Oct 24 13:54:07 2013 +0200
1.3 @@ -62,6 +62,26 @@
1.4 except NameError:
1.5 from sets import Set as set
1.6
1.7 +def get_context_and_value(value):
1.8 +
1.9 + "Return a context, value tuple for the given 'value'."
1.10 +
1.11 + # Functions have a replaceable context.
1.12 +
1.13 + if isinstance(value, Function):
1.14 + return (ReplaceableContext, value)
1.15 +
1.16 + # Classes use placeholder contexts which cannot be replaced but which
1.17 + # do not communicate useful contextual information.
1.18 +
1.19 + elif isinstance(value, Class):
1.20 + return (PlaceholderContext, value)
1.21 +
1.22 + # Other values employ themselves as the context.
1.23 +
1.24 + else:
1.25 + return (value, value)
1.26 +
1.27 class NamespaceDict(Namespace, BranchTracking):
1.28
1.29 "A mix-in providing dictionary methods."
1.30 @@ -126,7 +146,7 @@
1.31
1.32 def add_lambda(self, obj):
1.33 attr = Attr(None, self, obj.name)
1.34 - attr.update([self.get_context_and_value(obj)], single_assignment=1)
1.35 + attr.update([get_context_and_value(obj)], single_assignment=1)
1.36 self.lambdas[obj.name] = attr
1.37
1.38 # Specialised access methods.
1.39 @@ -249,30 +269,10 @@
1.40 if isinstance(attr_or_value, Attr):
1.41 context_values = self.get_updated_context_values(attr_or_value.context_values)
1.42 else:
1.43 - context_values = self.get_updated_context_values([self.get_context_and_value(attr_or_value)])
1.44 + context_values = self.get_updated_context_values([get_context_and_value(attr_or_value)])
1.45
1.46 attr.update(context_values, single_assignment)
1.47
1.48 - def get_context_and_value(self, value):
1.49 -
1.50 - "Return a context, value tuple for the given 'value'."
1.51 -
1.52 - # Functions have a replaceable context.
1.53 -
1.54 - if isinstance(value, Function):
1.55 - return (ReplaceableContext, value)
1.56 -
1.57 - # Classes use placeholder contexts which cannot be replaced but which
1.58 - # do not communicate useful contextual information.
1.59 -
1.60 - elif isinstance(value, Class):
1.61 - return (PlaceholderContext, value)
1.62 -
1.63 - # Other values employ themselves as the context.
1.64 -
1.65 - else:
1.66 - return (value, value)
1.67 -
1.68 def get_updated_context_values(self, context_values):
1.69
1.70 """