Skip to content

Log warning raised when opening an OLEfile without context manager #191

@vr0al

Description

@vr0al

If you run the following script with a file as the first argument, OLEfile throws a warning exception as pyhwp is not opening a file within a with context manager.

Reproduce

import sys

import hwp5.storage
import hwp5.xmlmodel

hwp5file = hwp5.xmlmodel.Hwp5File(sys.argv[1])
print("File opened")
File opened
/usr/local/lib/python3.8/dist-packages/olefile-0.47.dev4-py3.8.egg/olefile/olefile.py:1410: OleFileIONotClosed: Deleting OleFileIO instance with open file handle. You should ensure that OleFileIO is never deleted without calling close() first. Consider using "with OleFileIO(...) as ole: ...".
Stacktrace of open() call:
  File "test.py", line 5, in <module>
    hwp5file = hwp5.xmlmodel.Hwp5File(sys.argv[1])
  File "/home/yog/.local/lib/python3.8/site-packages/hwp5/filestructure.py", line 537, in __init__
    stg = Hwp5FileBase(stg)
  File "/home/yog/.local/lib/python3.8/site-packages/hwp5/filestructure.py", line 188, in __init__
    stg = OleStorage(stg)
  File "/home/yog/.local/lib/python3.8/site-packages/hwp5/storage/ole.py", line 35, in __init__
    self.impl = impl_class(*args, **kwargs)
  File "/home/yog/.local/lib/python3.8/site-packages/hwp5/plat/olefileio.py", line 115, in __init__
    olefile = OleFileIO(olefile)
  File "/usr/local/lib/python3.8/dist-packages/olefile-0.47.dev4-py3.8.egg/olefile/olefile.py", line 1107, in __init__
    self.open(filename, write_mode=write_mode)
  File "/usr/local/lib/python3.8/dist-packages/olefile-0.47.dev4-py3.8.egg/olefile/olefile.py", line 1213, in open
    self._open_stack = traceback.extract_stack()   # remember for warning

My version history is

python3 -m pip install olefile --upgrade
Requirement already up-to-date: olefile in /usr/local/lib/python3.8/dist-packages/olefile-0.47.dev4-py3.8.egg (0.47.dev4)

python3 -m pip install pyhwp --upgrade

Requirement already up-to-date: pyhwp in /home/yog/.local/lib/python3.8/site-packages (0.1b15)
Requirement already satisfied, skipping upgrade: lxml; platform_python_implementation != "Jython" in /home/yog/.local/lib/python3.8/site-packages (from pyhwp) (4.6.5)
Requirement already satisfied, skipping upgrade: olefile>=0.43; platform_python_implementation != "Jython" in /usr/local/lib/python3.8/dist-packages/olefile-0.47.dev4-py3.8.egg (from pyhwp) (0.47.dev4)
Requirement already satisfied, skipping upgrade: cryptography; platform_python_implementation != "Jython" in /home/yog/.local/lib/python3.8/site-packages (from pyhwp) (3.3.2)
Requirement already satisfied, skipping upgrade: cffi>=1.12 in /home/yog/.local/lib/python3.8/site-packages (from cryptography; platform_python_implementation != "Jython"->pyhwp) (1.15.0)
Requirement already satisfied, skipping upgrade: six>=1.4.1 in /usr/lib/python3/dist-packages (from cryptography; platform_python_implementation != "Jython"->pyhwp) (1.14.0)
Requirement already satisfied, skipping upgrade: pycparser in /home/yog/.local/lib/python3.8/site-packages (from cffi>=1.12->cryptography; platform_python_implementation != "Jython"->pyhwp) (2.21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions