more cleanup for photos provider
This commit is contained in:
parent
c37bc6e60e
commit
4ed70eee90
3 changed files with 45 additions and 33 deletions
19
my/common.py
19
my/common.py
|
@ -126,3 +126,22 @@ def mcachew(*args, **kwargs):
|
|||
import cachew.experimental
|
||||
cachew.experimental.enable_exceptions() # TODO do it only once?
|
||||
return cachew.cachew(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
@functools.lru_cache(1)
|
||||
def _magic():
|
||||
import magic # type: ignore
|
||||
return magic.Magic(mime=True)
|
||||
|
||||
|
||||
# TODO could reuse in pdf module?
|
||||
import mimetypes # TODO do I need init()?
|
||||
def fastermime(path: str) -> str:
|
||||
# mimetypes is faster
|
||||
(mime, _) = mimetypes.guess_type(path)
|
||||
if mime is not None:
|
||||
return mime
|
||||
# magic is slower but returns more stuff
|
||||
# TODO FIXME Result type; it's inherently racey
|
||||
return _magic().from_file(path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue