From e5b33160e024330013d7d6abb9e93b487a8570da Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Thu, 22 Nov 2018 17:48:22 -0600 Subject: [PATCH] Added a custom fix for Libloader with changes made by @jmdaweb #273 --- src/fixes/__init__.py | 2 ++ src/fixes/fix_libloader.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/fixes/fix_libloader.py diff --git a/src/fixes/__init__.py b/src/fixes/__init__.py index c14e4d6d..a4ef2a79 100644 --- a/src/fixes/__init__.py +++ b/src/fixes/__init__.py @@ -3,6 +3,7 @@ from __future__ import absolute_import import sys from . import fix_arrow # A few new locales for Three languages in arrow. +from . import fix_libloader # Regenerates comcache properly. from . import fix_urllib3_warnings # Avoiding some SSL warnings related to Twython. from . import fix_win32com from . import fix_requests #fix cacert.pem location for TWBlue binary copies @@ -11,6 +12,7 @@ def setup(): if hasattr(sys, "frozen"): fix_win32com.fix() fix_requests.fix(True) + fix_libloader.fix() else: fix_requests.fix(False) fix_urllib3_warnings.fix() \ No newline at end of file diff --git a/src/fixes/fix_libloader.py b/src/fixes/fix_libloader.py new file mode 100644 index 00000000..67f312a4 --- /dev/null +++ b/src/fixes/fix_libloader.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +import win32com +import paths +win32com.__gen_path__=paths.com_path() +import sys +import os +sys.path.append(os.path.join(win32com.__gen_path__, ".")) +from win32com.client import gencache +from pywintypes import com_error +from libloader import com + +fixed=False + +def patched_getmodule(modname): + mod=__import__(modname) + return sys.modules[modname] + +def load_com(*names): + global fixed + if fixed==False: + gencache._GetModule=patched_getmodule + com.prepare_gencache() + fixed=True + result = None + for name in names: + try: + result = gencache.EnsureDispatch(name) + break + except com_error: + continue + if result is None: + raise com_error("Unable to load any of the provided com objects.") + return result + +def fix(): + com.load_com = load_com \ No newline at end of file