diff --git a/cpy2py/__init__.py b/cpy2py/__init__.py index de415f5..dd4fd29 100644 --- a/cpy2py/__init__.py +++ b/cpy2py/__init__.py @@ -37,8 +37,8 @@ from cpy2py.meta import __version__ from cpy2py.utility.compat import NullHandler as _NullHandler -from cpy2py.proxy.proxy_object import TwinObject, localmethod -from cpy2py.proxy.proxy_func import twinfunction +from cpy2py.proxy.baseclass import TwinObject, localmethod +from cpy2py.proxy.function import twinfunction from cpy2py.twinterpreter.master import TwinMaster from cpy2py.kernel import kernel_state diff --git a/cpy2py/kernel/kernel_single.py b/cpy2py/kernel/kernel_single.py index 1b4fa19..1d02893 100644 --- a/cpy2py/kernel/kernel_single.py +++ b/cpy2py/kernel/kernel_single.py @@ -31,15 +31,15 @@ from cpy2py.utility.exceptions import format_exception from cpy2py.ipyc import ipyc_exceptions from cpy2py.kernel.kernel_exceptions import StopTwinterpreter -from cpy2py.proxy import proxy_tracker +from cpy2py.proxy import tracker from cpy2py.kernel.kernel_requesthandler import RequestDispatcher, RequestHandler def _connect_ipyc(ipyc, pickle_protocol): """Connect pickle/unpickle trackers to a duplex IPyC""" - pickler = proxy_tracker.twin_pickler(ipyc.writer, pickle_protocol) + pickler = tracker.twin_pickler(ipyc.writer, pickle_protocol) send = pickler.dump - unpickler = proxy_tracker.twin_unpickler(ipyc.reader) + unpickler = tracker.twin_unpickler(ipyc.reader) recv = unpickler.load return send, recv diff --git a/cpy2py/proxy/proxy_object.py b/cpy2py/proxy/baseclass.py similarity index 87% rename from cpy2py/proxy/proxy_object.py rename to cpy2py/proxy/baseclass.py index 27fe22a..0821427 100644 --- a/cpy2py/proxy/proxy_object.py +++ b/cpy2py/proxy/baseclass.py @@ -13,9 +13,9 @@ # - # limitations under the License. import time -from cpy2py.proxy import proxy_tracker -from cpy2py.proxy.proxy_meta import TwinMeta -from cpy2py.proxy.proxy_twin import TwinProxy +from cpy2py.proxy import tracker +from cpy2py.proxy.metaclass import TwinMeta +from cpy2py.proxy.proxy import InstanceProxy def instance_id(instance): @@ -41,7 +41,7 @@ def new_twin_object(cls, *args, **kwargs): # pylint: disable=unused-argument self = object.__new__(cls) object.__setattr__(self, '__instance_id__', instance_id(self)) # register our reference for lookup - proxy_tracker.__active_instances__[self.__twin_id__, self.__instance_id__] = self + tracker.__active_instances__[self.__twin_id__, self.__instance_id__] = self return self # calling TwinMeta to set metaclass explicitly works for py2 and py3 @@ -76,6 +76,6 @@ def localmethod(method): setattr(method, TwinMeta.mark_localmember, True) return method -# TwinObject and TwinProxy are not created by metaclass, initialize manually +# TwinObject and InstanceProxy are not created by metaclass, initialize manually TwinObject.__import_mod_name__ = (TwinObject.__module__, TwinObject.__name__) -TwinProxy.__import_mod_name__ = TwinObject.__import_mod_name__ +InstanceProxy.__import_mod_name__ = TwinObject.__import_mod_name__ diff --git a/cpy2py/proxy/proxy_func.py b/cpy2py/proxy/function.py similarity index 100% rename from cpy2py/proxy/proxy_func.py rename to cpy2py/proxy/function.py diff --git a/cpy2py/proxy/proxy_meta.py b/cpy2py/proxy/metaclass.py similarity index 94% rename from cpy2py/proxy/proxy_meta.py rename to cpy2py/proxy/metaclass.py index 430d9cb..e40f821 100644 --- a/cpy2py/proxy/proxy_meta.py +++ b/cpy2py/proxy/metaclass.py @@ -15,7 +15,7 @@ import types from cpy2py.kernel import kernel_state -from cpy2py.proxy.proxy_twin import TwinProxy, ProxyMethod +from cpy2py.proxy.proxy import InstanceProxy, UnboundedMethodProxy class TwinMeta(type): @@ -103,13 +103,13 @@ def __new_proxy_class__(mcs, name, bases, class_dict): del proxy_dict[aname] # methods must be proxy'd elif isinstance(proxy_dict[aname], types.FunctionType): - proxy_dict[aname] = ProxyMethod(proxy_dict[aname]) + proxy_dict[aname] = UnboundedMethodProxy(proxy_dict[aname]) elif isinstance(proxy_dict[aname], (classmethod, staticmethod)): try: real_func = proxy_dict[aname].__func__ except AttributeError: # py2.6 real_func = proxy_dict[aname].__get__(None, object) - proxy_dict[aname] = ProxyMethod(real_func) + proxy_dict[aname] = UnboundedMethodProxy(real_func) # remove non-magic attributes so they don't shadow the real ones elif aname not in mcs.__proxy_inherits_attributes__: del proxy_dict[aname] @@ -141,12 +141,12 @@ def __get_real_class(mcs, unknown_class): @classmethod def register_proxy(mcs, real_class, proxy_class): """ - Register a class acting as :py:class:`~.TwinProxy` for a real class + Register a class acting as :py:class:`~.InstanceProxy` for a real class :param real_class: a normal, non-cpy2py class :type real_class: object or :py:class:`~cpy2py.proxy.proxy_object.TwinObject` - :param proxy_class: a proxy class similar to :py:class:`~.TwinProxy` - :type proxy_class: object or :py:class:`~.TwinProxy` + :param proxy_class: a proxy class similar to :py:class:`~.InstanceProxy` + :type proxy_class: object or :py:class:`~.InstanceProxy` """ # TODO: weakref any of these? - MF@20160401 mcs.__real_class_store__[proxy_class] = real_class @@ -175,4 +175,4 @@ def __delattr__(cls, name): type.__setattr__(cls, name) -TwinMeta.register_proxy(object, TwinProxy) +TwinMeta.register_proxy(object, InstanceProxy) diff --git a/cpy2py/proxy/proxy_twin.py b/cpy2py/proxy/proxy.py similarity index 89% rename from cpy2py/proxy/proxy_twin.py rename to cpy2py/proxy/proxy.py index 141006d..5dec8a4 100644 --- a/cpy2py/proxy/proxy_twin.py +++ b/cpy2py/proxy/proxy.py @@ -11,19 +11,23 @@ # - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # - # See the License for the specific language governing permissions and # - # limitations under the License. +""" +Proxies for entities in other twinterpreters +""" from cpy2py.kernel.kernel_exceptions import TwinterpeterUnavailable from cpy2py.kernel import kernel_state -from cpy2py.proxy import proxy_tracker +from cpy2py.proxy import tracker -class ProxyMethod(object): +class UnboundedMethodProxy(object): """ - Proxy for Methods + Proxy for unbounded methods - :param real_method: the method object to be proxied - """ + :param real_method: the unbounded method object to be proxied + :note: In Python3 terms, an unbounded method is simply a function bound to a class. + """ def __init__(self, real_method): self.__wrapped__ = real_method for attribute in ('__doc__', '__defaults__', '__name__', '__module__'): @@ -48,9 +52,9 @@ def __get__(self, instance, owner): ) -class TwinProxy(object): +class InstanceProxy(object): """ - Proxy for instances existing in another twinterpreter + Proxy for instances of classes :see: Real object :py:class:`~cpy2py.proxy.proxy_object.TwinObject` for magic attributes. @@ -81,7 +85,7 @@ def __new__(cls, *args, **kwargs): object.__setattr__(self, '__instance_id__', __instance_id__) __kernel__.increment_instance_ref(self) # store for later use without requiring explicit lookup/converter calls - proxy_tracker.__active_instances__[self.__twin_id__, self.__instance_id__] = self + tracker.__active_instances__[self.__twin_id__, self.__instance_id__] = self return self def __repr__(self): diff --git a/cpy2py/proxy/proxy_tracker.py b/cpy2py/proxy/tracker.py similarity index 100% rename from cpy2py/proxy/proxy_tracker.py rename to cpy2py/proxy/tracker.py diff --git a/cpy2py/twinterpreter/group_state.py b/cpy2py/twinterpreter/group_state.py index 92ed616..5e99a62 100644 --- a/cpy2py/twinterpreter/group_state.py +++ b/cpy2py/twinterpreter/group_state.py @@ -12,7 +12,7 @@ # - # See the License for the specific language governing permissions and # - # limitations under the License. from __future__ import print_function -from cpy2py.proxy.proxy_object import TwinObject, localmethod +from cpy2py.proxy.baseclass import TwinObject, localmethod from cpy2py.kernel import kernel_state import threading diff --git a/cpy2py_unittests/test_object.py b/cpy2py_unittests/test_object.py index 0c99411..ea00ed5 100644 --- a/cpy2py_unittests/test_object.py +++ b/cpy2py_unittests/test_object.py @@ -2,7 +2,7 @@ import time from cpy2py import TwinMaster, TwinObject -import cpy2py.proxy.proxy_twin # proxy type check +import cpy2py.proxy.proxy # proxy type check class PrimitiveObject(TwinObject): @@ -36,7 +36,7 @@ def tearDown(self): def test_init(self): instance = PrimitiveObject() - self.assertTrue(isinstance(instance, cpy2py.proxy.proxy_twin.TwinProxy)) + self.assertTrue(isinstance(instance, cpy2py.proxy.proxy.InstanceProxy)) def test_class_attribute(self): instance = PrimitiveObject() diff --git a/cpy2py_unittests/test_proxy/test_proxy_func.py b/cpy2py_unittests/test_proxy/test_proxy_func.py index c3bbe92..01e25fa 100644 --- a/cpy2py_unittests/test_proxy/test_proxy_func.py +++ b/cpy2py_unittests/test_proxy/test_proxy_func.py @@ -3,16 +3,16 @@ import time from cpy2py import kernel_state, TwinMaster -from cpy2py.proxy import proxy_func +from cpy2py.proxy import function -@proxy_func.twinfunction(kernel_state.TWIN_ID) +@function.twinfunction(kernel_state.TWIN_ID) def native_func(arg): """docstring""" return arg -@proxy_func.twinfunction('pypy') +@function.twinfunction('pypy') def proxied_func(arg): """docstring""" return arg diff --git a/cpy2py_unittests/test_scope.py b/cpy2py_unittests/test_scope.py index 48c8812..f009fa0 100644 --- a/cpy2py_unittests/test_scope.py +++ b/cpy2py_unittests/test_scope.py @@ -2,7 +2,7 @@ import time from cpy2py import kernel_state, TwinMaster, TwinObject -from cpy2py.proxy.proxy_object import localmethod +from cpy2py.proxy.baseclass import localmethod def test_kernel(kernel_id):