1.1 --- a/micropython/data.py Tue Apr 07 00:57:04 2009 +0200
1.2 +++ b/micropython/data.py Mon Apr 20 01:50:00 2009 +0200
1.3 @@ -44,7 +44,7 @@
1.4 where each such object is defined.
1.5 """
1.6
1.7 -from micropython.common import *
1.8 +from micropython.program import DataObject
1.9
1.10 def shortrepr(obj):
1.11 if obj is None:
1.12 @@ -52,8 +52,63 @@
1.13 else:
1.14 return obj.__shortrepr__()
1.15
1.16 +# Special representations.
1.17 +
1.18 +class AtLeast:
1.19 +
1.20 + "A special representation for numbers of a given value or greater."
1.21 +
1.22 + def __init__(self, count):
1.23 + self.count = count
1.24 +
1.25 + def __eq__(self, other):
1.26 + return 0
1.27 +
1.28 + __lt__ = __le__ = __eq__
1.29 +
1.30 + def __ne__(self, other):
1.31 + return 1
1.32 +
1.33 + def __gt__(self, other):
1.34 + if isinstance(other, AtLeast):
1.35 + return 0
1.36 + else:
1.37 + return self.count > other
1.38 +
1.39 + def __ge__(self, other):
1.40 + if isinstance(other, AtLeast):
1.41 + return 0
1.42 + else:
1.43 + return self.count >= other
1.44 +
1.45 + def __iadd__(self, other):
1.46 + if isinstance(other, AtLeast):
1.47 + self.count += other.count
1.48 + else:
1.49 + self.count += other
1.50 + return self
1.51 +
1.52 + def __radd__(self, other):
1.53 + if isinstance(other, AtLeast):
1.54 + return AtLeast(self.count + other.count)
1.55 + else:
1.56 + return AtLeast(self.count + other)
1.57 +
1.58 + def __repr__(self):
1.59 + return "AtLeast(%r)" % self.count
1.60 +
1.61 # Mix-ins and abstract classes.
1.62
1.63 +class Naming:
1.64 +
1.65 + "A mix-in providing naming conveniences."
1.66 +
1.67 + def full_name(self):
1.68 + if self.name is not None:
1.69 + return self.parent.full_name() + "." + self.name
1.70 + else:
1.71 + return self.parent.full_name()
1.72 +
1.73 class NamespaceDict:
1.74
1.75 "A mix-in providing dictionary methods."