From afc012ab6361d7d12e1b9519a4b5a3f14c559bd0 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Sat, 22 Aug 2015 19:49:56 -0700 Subject: [PATCH] overwrite definition of where in requests.certs for different filesystem encodings --- wakatime/compat.py | 1 + wakatime/packages/requests/certs.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wakatime/compat.py b/wakatime/compat.py index 3abbfa5..ba8f107 100644 --- a/wakatime/compat.py +++ b/wakatime/compat.py @@ -40,6 +40,7 @@ elif is_py3: # pragma: nocover open = open basestring = (str, bytes) + try: from importlib import import_module except ImportError: # pragma: nocover diff --git a/wakatime/packages/requests/certs.py b/wakatime/packages/requests/certs.py index 07e6475..47cc228 100644 --- a/wakatime/packages/requests/certs.py +++ b/wakatime/packages/requests/certs.py @@ -11,6 +11,7 @@ If you are packaging Requests, e.g., for a Linux distribution or a managed environment, you can change the definition of where() to return a separately packaged CA bundle. """ +import sys import os.path try: @@ -19,7 +20,13 @@ except ImportError: def where(): """Return the preferred certificate bundle.""" # vendored bundle inside Requests - return os.path.join(os.path.dirname(__file__), 'cacert.pem') + is_py3 = (sys.version_info[0] == 3) + certdir = os.path.dirname( + __file__ + if is_py3 else + __file__.decode(sys.getfilesystemencoding()) + ) + return os.path.join(certdir, 'cacert.pem') if __name__ == '__main__': print(where())