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

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