mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #1415 from wiredfool/dup_code
Dedup code in image.open
This commit is contained in:
		
						commit
						254201cac6
					
				
							
								
								
									
										25
									
								
								PIL/Image.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								PIL/Image.py
									
									
									
									
									
								
							| 
						 | 
					@ -2299,19 +2299,7 @@ def open(fp, mode="r"):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    preinit()
 | 
					    preinit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for i in ID:
 | 
					    def _open_core(fp, filename, prefix):
 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            factory, accept = OPEN[i]
 | 
					 | 
				
			||||||
            if not accept or accept(prefix):
 | 
					 | 
				
			||||||
                fp.seek(0)
 | 
					 | 
				
			||||||
                im = factory(fp, filename)
 | 
					 | 
				
			||||||
                _decompression_bomb_check(im.size)
 | 
					 | 
				
			||||||
                return im
 | 
					 | 
				
			||||||
        except (SyntaxError, IndexError, TypeError, struct.error):
 | 
					 | 
				
			||||||
            logger.debug("", exc_info=True)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if init():
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for i in ID:
 | 
					        for i in ID:
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                factory, accept = OPEN[i]
 | 
					                factory, accept = OPEN[i]
 | 
				
			||||||
| 
						 | 
					@ -2322,11 +2310,20 @@ def open(fp, mode="r"):
 | 
				
			||||||
                    return im
 | 
					                    return im
 | 
				
			||||||
            except (SyntaxError, IndexError, TypeError, struct.error):
 | 
					            except (SyntaxError, IndexError, TypeError, struct.error):
 | 
				
			||||||
                logger.debug("", exc_info=True)
 | 
					                logger.debug("", exc_info=True)
 | 
				
			||||||
 | 
					        return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    im = _open_core(fp, filename, prefix)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if im is None:
 | 
				
			||||||
 | 
					        if init():
 | 
				
			||||||
 | 
					            im = _open_core(fp, filename, prefix)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if im:
 | 
				
			||||||
 | 
					        return im
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    raise IOError("cannot identify image file %r"
 | 
					    raise IOError("cannot identify image file %r"
 | 
				
			||||||
                  % (filename if filename else fp))
 | 
					                  % (filename if filename else fp))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# Image processing.
 | 
					# Image processing.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user