mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Merge pull request #2226 from jdufresne/font-file-close
Use a context manager in FontFile.save() to ensure file is always closed
This commit is contained in:
		
						commit
						8b4cd7eb7a
					
				| 
						 | 
					@ -100,7 +100,7 @@ class FontFile(object):
 | 
				
			||||||
        self.bitmap.save(os.path.splitext(filename)[0] + ".pbm", "PNG")
 | 
					        self.bitmap.save(os.path.splitext(filename)[0] + ".pbm", "PNG")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # font metrics
 | 
					        # font metrics
 | 
				
			||||||
        fp = open(os.path.splitext(filename)[0] + ".pil", "wb")
 | 
					        with open(os.path.splitext(filename)[0] + ".pil", "wb") as fp:
 | 
				
			||||||
            fp.write(b"PILfont\n")
 | 
					            fp.write(b"PILfont\n")
 | 
				
			||||||
            fp.write((";;;;;;%d;\n" % self.ysize).encode('ascii'))  # HACK!!!
 | 
					            fp.write((";;;;;;%d;\n" % self.ysize).encode('ascii'))  # HACK!!!
 | 
				
			||||||
            fp.write(b"DATA\n")
 | 
					            fp.write(b"DATA\n")
 | 
				
			||||||
| 
						 | 
					@ -110,4 +110,3 @@ class FontFile(object):
 | 
				
			||||||
                    puti16(fp, [0] * 10)
 | 
					                    puti16(fp, [0] * 10)
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    puti16(fp, m[0] + m[1] + m[2])
 | 
					                    puti16(fp, m[0] + m[1] + m[2])
 | 
				
			||||||
        fp.close()
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user