1
0

0.4.27-21-gfd279e0.magic-init-add-kwargs-to-enable-disable-different-types-of-magic-detection.patch 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. Subject: Magic.__init__: add kwargs to enable/disable different types of magic detection
  2. Origin: upstream, commit 0.4.27-21-gfd279e0 <https://github.com/ahupp/python-magic/commit/0.4.27-21-gfd279e0>
  3. Author: Robert Scott <code@humanleg.org.uk>
  4. Date: Sat Oct 7 18:18:08 2023 +0100
  5. Forwarded: not-needed
  6. --- a/magic/__init__.py
  7. +++ b/magic/__init__.py
  8. @@ -40,7 +40,10 @@
  9. def __init__(self, mime=False, magic_file=None, mime_encoding=False,
  10. keep_going=False, uncompress=False, raw=False, extension=False,
  11. - follow_symlinks=False):
  12. + follow_symlinks=False, check_tar=True, check_soft=True,
  13. + check_apptype=True, check_elf=True, check_text=True,
  14. + check_cdf=True, check_csv=True, check_encoding=True,
  15. + check_json=True, check_simh=True):
  16. """
  17. Create a new libmagic wrapper.
  18. @@ -69,6 +72,27 @@
  19. if follow_symlinks:
  20. self.flags |= MAGIC_SYMLINK
  21. + if not check_tar:
  22. + self.flags |= MAGIC_NO_CHECK_TAR
  23. + if not check_soft:
  24. + self.flags |= MAGIC_NO_CHECK_SOFT
  25. + if not check_apptype:
  26. + self.flags |= MAGIC_NO_CHECK_APPTYPE
  27. + if not check_elf:
  28. + self.flags |= MAGIC_NO_CHECK_ELF
  29. + if not check_text:
  30. + self.flags |= MAGIC_NO_CHECK_TEXT
  31. + if not check_cdf:
  32. + self.flags |= MAGIC_NO_CHECK_CDF
  33. + if not check_csv:
  34. + self.flags |= MAGIC_NO_CHECK_CSV
  35. + if not check_encoding:
  36. + self.flags |= MAGIC_NO_CHECK_ENCODING
  37. + if not check_json:
  38. + self.flags |= MAGIC_NO_CHECK_JSON
  39. + if not check_simh:
  40. + self.flags |= MAGIC_NO_CHECK_SIMH
  41. +
  42. self.cookie = magic_open(self.flags)
  43. self.lock = threading.Lock()
  44. @@ -411,10 +435,16 @@
  45. MAGIC_NO_CHECK_SOFT = 0x004000 # Don't check magic entries
  46. MAGIC_NO_CHECK_APPTYPE = 0x008000 # Don't check application type
  47. MAGIC_NO_CHECK_ELF = 0x010000 # Don't check for elf details
  48. -MAGIC_NO_CHECK_ASCII = 0x020000 # Don't check for ascii files
  49. -MAGIC_NO_CHECK_TROFF = 0x040000 # Don't check ascii/troff
  50. -MAGIC_NO_CHECK_FORTRAN = 0x080000 # Don't check ascii/fortran
  51. -MAGIC_NO_CHECK_TOKENS = 0x100000 # Don't check ascii/tokens
  52. +MAGIC_NO_CHECK_TEXT = 0x020000 # Don't check for ascii files
  53. +MAGIC_NO_CHECK_ASCII = 0x020000 # Deprecated alias for MAGIC_NO_CHECK_TEXT
  54. +MAGIC_NO_CHECK_TROFF = 0x040000 # Don't check ascii/troff (deprecated)
  55. +MAGIC_NO_CHECK_FORTRAN = 0x080000 # Don't check ascii/fortran (deprecated)
  56. +MAGIC_NO_CHECK_TOKENS = 0x100000 # Don't check ascii/tokens (deprecated)
  57. +MAGIC_NO_CHECK_CDF = 0x0040000 # Don't check for CDF files
  58. +MAGIC_NO_CHECK_CSV = 0x0080000 # Don't check for CSV files
  59. +MAGIC_NO_CHECK_ENCODING = 0x0200000 # Don't check text encodings
  60. +MAGIC_NO_CHECK_JSON = 0x0400000 # Don't check for JSON files
  61. +MAGIC_NO_CHECK_SIMH = 0x0800000 # Don't check for SIMH tape files
  62. MAGIC_PARAM_INDIR_MAX = 0 # Recursion limit for indirect magic
  63. MAGIC_PARAM_NAME_MAX = 1 # Use count limit for name/use magic
  64. --- a/magic/__init__.pyi
  65. +++ b/magic/__init__.pyi
  66. @@ -11,7 +11,7 @@
  67. flags: int = ...
  68. cookie: Any = ...
  69. lock: threading.Lock = ...
  70. - def __init__(self, mime: bool = ..., magic_file: Optional[Any] = ..., mime_encoding: bool = ..., keep_going: bool = ..., uncompress: bool = ..., raw: bool = ..., extension: bool = ..., follow_symlinks: bool = ...) -> None: ...
  71. + def __init__(self, mime: bool = ..., magic_file: Optional[Any] = ..., mime_encoding: bool = ..., keep_going: bool = ..., uncompress: bool = ..., raw: bool = ..., extension: bool = ..., follow_symlinks: bool = ..., check_tar: bool = ..., check_soft: bool = ..., check_apptype: bool = ..., check_elf: bool = ..., check_text: bool = ..., check_encoding: bool = ..., check_json: bool = ..., check_simh: bool = ...) -> None: ...
  72. def from_buffer(self, buf: Union[bytes, str]) -> Text: ...
  73. def from_file(self, filename: Union[bytes, str, PathLike]) -> Text: ...
  74. def from_descriptor(self, fd: int, mime: bool = ...) -> Text: ...
  75. @@ -74,10 +74,16 @@
  76. MAGIC_NO_CHECK_SOFT: int
  77. MAGIC_NO_CHECK_APPTYPE: int
  78. MAGIC_NO_CHECK_ELF: int
  79. +MAGIC_NO_CHECK_TEXT: int
  80. MAGIC_NO_CHECK_ASCII: int
  81. MAGIC_NO_CHECK_TROFF: int
  82. MAGIC_NO_CHECK_FORTRAN: int
  83. +MAGIC_NO_CHECK_CDF: int
  84. +MAGIC_NO_CHECK_CSV: int
  85. MAGIC_NO_CHECK_TOKENS: int
  86. +MAGIC_NO_CHECK_ENCODING: int
  87. +MAGIC_NO_CHECK_JSON: int
  88. +MAGIC_NO_CHECK_SIMH: int
  89. MAGIC_PARAM_INDIR_MAX: int
  90. MAGIC_PARAM_NAME_MAX: int
  91. MAGIC_PARAM_ELF_PHNUM_MAX: int