mutagen/ogg.py
def find_last(fileobj, serial):
        """Find the last page of the stream 'serial'.

        If the file is not multiplexed this function is fast. If it is,
        it must read the whole the stream.

        This finds the last page in the actual file object, or the last
        page in the stream (with eos set), whichever comes first.
        """

        # For non-muxed streams, look at the last page.
        try:
            fileobj.seek(-256*256, 2)
        except IOError:
            # The file is less than 64k in length.
            fileobj.seek(0)
        data = fileobj.read()
        try:
            index = data.rindex(b"OggS")
        except ValueError:
            raise error("unable to find final Ogg header")
        bytesobj = cBytesIO(data[index:])
        best_page = None
        try:
            page = OggPage(bytesobj)
        except error:
            pass
        else:
            if page.serial == serial:
                if page.last:
                    return page
                else:
                    best_page = page
            else:
                best_page = None

        # The stream is muxed, so use the slow way.
        fileobj.seek(0)
        try:
            page = OggPage(fileobj)
            while not page.last:
                page = OggPage(fileobj)
                while page.serial != serial:
                    page = OggPage(fileobj)
                best_page = page
            return page
        except error:
            return best_page
        except EOFError:
            return best_page
def find_last(fileobj, serial):
        # For non-muxed streams, look at the last page.
        try:
            fileobj.seek(-256*256, 2)
        except IOError:
            # The file is less than 64k in length.
            fileobj.seek(0)
        data = fileobj.read()
        try:
            index = data.rindex(b"OggS")
        except ValueError:
            raise error("unable to find final Ogg header")
        bytesobj = cBytesIO(data[index:])
        best_page = None
        try:
            page = OggPage(bytesobj)
        except error:
            pass
        else:
            if page.serial == serial:
                if page.last:
                    return page
                else:
                    best_page = page
            else:
                best_page = None

        # The stream is muxed, so use the slow way.
        fileobj.seek(0)
        try:
            page = OggPage(fileobj)
            while not page.last:
                page = OggPage(fileobj)
                while page.serial != serial:
                    page = OggPage(fileobj)
                best_page = page
            return page
        except error:
            return best_page
        except EOFError:
            return best_page
def find_last ( fileobj , serial ) : # For non-muxed streams, look at the last page. try : fileobj . seek ( - 256 * 256 , 2 ) except IOError : # The file is less than 64k in length. fileobj . seek ( 0 ) data = fileobj . read ( ) try : index = data . rindex ( b"OggS" ) except ValueError : raise error ( "unable to find final Ogg header" ) bytesobj = cBytesIO ( data [ index : ] ) best_page = None try : page = OggPage ( bytesobj ) except error : pass else : if page . serial == serial : if page . last : return page else : best_page = page else : best_page = None # The stream is muxed, so use the slow way. fileobj . seek ( 0 ) try : page = OggPage ( fileobj ) while not page . last : page = OggPage ( fileobj ) while page . serial != serial : page = OggPage ( fileobj ) best_page = page return page except error : return best_page except EOFError : return best_page
Find the last page of the stream 'serial'.

        If the file is not multiplexed this function is fast. If it is,
        it must read the whole the stream.

        This finds the last page in the actual file object, or the last
        page in the stream (with eos set), whichever comes first.
Find the last page of the stream serial .