mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Replaced KeyError catch with dictionary get method
This commit is contained in:
		
							parent
							
								
									0ae3e3b482
								
							
						
					
					
						commit
						f9a99652e4
					
				| 
						 | 
					@ -415,10 +415,7 @@ def _save(im, fp, filename, save_all=False):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_interlace(im):
 | 
					def get_interlace(im):
 | 
				
			||||||
    try:
 | 
					    interlace = im.encoderinfo.get("interlace", 1)
 | 
				
			||||||
        interlace = im.encoderinfo["interlace"]
 | 
					 | 
				
			||||||
    except KeyError:
 | 
					 | 
				
			||||||
        interlace = 1
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # workaround for @PIL153
 | 
					    # workaround for @PIL153
 | 
				
			||||||
    if min(im.size) < 16:
 | 
					    if min(im.size) < 16:
 | 
				
			||||||
| 
						 | 
					@ -484,10 +481,7 @@ def _get_local_header(fp, im, offset, flags):
 | 
				
			||||||
                 o8(0))
 | 
					                 o8(0))
 | 
				
			||||||
    include_color_table = im.encoderinfo.get('include_color_table')
 | 
					    include_color_table = im.encoderinfo.get('include_color_table')
 | 
				
			||||||
    if include_color_table:
 | 
					    if include_color_table:
 | 
				
			||||||
        try:
 | 
					        palette = im.encoderinfo.get("palette", None)
 | 
				
			||||||
            palette = im.encoderinfo["palette"]
 | 
					 | 
				
			||||||
        except KeyError:
 | 
					 | 
				
			||||||
            palette = None
 | 
					 | 
				
			||||||
        palette_bytes = _get_palette_bytes(im, palette, im.encoderinfo)[0]
 | 
					        palette_bytes = _get_palette_bytes(im, palette, im.encoderinfo)[0]
 | 
				
			||||||
        color_table_size = _get_color_table_size(palette_bytes)
 | 
					        color_table_size = _get_color_table_size(palette_bytes)
 | 
				
			||||||
        if color_table_size:
 | 
					        if color_table_size:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -325,10 +325,7 @@ def _save(im, fp, filename, check=0):
 | 
				
			||||||
    except KeyError:
 | 
					    except KeyError:
 | 
				
			||||||
        raise ValueError("Cannot save %s images as IM" % im.mode)
 | 
					        raise ValueError("Cannot save %s images as IM" % im.mode)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    frames = im.encoderinfo.get("frames", 1)
 | 
				
			||||||
        frames = im.encoderinfo["frames"]
 | 
					 | 
				
			||||||
    except KeyError:
 | 
					 | 
				
			||||||
        frames = 1
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if check:
 | 
					    if check:
 | 
				
			||||||
        return check
 | 
					        return check
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2194,10 +2194,7 @@ def fromarray(obj, mode=None):
 | 
				
			||||||
    arr = obj.__array_interface__
 | 
					    arr = obj.__array_interface__
 | 
				
			||||||
    shape = arr['shape']
 | 
					    shape = arr['shape']
 | 
				
			||||||
    ndim = len(shape)
 | 
					    ndim = len(shape)
 | 
				
			||||||
    try:
 | 
					    strides = arr.get('strides', None)
 | 
				
			||||||
        strides = arr['strides']
 | 
					 | 
				
			||||||
    except KeyError:
 | 
					 | 
				
			||||||
        strides = None
 | 
					 | 
				
			||||||
    if mode is None:
 | 
					    if mode is None:
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            typekey = (1, 1) + shape[2:], arr['typestr']
 | 
					            typekey = (1, 1) + shape[2:], arr['typestr']
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,10 +38,7 @@ class UI(Label):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.update()
 | 
					        self.update()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        duration = im.info.get("duration", 100)
 | 
				
			||||||
            duration = im.info["duration"]
 | 
					 | 
				
			||||||
        except KeyError:
 | 
					 | 
				
			||||||
            duration = 100
 | 
					 | 
				
			||||||
        self.after(duration, self.next)
 | 
					        self.after(duration, self.next)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def next(self):
 | 
					    def next(self):
 | 
				
			||||||
| 
						 | 
					@ -64,10 +61,7 @@ class UI(Label):
 | 
				
			||||||
            except EOFError:
 | 
					            except EOFError:
 | 
				
			||||||
                return  # end of file
 | 
					                return  # end of file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        duration = im.info.get("duration", 100)
 | 
				
			||||||
            duration = im.info["duration"]
 | 
					 | 
				
			||||||
        except KeyError:
 | 
					 | 
				
			||||||
            duration = 100
 | 
					 | 
				
			||||||
        self.after(duration, self.next)
 | 
					        self.after(duration, self.next)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.update_idletasks()
 | 
					        self.update_idletasks()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user