Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydev_saved_modules: clone first-level module content #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
import sys
IS_PY2 = sys.version_info < (3,)
del sys

import threading

import time
import importlib
if IS_PY2:
def _CloneModule(name):
import imp
proxy_module = imp.new_module(name)
real_module = importlib.import_module(name)
for attr in dir(real_module):
setattr(proxy_module, attr, getattr(real_module, attr))
return proxy_module
else:
def _CloneModule(name):
import types
proxy_module = types.ModuleType(name)
real_module = importlib.import_module(name)
for attr in dir(real_module):
setattr(proxy_module, attr, getattr(real_module, attr))
return proxy_module

import socket
# Capture a clone of modules so that if parts of them are mocked out by a
# target, it does not impact the execution of pydev.
# Usage:
# import x --> x = CloneModule("x")
# import x as y --> y = CloneModule("x")

import select
threading = _CloneModule("threading")
time = _CloneModule("time")
socket = _CloneModule("socket")
select = _CloneModule("select")

if IS_PY2:
import thread
import Queue as _queue
import xmlrpclib
import SimpleXMLRPCServer as _pydev_SimpleXMLRPCServer
import BaseHTTPServer
thread = _CloneModule("thread")
_queue = _CloneModule("Queue")
xmlrpclib = _CloneModule("xmlrpclib")
_pydev_SimpleXMLRPCServer = _CloneModule("SimpleXMLRPCServer")
BaseHTTPServer = _CloneModule("BaseHTTPServer")
else:
import _thread as thread
import queue as _queue
import xmlrpc.client as xmlrpclib
import xmlrpc.server as _pydev_SimpleXMLRPCServer
import http.server as BaseHTTPServer
thread = _CloneModule("_thread")
_queue = _CloneModule("queue")
xmlrpclib = _CloneModule("xmlrpc.client")
_pydev_SimpleXMLRPCServer = _CloneModule("xmlrpc.server")
BaseHTTPServer = _CloneModule("http.server")

del _CloneModule
del importlib
del IS_PY2