1 #!/usr/bin/env python 2 3 """ 4 Core objects. 5 6 Copyright (C) 2015, 2016 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 from native import _get_using 23 24 class object: 25 26 "The root class of all objects except functions." 27 28 def __init__(self): 29 30 "No-operation." 31 32 pass 33 34 def __bool__(self): 35 36 "Objects are true by default." 37 38 return True 39 40 def __str__(self): 41 42 "Return a string representation." 43 44 return str(buffer(["<", self.__name__, " instance>"])) 45 46 __repr__ = __str__ 47 48 class module: 49 50 "The class of module objects." 51 52 def __str__(self): 53 54 "Return a string representation." 55 56 return self.__name__ 57 58 __repr__ = __str__ 59 60 class function: 61 62 """ 63 The class of all function objects. 64 Note that as a special case, function does not inherit from object. 65 """ 66 67 def __init__(self): 68 69 """ 70 Reserve special attributes for function instances. 71 """ 72 73 self.__fn__ = None 74 self.__args__ = None 75 self.__fname__ = None 76 77 def __bool__(self): 78 79 "Functions are true by default." 80 81 return True 82 83 def __str__(self): 84 85 "Return a string representation." 86 87 return self.__fname__ 88 89 __repr__ = __str__ 90 91 class type(object): 92 93 "The class of all classes." 94 95 # __str__ and __repr__ are handled by str and repr for classes. 96 97 pass 98 99 class BaseException: 100 101 "The root of all exception types." 102 103 pass 104 105 class Exception(BaseException): pass 106 class MemoryError(Exception): pass 107 class TypeError(Exception): pass 108 class UnboundMethodInvocation(Exception): pass 109 class Warning(object): pass 110 111 def get_using(callable, instance): 112 113 "Return 'callable' bound to 'instance'." 114 115 return _get_using(callable, instance) 116 117 # vim: tabstop=4 expandtab shiftwidth=4