def __getitem__()

in pci_lib/pci_lib.py [0:0]


    def __getitem__(self, k):
        if isinstance(k, slice):
            if k.step is not None:
                raise Exception('Cannot step in PCI config space')
            start = k.start
            stop = k.stop
        else:
            raise Exception('Can only use slices to index config space')
        if stop > self.size:
            raise Exception(
                'Attempt to read at {}, past end of config space: {}'.format(
                    (start, stop), self
                )
            )
        data = self.cache[start:stop]
        if any(d is None for d in data):
            self.open()
            # Align to 32 bit words
            rstart, rstop = align32(start, stop)
            os.lseek(self.fd, rstart, os.SEEK_SET)
            data = os.read(self.fd, rstop - rstart)
            self.cache[rstart:rstop] = list(iterbytes(data))
            data = self.cache[start:stop]
        return b''.join(int2byte(b) for b in data)