[File] Python bindings to libmagic
Hoël Bézier
hoelbezier at leanco.fr
Wed Jul 13 10:14:20 UTC 2022
Hi,
the libmagic python bindings seem to have very limited error handling
capabilities, mostly returning None instead of the expected object when failing
and never raising any Exception of any kind.
This makes proper error handling a bit harder on the user side, and to make
sure I do things properly I’d like to clarify something.
The `open` routine pretends it returns None on failure, but it is defined in
the following way:
```
def open(flags):
"""
Returns a magic object on success and None on failure.
Flags argument as for setflags.
"""
return Magic(_open(flags))
```
with the Magic constructor being:
```
class Magic(object):
def __init__(self, ms):
self._magic_t = ms
```
So it seems to me that the `open` routine always returns a Magic object and
cannot fail. The `_open` routine on the other hand might fail, and thus the
returned Magic object would have a _magic_t attribute set to None.
If I understood things properly, maybe the documentation would need to be
updated so that users may handle failures properly.
Regards,
Hoël
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mailman.astron.com/pipermail/file/attachments/20220713/cbd8a2de/attachment-0001.asc>
More information about the File
mailing list