From 61309fd1e1c42930e4a267525379220f57f36328 Mon Sep 17 00:00:00 2001 From: Mathias Markl Date: Wed, 25 Jul 2018 01:45:50 +0200 Subject: [PATCH] update --- muk_utils/__manifest__.py | 2 +- muk_utils/tools/utils_os.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/muk_utils/__manifest__.py b/muk_utils/__manifest__.py index e1451cf..29e154b 100644 --- a/muk_utils/__manifest__.py +++ b/muk_utils/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Utils", "summary": """Utility Features""", - "version": '11.0.1.0.9', + "version": '11.0.1.0.10', "category": 'Extra Tools', "license": "AGPL-3", "website": "https://www.mukit.at", diff --git a/muk_utils/tools/utils_os.py b/muk_utils/tools/utils_os.py index 58a5490..713ab6e 100644 --- a/muk_utils/tools/utils_os.py +++ b/muk_utils/tools/utils_os.py @@ -18,7 +18,13 @@ ################################################################################### import os +import io +import base64 +import shutil +import urllib import logging +import tempfile +import mimetypes _logger = logging.getLogger(__name__) @@ -37,4 +43,15 @@ def unique_name(name, names, escape_suffix=False): while name in names: suffix += 1 name = compute_name(name, suffix, escape_suffix) - return name \ No newline at end of file + return name + +def get_extension(filename, mimetype): + if not mimetype and not filename: + mimetype = guess_mimetype(binary, default=False) + if not mimetype and filename: + mimetype = mimetypes.guess_type(urllib.request.pathname2url(filename))[0] + if not filename and mimetype: + return mimetypes.guess_extension(mimetype)[1:].strip().lower() + elif filename: + return os.path.splitext(filename)[1][1:].strip().lower() + return None \ No newline at end of file