Skip to content

Commit

Permalink
Merge pull request #244 from jspricke/fix_del_cookie
Browse files Browse the repository at this point in the history
Check for cookie attribute before trying to delete it
  • Loading branch information
ahupp authored May 17, 2021
2 parents 53aa709 + 12d0ea0 commit e6d7ee0
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions magic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def __init__(self, mime=False, magic_file=None, mime_encoding=False,
raw - Do not try to decode "non-printable" chars.
extension - Print a slash-separated list of valid extensions for the file type found.
"""

self.cookie = None
self.flags = MAGIC_NONE
if mime:
self.flags |= MAGIC_MIME_TYPE
Expand Down Expand Up @@ -152,7 +150,7 @@ def __del__(self):
# incorrect fix for a threading problem, however I'm leaving
# it in because it's harmless and I'm slightly afraid to
# remove it.
if self.cookie and magic_close:
if hasattr(self, 'cookie') and self.cookie and magic_close:
magic_close(self.cookie)
self.cookie = None

Expand Down

0 comments on commit e6d7ee0

Please sign in to comment.