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