micropython

lib/builtins.py

233:8abc113da24c
2009-06-01 Paul Boddie Fixed StoreCallable using a new DataObject method which replaces the address of the callable. Made a cmd module to handle common compilation and processing activities. Renamed MakeObject to MakeInstance. Changed FillDefaults to use the current value as a reference to the container holding the defaults. Removed the extra temporary storage slot previously used when adjusting frames. Changed lambda functions to use a context parameter, changing the image to not reserve space for defaults immediately after the header of such functions. Added notes about the issues with positioning keyword arguments. Expanded and improved the tests.
     1 #!/usr/bin/env python     2      3 """     4 Simple built-in classes and functions.     5      6 Copyright (C) 2005, 2006, 2007, 2008 Paul Boddie <paul@boddie.org.uk>     7      8 This program is free software; you can redistribute it and/or modify it under     9 the terms of the GNU General Public License as published by the Free Software    10 Foundation; either version 3 of the License, or (at your option) any later    11 version.    12     13 This program is distributed in the hope that it will be useful, but WITHOUT    14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    15 FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more    16 details.    17     18 You should have received a copy of the GNU General Public License along with    19 this program.  If not, see <http://www.gnu.org/licenses/>.    20 """    21     22 class object:    23     def __init__(self): pass    24     def __bool__(self): pass    25     def __iadd__(self, other): pass    26     27 class basestring(object):    28     def __init__(self, x=None): pass    29     def __getitem__(self, index): pass    30     def __getslice__(self, start, end=None): pass    31     def __iadd__(self, other): pass    32     def __add__(self, other): pass    33     def __radd__(self, other): pass    34     def __mul__(self, other): pass    35     def __rmul__(self, other): pass    36     def __mod__(self, other): pass    37     def __rmod__(self, other): pass    38     def __lt__(self, other): pass    39     def __gt__(self, other): pass    40     def __le__(self, other): pass    41     def __ge__(self, other): pass    42     def __eq__(self, other): pass    43     def __ne__(self, other): pass    44     def __len__(self): pass    45     def __str__(self): pass    46     def __bool__(self): pass    47     def join(self, l): pass    48     49 class bool(object):    50     def __bool__(self): pass    51     def __str__(self): pass    52     53 class buffer(object):    54     def __init__(self, size): pass    55     def append(self, s): pass    56     def __str__(self): pass    57     58 class complex(object):    59     def __init__(self, real, imag=None): pass    60     61 class dict(object):    62     def __init__(self, *args): pass    63     def __setitem__(self, key, value): pass    64     def __getitem__(self, key): pass    65     66 class file(object):    67     def write(self, s): pass    68     69 class float(object):    70     def __init__(self, number_or_string=None): pass    71     def __iadd__(self, other): pass    72     def __isub__(self, other): pass    73     def __add__(self, other): pass    74     def __radd__(self, other): pass    75     def __sub__(self, other): pass    76     def __rsub__(self, other): pass    77     def __mul__(self, other): pass    78     def __rmul__(self, other): pass    79     def __div__(self, other): pass    80     def __rdiv__(self, other): pass    81     def __floordiv__(self, other): pass    82     def __rfloordiv__(self, other): pass    83     def __mod__(self, other): pass    84     def __rmod__(self, other): pass    85     def __pow__(self, other): pass    86     def __rpow__(self, other): pass    87     def __lt__(self, other): pass    88     def __gt__(self, other): pass    89     def __le__(self, other): pass    90     def __ge__(self, other): pass    91     def __eq__(self, other): pass    92     def __ne__(self, other): pass    93     def __neg__(self): pass    94     def __pos__(self): pass    95     def __str__(self): pass    96     def __bool__(self): pass    97     98 class frozenset(object):    99     def __init__(self, iterable): pass   100    101 class function(object):   102     pass   103    104 class int(object):   105     def __init__(self, number_or_string=None): pass   106     def __iadd__(self, other): pass   107     def __isub__(self, other): pass   108     def __add__(self, other): pass   109     def __radd__(self, other): pass   110     def __sub__(self, other): pass   111     def __rsub__(self, other): pass   112     def __mul__(self, other): pass   113     def __rmul__(self, other): pass   114     def __div__(self, other): pass   115     def __rdiv__(self, other): pass   116     def __floordiv__(self, other): pass   117     def __rfloordiv__(self, other): pass   118     def __mod__(self, other): pass   119     def __rmod__(self, other): pass   120     def __pow__(self, other): pass   121     def __rpow__(self, other): pass   122     def __and__(self, other): pass   123     def __rand__(self, other): pass   124     def __or__(self, other): pass   125     def __ror__(self, other): pass   126     def __xor__(self, other): pass   127     def __rxor__(self, other): pass   128     def __lt__(self, other): pass   129     def __gt__(self, other): pass   130     def __le__(self, other): pass   131     def __ge__(self, other): pass   132     def __eq__(self, other): pass   133     def __ne__(self, other): pass   134     def __neg__(self): pass   135     def __pos__(self): pass   136     def __str__(self): pass   137     def __bool__(self): pass   138    139 class list(object):   140     def __init__(self, args=()): pass   141     def __getitem__(self, index): pass   142     def __setitem__(self, index, value): pass   143     def __getslice__(self, start, end=None): pass   144     def __setslice__(self, start, end, slice): pass   145     def append(self, value): pass   146     def __len__(self): pass   147     def __add__(self, other): pass   148     def __iadd__(self, other): pass   149     def __str__(self): pass   150     def __iter__(self): pass   151     def __bool__(self): pass   152    153 class long(object):   154     def __init__(self, number_or_string=None): pass   155     def __iadd__(self, other): pass   156     def __isub__(self, other): pass   157     def __add__(self, other): pass   158     def __radd__(self, other): pass   159     def __sub__(self, other): pass   160     def __rsub__(self, other): pass   161     def __mul__(self, other): pass   162     def __rmul__(self, other): pass   163     def __div__(self, other): pass   164     def __rdiv__(self, other): pass   165     def __floordiv__(self, other): pass   166     def __rfloordiv__(self, other): pass   167     def __and__(self, other): pass   168     def __rand__(self, other): pass   169     def __or__(self, other): pass   170     def __ror__(self, other): pass   171     def __xor__(self, other): pass   172     def __rxor__(self, other): pass   173     def __lt__(self, other): pass   174     def __gt__(self, other): pass   175     def __le__(self, other): pass   176     def __ge__(self, other): pass   177     def __eq__(self, other): pass   178     def __ne__(self, other): pass   179     def __neg__(self): pass   180     def __pos__(self): pass   181     def __str__(self): pass   182     def __bool__(self): pass   183    184 class set(object):   185     def __init__(self, iterable): pass   186    187 class slice(object):   188     def __init__(self, start_or_end, end=None, step=None): pass   189    190 class str(basestring):   191     pass   192    193 class type(object):   194     pass   195    196 class tuple(object):   197     def __init__(self, args): pass   198     def __getitem__(self, index): pass   199     def __getslice__(self, start, end=None): pass   200     def __len__(self): pass   201     def __add__(self, other): pass   202     def __str__(self): pass   203     def __iter__(self): pass   204     def __bool__(self): pass   205    206 class unicode(basestring):   207     pass   208    209 class xrange(object):   210     def __init__(self, start_or_end, end=None, step=1): pass   211     def __iter__(self): pass   212     def next(self): pass   213    214 # Exceptions and warnings.   215    216 class BaseException(object):   217     def __init__(self, *args): pass   218    219 class Exception(BaseException): pass   220 class Warning(object): pass   221    222 class ArithmeticError(Exception): pass   223 class AssertionError(Exception): pass   224 class AttributeError(Exception): pass   225 class DeprecationWarning(Exception): pass   226 class EOFError(Exception): pass   227 class EnvironmentError(Exception): pass   228 class FloatingPointError(Exception): pass   229 class FutureWarning(Warning): pass   230 class GeneratorExit(Exception): pass   231 class ImportError(Exception): pass   232 class ImportWarning(Warning): pass   233 class IndentationError(Exception): pass   234 class IndexError(Exception): pass   235 class IOError(Exception): pass   236 class KeyError(Exception): pass   237 class KeyboardInterrupt(Exception): pass   238 class LookupError(Exception): pass   239 class MemoryError(Exception): pass   240 class NameError(Exception): pass   241 class NotImplementedError(Exception): pass   242 class OSError(Exception): pass   243 class OverflowError(Exception): pass   244 class PendingDeprecationWarning(Warning): pass   245 class ReferenceError(Exception): pass   246 class RuntimeError(Exception): pass   247 class RuntimeWarning(Warning): pass   248 class StandardError(Exception): pass   249 class StopIteration(Exception): pass   250 class SyntaxError(Exception): pass   251 class SyntaxWarning(Warning): pass   252 class SystemError(Exception): pass   253 class SystemExit(Exception): pass   254 class TabError(Exception): pass   255 class TypeError(Exception): pass   256 class UnboundLocalError(Exception): pass   257 class UnicodeDecodeError(Exception): pass   258 class UnicodeEncodeError(Exception): pass   259 class UnicodeError(Exception): pass   260 class UnicodeTranslateError(Exception): pass   261 class UnicodeWarning(Warning): pass   262 class UserWarning(Warning): pass   263 class ValueError(Exception): pass   264 class ZeroDivisionError(Exception): pass   265    266 # Various types.   267    268 #class ellipsis: pass   269 class NoneType: pass   270 class NotImplementedType: pass   271    272 # General functions.   273 # NOTE: Some of these are actually provided by classes in CPython.   274 # NOTE: We may refuse to support some of these in practice, such as...   275 # NOTE: super, reload.   276    277 def __import__(name, globals=None, locals=None, fromlist=None, level=-1): pass   278 def abs(number): pass   279 def all(iterable): pass   280 def any(iterable): pass   281 def callable(obj): pass   282 def chr(i): pass   283 def classmethod(function): pass   284 def cmp(x, y): pass   285 def compile(source, filename, mode, flags=None, dont_inherit=None): pass   286 def delattr(obj, name): pass   287 def dir(obj=None): pass   288 def divmod(x, y): pass   289 def enumerate(iterable): pass   290 def eval(source, globals=None, locals=None): pass   291 def execfile(filename, globals=None, locals=None): pass   292 def filter(function, sequence): pass   293 def getattr(obj, name, default=None): pass   294 def globals(): pass   295 def hasattr(obj, name): pass   296 def hash(obj): pass   297 def help(*args): pass   298 def hex(number): pass   299 def id(obj): pass   300 def input(prompt=None): pass   301 def isinstance(obj, cls_or_tuple): pass   302 def issubclass(obj, cls_or_tuple): pass   303 def iter(collection_or_callable, sentinel=None): pass   304 def len(obj): pass   305 def locals(): pass   306 def map(function, *args): pass   307 def max(*args): pass   308 def min(*args): pass   309 def oct(number): pass   310 def open(name, mode=None, buffering=None): pass   311 def ord(c): pass   312 def pow(x, y, z=None): pass   313 def property(fget=None, fset=None, fdel=None, doc=None): pass   314 def range(start_or_end, end=None, step=None): pass   315 def raw_input(prompt=None): pass   316 def reduce(function, sequence, initial=None): pass   317 def reload(module): pass   318 def repr(obj): pass   319 def reversed(sequence): pass   320 def round(number, ndigits=None): pass   321 def setattr(obj, name, value): pass   322 def sorted(iterable, cmp=None, key=None, reverse=False): pass   323 def staticmethod(function): pass   324 def sum(sequence, start=0): pass   325 def super(*args): pass   326 def unichr(i): pass   327 def vars(obj=None): pass   328 def zip(*args): pass   329    330 # Reference some names to ensure their existence. This should be everything   331 # mentioned in a get_builtin or load_builtin call. Instances from this module   332 # should be predefined constants.   333    334 function   335 AttributeError   336 StopIteration   337 TypeError   338 IndexError   339    340 list   341 tuple   342 #xrange   343 #ellipsis   344 #bool   345    346 # vim: tabstop=4 expandtab shiftwidth=4