(to_module)
| 429 | # resolve, We ship a copy of that module, and expose it's functions |
| 430 | # wrapped in deprecation warnings. |
| 431 | def _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()) |
no test coverage detected
searching dependent graphs…