def _convert_index(self, index): if isinstance(index, int): return str(index + 1) # -> matlab 1-based indexing elif isString(index): return self._matlab_str_repr(index) elif isinstance(index, slice): if index == slice(None, None, None): return ":" elif index.step not in (None, 1): raise ValueError("Illegal index for a proxy %r" % index) else: start = (index.start or 0) + 1 if start == 0: start_s = 'end' elif start < 0: start_s = 'end%d' % start else: start_s = '%d' % start if index.stop is None: stop_s = 'end' elif index.stop < 0: stop_s = 'end%d' % index.stop else: stop_s = '%d' % index.stop return '%s:%s' % (start_s, stop_s) else: raise TypeError("Unsupported index type: %r." % type(index))
def _convert_index(self, index): if isinstance(index, int): return str(index + 1) # -> matlab 1-based indexing elif isString(index): return self._matlab_str_repr(index) elif isinstance(index, slice): if index == slice(None,None,None): return ":" elif index.step not in (None,1): raise ValueError("Illegal index for a proxy %r" % index) else: start = (index.start or 0) + 1 if start == 0: start_s = 'end' elif start < 0: start_s = 'end%d' % start else: start_s = '%d' % start if index.stop is None: stop_s = 'end' elif index.stop < 0: stop_s = 'end%d' % index.stop else: stop_s = '%d' % index.stop return '%s:%s' % (start_s, stop_s) else: raise TypeError("Unsupported index type: %r." % type(index))
def convert_individual_index(index): if isinstance(index, int): # XXX there might be a better type-check if index < 0: return "end%+d" % (index+1) else: return str(index + 1) elif isString(index): return "'%s'" % index elif isinstance(index, slice): if index == slice(None,None,None): return ":" else: start, stop, step = index.start, index.stop, index.step if start is None: if (step or 1) < 0: mstart = 'end' else: mstart = '1' elif start < 0: mstart = 'end%d' % (start-1) else: mstart = str(start+1) if stop is None: if (step or 1) < 0: mstop = '1' else: mstop = 'end' elif stop < 0: mstop = 'end%d' % stop else: mstop = str(stop) print "DEBUG: ", mstart + ':' + str(step) + ':' + mstop if step is not None: return mstart + ':' + str(step) + ':' + mstop else: return mstart + ':' + mstop # XXX could also handle arrays, lists and tuples, but not right now else: raise TypeError("Unsupported proxy index type: %r." % type(index))