diff options
| author | Christos Zoulas <christos@zoulas.com> | 2021-01-04 19:44:54 +0000 |
|---|---|---|
| committer | Christos Zoulas <christos@zoulas.com> | 2021-01-04 19:44:54 +0000 |
| commit | 6faf2eba2b8c65fbac7acd36602500d757614d2f (patch) | |
| tree | 6ac6551b42d7f41ee114d9fbbad45889b26b0f04 /python/magic.py | |
| parent | ef0125ab6a5e3241e3a26e3e1ad41844a250b9a6 (diff) | |
| download | file-git-6faf2eba2b8c65fbac7acd36602500d757614d2f.tar.gz | |
PR/225: Brian: add get/setparam
Diffstat (limited to 'python/magic.py')
| -rw-r--r-- | python/magic.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/python/magic.py b/python/magic.py index 4c1ff7a7..0c17caf2 100644 --- a/python/magic.py +++ b/python/magic.py @@ -50,6 +50,14 @@ MAGIC_NO_CHECK_ENCODING = NO_CHECK_ENCODING = 2097152 MAGIC_NO_CHECK_BUILTIN = NO_CHECK_BUILTIN = 4173824 +MAGIC_PARAM_INDIR_MAX = PARAM_INDIR_MAX = 0 +MAGIC_PARAM_NAME_MAX = PARAM_NAME_MAX = 1 +MAGIC_PARAM_ELF_PHNUM_MAX = PARAM_ELF_PHNUM_MAX = 2 +MAGIC_PARAM_ELF_SHNUM_MAX = PARAM_ELF_SHNUM_MAX = 3 +MAGIC_PARAM_ELF_NOTES_MAX = PARAM_ELF_NOTES_MAX = 4 +MAGIC_PARAM_REGEX_MAX = PARAM_REGEX_MAX = 5 +MAGIC_PARAM_BYTES_MAX = PARAM_BYTES_MAX = 6 + FileMagic = namedtuple('FileMagic', ('mime_type', 'encoding', 'name')) @@ -106,6 +114,14 @@ _errno = _libraries['magic'].magic_errno _errno.restype = c_int _errno.argtypes = [magic_t] +_getparam = _libraries['magic'].magic_getparam +_getparam.restype = c_int +_getparam.argtypes = [magic_t, c_int, c_void_p] + +_setparam = _libraries['magic'].magic_setparam +_setparam.restype = c_int +_setparam.argtypes = [magic_t, c_int, c_void_p] + class Magic(object): def __init__(self, ms): @@ -231,6 +247,24 @@ class Magic(object): """ return _errno(self._magic_t) + def getparam(self, param): + """ + Returns the param value if successful and -1 if the parameter + was unknown. + """ + v = c_int() + i = _getparam(self._magic_t, param, byref(v)) + if i == -1: + return -1 + return v.value + + def setparam(self, param, value): + """ + Returns 0 if successful and -1 if the parameter was unknown. + """ + v = c_int(value) + return _setparam(self._magic_t, param, byref(v)) + def open(flags): """ |
