close file automaticaly

This commit is contained in:
Denis Fomin 2013-01-03 17:09:51 +04:00
parent 1202d79a3c
commit ec6b85a75b
2 changed files with 4 additions and 4 deletions

View File

@ -154,8 +154,8 @@ class ProfileWindow:
scaled_pixbuf.savev(path_to_file, 'png', [], [])
must_delete = True
fd = open(path_to_file, 'rb')
data = fd.read()
with open(path_to_file, 'rb') as fd:
data = fd.read()
pixbuf = gtkgui_helpers.get_pixbuf_from_data(data)
try:
# rescale it

View File

@ -905,8 +905,8 @@ class SignalObject(dbus.service.Object):
else:
invalid_file = True
if not invalid_file and filesize < 16384:
fd = open(picture, 'rb')
data = fd.read()
with open(picture, 'rb') as fb:
data = fd.read()
avatar = base64.b64encode(data).decode('utf-8')
avatar_mime_type = mimetypes.guess_type(picture)[0]
vcard={}