From 1a5b9f1dc3099a0463beeae05a3927070fde41df Mon Sep 17 00:00:00 2001 From: hjpotter92 Date: Wed, 27 Sep 2017 09:52:21 +0530 Subject: [PATCH] Support for filetypes in Python 3 version Also allow for `StringIO` type variables Signed-off-by: hjpotter92 --- redminelib/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/redminelib/__init__.py b/redminelib/__init__.py index 24d46e6..1a66669 100644 --- a/redminelib/__init__.py +++ b/redminelib/__init__.py @@ -82,7 +82,13 @@ def upload(self, filepath_obj): url = '{0}/uploads.json'.format(self.url) headers = {'Content-Type': 'application/octet-stream'} - if isinstance(filepath_obj, file): + try: + from StringIO import StringIO + filetype = (file, StringIO) + except (NameError, ImportError): + from io import IOBase + filetype = IOBase + if isinstance(filepath_obj, filetype): response = self.engine.request('post', url, data=filepath_obj, headers=headers) else: if not os.path.isfile(filepath_obj) or os.path.getsize(filepath_obj) == 0: