paul@6 | 1 | #!/usr/bin/env python |
paul@6 | 2 | |
paul@6 | 3 | """ |
paul@6 | 4 | Core objects. |
paul@6 | 5 | |
paul@107 | 6 | Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> |
paul@6 | 7 | |
paul@6 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@6 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@6 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@6 | 11 | version. |
paul@6 | 12 | |
paul@6 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@6 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@6 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@6 | 16 | details. |
paul@6 | 17 | |
paul@6 | 18 | You should have received a copy of the GNU General Public License along with |
paul@6 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@6 | 20 | """ |
paul@6 | 21 | |
paul@230 | 22 | from native import _get_using |
paul@230 | 23 | |
paul@6 | 24 | class object: |
paul@107 | 25 | |
paul@107 | 26 | "The root class of all objects except functions." |
paul@107 | 27 | |
paul@6 | 28 | def __init__(self): |
paul@230 | 29 | |
paul@6 | 30 | "No-operation." |
paul@230 | 31 | |
paul@6 | 32 | pass |
paul@107 | 33 | |
paul@6 | 34 | def __bool__(self): |
paul@230 | 35 | |
paul@6 | 36 | "Objects are true by default." |
paul@230 | 37 | |
paul@6 | 38 | return True |
paul@6 | 39 | |
paul@230 | 40 | def __str__(self): |
paul@230 | 41 | |
paul@230 | 42 | "Return a string representation." |
paul@230 | 43 | |
paul@230 | 44 | return self.__name__ |
paul@230 | 45 | |
paul@230 | 46 | __repr__ = __str__ |
paul@230 | 47 | |
paul@107 | 48 | class function: |
paul@107 | 49 | |
paul@107 | 50 | """ |
paul@107 | 51 | The class of all function objects. |
paul@107 | 52 | Note that as a special case, function does not inherit from object. |
paul@107 | 53 | """ |
paul@107 | 54 | |
paul@6 | 55 | def __init__(self): |
paul@6 | 56 | |
paul@107 | 57 | """ |
paul@107 | 58 | Reserve special attributes for function instances. |
paul@107 | 59 | """ |
paul@6 | 60 | |
paul@6 | 61 | self.__fn__ = None |
paul@6 | 62 | self.__args__ = None |
paul@6 | 63 | |
paul@107 | 64 | def __bool__(self): |
paul@230 | 65 | |
paul@107 | 66 | "Functions are true by default." |
paul@230 | 67 | |
paul@107 | 68 | return True |
paul@107 | 69 | |
paul@230 | 70 | def __str__(self): |
paul@230 | 71 | |
paul@230 | 72 | "Return a string representation." |
paul@230 | 73 | |
paul@230 | 74 | return "<function>" # NOTE: Could be made specific. |
paul@230 | 75 | |
paul@230 | 76 | __repr__ = __str__ |
paul@230 | 77 | |
paul@6 | 78 | class type(object): |
paul@107 | 79 | |
paul@107 | 80 | "The class of all classes." |
paul@107 | 81 | |
paul@248 | 82 | # __str__ and __repr__ are handled by str and repr for classes. |
paul@230 | 83 | |
paul@248 | 84 | pass |
paul@6 | 85 | |
paul@233 | 86 | class BaseException: |
paul@233 | 87 | |
paul@233 | 88 | "The root of all exception types." |
paul@233 | 89 | |
paul@233 | 90 | pass |
paul@233 | 91 | |
paul@6 | 92 | class Exception(BaseException): pass |
paul@233 | 93 | class TypeError(Exception): pass |
paul@193 | 94 | class UnboundMethodInvocation(Exception): pass |
paul@6 | 95 | class Warning(object): pass |
paul@6 | 96 | |
paul@230 | 97 | def get_using(callable, instance): |
paul@230 | 98 | |
paul@230 | 99 | "Return 'callable' bound to 'instance'." |
paul@230 | 100 | |
paul@230 | 101 | return _get_using(callable, instance) |
paul@121 | 102 | |
paul@6 | 103 | # vim: tabstop=4 expandtab shiftwidth=4 |