mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Allow pathlib.Path in Image.open on Python 2.7
Although the pathlib backport for Python 2.7 may be deprecated: https://pypi.python.org/pypi/pathlib/ It is still used by many projects. Therefore, changing to a Try/Except pattern for checking for pathlib is not any more obtrusive that the current >= Python 3.4 check and allows users to use the backport without issue.
This commit is contained in:
		
							parent
							
								
									6e7553fb0f
								
							
						
					
					
						commit
						e981c41b47
					
				
							
								
								
									
										12
									
								
								PIL/Image.py
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								PIL/Image.py
									
									
									
									
									
								
							| 
						 | 
					@ -2279,10 +2279,14 @@ def open(fp, mode="r"):
 | 
				
			||||||
    filename = ""
 | 
					    filename = ""
 | 
				
			||||||
    if isPath(fp):
 | 
					    if isPath(fp):
 | 
				
			||||||
        filename = fp
 | 
					        filename = fp
 | 
				
			||||||
    elif sys.version_info >= (3, 4):
 | 
					    else:
 | 
				
			||||||
        from pathlib import Path
 | 
					        try:
 | 
				
			||||||
        if isinstance(fp, Path):
 | 
					            from pathlib import Path
 | 
				
			||||||
            filename = str(fp.resolve())
 | 
					            if isinstance(fp, Path):
 | 
				
			||||||
 | 
					                filename = str(fp.resolve())
 | 
				
			||||||
 | 
					        except ImportError:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if filename:
 | 
					    if filename:
 | 
				
			||||||
        fp = builtins.open(filename, "rb")
 | 
					        fp = builtins.open(filename, "rb")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user