paul@6 | 1 | #!/usr/bin/env python |
paul@6 | 2 | |
paul@6 | 3 | """ |
paul@6 | 4 | List objects. |
paul@6 | 5 | |
paul@9 | 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@9 | 22 | from __builtins__.iterator import listiterator |
paul@9 | 23 | from __builtins__.sequence import _getitem, _getslice |
paul@140 | 24 | import native |
paul@6 | 25 | |
paul@6 | 26 | class list(object): |
paul@6 | 27 | |
paul@6 | 28 | "Implementation of list." |
paul@6 | 29 | |
paul@6 | 30 | def __init__(self, args=None): |
paul@6 | 31 | |
paul@6 | 32 | "Initialise the list." |
paul@6 | 33 | |
paul@6 | 34 | if args is not None: |
paul@6 | 35 | self.extend(args) |
paul@6 | 36 | |
paul@6 | 37 | # Reserve space for a fragment reference. |
paul@140 | 38 | |
paul@140 | 39 | self.__data__ = None |
paul@6 | 40 | |
paul@6 | 41 | def __getitem__(self, index): |
paul@6 | 42 | |
paul@6 | 43 | "Return the item or slice specified by 'index'." |
paul@6 | 44 | |
paul@6 | 45 | return _getitem(self, index) |
paul@6 | 46 | |
paul@6 | 47 | def __contains__(self, value): pass |
paul@6 | 48 | def __setitem__(self, index, value): pass |
paul@6 | 49 | def __delitem__(self, index): pass |
paul@6 | 50 | |
paul@6 | 51 | def __getslice__(self, start, end=None): |
paul@6 | 52 | |
paul@6 | 53 | "Return a slice starting from 'start', with the optional 'end'." |
paul@6 | 54 | |
paul@6 | 55 | return _getslice(self, start, end) |
paul@6 | 56 | |
paul@6 | 57 | def __setslice__(self, start, end, slice): pass |
paul@6 | 58 | def __delslice__(self, start, end): pass |
paul@6 | 59 | def append(self, value): pass |
paul@6 | 60 | def insert(self, i, value): pass |
paul@6 | 61 | |
paul@6 | 62 | def extend(self, iterable): |
paul@6 | 63 | |
paul@6 | 64 | "Extend the list with the contents of 'iterable'." |
paul@6 | 65 | |
paul@6 | 66 | for i in iterable: |
paul@6 | 67 | self.append(i) |
paul@6 | 68 | |
paul@6 | 69 | def pop(self): pass |
paul@6 | 70 | def reverse(self): pass |
paul@6 | 71 | def sort(self, cmp=None, key=None, reverse=0): pass |
paul@140 | 72 | |
paul@140 | 73 | def __len__(self): |
paul@140 | 74 | |
paul@140 | 75 | "Return the length of the list." |
paul@140 | 76 | |
paul@140 | 77 | return native._list_len(self) |
paul@140 | 78 | |
paul@6 | 79 | def __add__(self, other): pass |
paul@6 | 80 | def __iadd__(self, other): pass |
paul@6 | 81 | def __str__(self): pass |
paul@6 | 82 | |
paul@6 | 83 | def __bool__(self): |
paul@6 | 84 | |
paul@6 | 85 | "Lists are true if non-empty." |
paul@6 | 86 | |
paul@140 | 87 | return native._list_nonempty(self) |
paul@6 | 88 | |
paul@6 | 89 | def __iter__(self): |
paul@6 | 90 | |
paul@6 | 91 | "Return an iterator." |
paul@6 | 92 | |
paul@6 | 93 | return listiterator(self) |
paul@6 | 94 | |
paul@6 | 95 | # Special implementation methods. |
paul@6 | 96 | |
paul@140 | 97 | def __get_single_item__(self, index): |
paul@140 | 98 | |
paul@140 | 99 | "Return the item at 'index'." |
paul@140 | 100 | |
paul@140 | 101 | return native._list_element(self, index) |
paul@6 | 102 | |
paul@6 | 103 | # vim: tabstop=4 expandtab shiftwidth=4 |