def has_magic(s): if isinstance(s, binary_type): match = magic_check_bytes.search(s) else: match = magic_check.search(s) return match is not None