MCPcopy Create free account
hub / github.com/ahupp/python-magic / _add_compat

Function _add_compat

magic/__init__.py:431–466  ·  view source on GitHub ↗
(to_module)

Source from the content-addressed store, hash-verified

429# resolve, We ship a copy of that module, and expose it's functions
430# wrapped in deprecation warnings.
431def _add_compat(to_module):
432 import warnings, re
433 from magic import compat
434
435 def deprecation_wrapper(fn):
436 def _(*args, **kwargs):
437 warnings.warn(
438 "Using compatibility mode with libmagic's python binding. "
439 "See https://github.com/ahupp/python-magic/blob/master/COMPAT.md for details.",
440 PendingDeprecationWarning)
441
442 return fn(*args, **kwargs)
443
444 return _
445
446 fn = ['detect_from_filename',
447 'detect_from_content',
448 'detect_from_fobj',
449 'open']
450 for fname in fn:
451 to_module[fname] = deprecation_wrapper(compat.__dict__[fname])
452
453 # copy constants over, ensuring there's no conflicts
454 is_const_re = re.compile("^[A-Z_]+$")
455 allowed_inconsistent = set(['MAGIC_MIME'])
456 for name, value in compat.__dict__.items():
457 if is_const_re.match(name):
458 if name in to_module:
459 if name in allowed_inconsistent:
460 continue
461 if to_module[name] != value:
462 raise Exception("inconsistent value for " + name)
463 else:
464 continue
465 else:
466 to_module[name] = value
467
468
469_add_compat(globals())

Callers 1

__init__.pyFile · 0.85

Calls 2

deprecation_wrapperFunction · 0.85
compileMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…