def __getitem__(self, i):
if isinstance(i, int):<EOL><INDENT>old, j = self.__i, i<EOL><DEDENT>else:<EOL><INDENT>old, j = self.__i, i.stop<EOL><DEDENT>while j is None or self.__i <= j:<EOL><INDENT>try:<EOL><INDENT>next(self)<EOL><DEDENT>except StopIteration:<EOL><INDENT>break<EOL><DEDENT><DEDENT>self.__i = old<EOL>if isinstance(i, int):<EOL><INDENT>return self.__queue[i]<EOL><DEDENT>return self.__join(self.__queue[i])<EOL>
Supports indexing list

        >>> b = Buffer('asdf')
        >>> b[5]
        Traceback (most recent call last):
            ...
        IndexError: list index out of range
        >>> b[0]
        'a'
        >>> b[1:3]
        'sd'
        >>> b[1:]
        'sdf'
        >>> b[:3]
        'asd'
        >>> b[:]
        'asdf'