## The Python Imaging Library# $Id$## BUFR stub adapter## Copyright (c) 1996-2003 by Fredrik Lundh## See the README file for information on usage and redistribution.#from__future__importannotationsfromtypingimportIOfrom.importImage,ImageFile_handler=None
[docs]classBufrStubImageFile(ImageFile.StubImageFile):format="BUFR"format_description="BUFR"def_open(self)->None:offset=self.fp.tell()ifnot_accept(self.fp.read(4)):msg="Not a BUFR file"raiseSyntaxError(msg)self.fp.seek(offset)# make something upself._mode="F"self._size=1,1loader=self._load()ifloader:loader.open(self)def_load(self)->ImageFile.StubHandler|None:return_handler
def_save(im:Image.Image,fp:IO[bytes],filename:str|bytes)->None:if_handlerisNoneornothasattr(_handler,"save"):msg="BUFR save handler not installed"raiseOSError(msg)_handler.save(im,fp,filename)# --------------------------------------------------------------------# RegistryImage.register_open(BufrStubImageFile.format,BufrStubImageFile,_accept)Image.register_save(BufrStubImageFile.format,_save)Image.register_extension(BufrStubImageFile.format,".bufr")