1.1 --- a/lib/builtins.py Sat Apr 30 23:36:09 2011 +0200
1.2 +++ b/lib/builtins.py Sun May 01 00:37:51 2011 +0200
1.3 @@ -2,7 +2,8 @@
1.4
1.5 """
1.6 Simple built-in classes and functions. Objects which provide code that shall
1.7 -always be compiled should provide docstrings.
1.8 +always be compiled should provide docstrings. Objects without code should be
1.9 +provided by native library code.
1.10
1.11 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Paul Boddie <paul@boddie.org.uk>
1.12
1.13 @@ -447,7 +448,21 @@
1.14 def eval(source, globals=None, locals=None): pass
1.15 def execfile(filename, globals=None, locals=None): pass
1.16 def filter(function, sequence): pass
1.17 -def getattr(obj, name, default=None): pass
1.18 +
1.19 +def getattr(obj, name, default=object()): # object() is a placeholder
1.20 +
1.21 + "Implementation of getattr."
1.22 +
1.23 + _accessor # avoid isinstance but ensure that this class is included
1.24 +
1.25 + try:
1.26 + return _getattr(obj, name)
1.27 + except AttributeError:
1.28 + if default is not NotImplemented:
1.29 + return default
1.30 + else:
1.31 + raise
1.32 +
1.33 def globals(): pass
1.34 def hasattr(obj, name): pass
1.35 def hash(obj): pass
1.36 @@ -611,8 +626,19 @@
1.37 start += 1
1.38 return result
1.39
1.40 +# Special implementation classes.
1.41 +
1.42 +class _accessor(str):
1.43 +
1.44 + "A string which can be used to access attributes."
1.45 +
1.46 + def __new__(self):
1.47 + # Reserve space for an object table index.
1.48 + self._index = None
1.49 +
1.50 # Special implementation functions.
1.51
1.52 +def _getattr(obj, name): pass
1.53 def _isinstance(obj, cls): pass
1.54 def _print(dest, *args): pass
1.55 def _printnl(dest, *args): pass