diff --git a/rethinkdb/__init__.py b/rethinkdb/__init__.py index 68c926a5..70b1661a 100644 --- a/rethinkdb/__init__.py +++ b/rethinkdb/__init__.py @@ -11,10 +11,6 @@ # 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. -import imp -import os - -import pkg_resources from rethinkdb import errors, version @@ -65,29 +61,30 @@ def __init__(self): self.set_loop_type(None) def set_loop_type(self, library=None): - if library is None: - self.connection_type = self.net.DefaultConnection - return - - # find module file - manager = pkg_resources.ResourceManager() - lib_path = "%(library)s_net/net_%(library)s.py" % {"library": library} - if not manager.resource_exists(__name__, lib_path): - raise ValueError("Unknown loop type: %r" % library) - - # load the module - module_path = manager.resource_filename(__name__, lib_path) - module_name = "net_%s" % library - module_file, pathName, desc = imp.find_module( - module_name, [os.path.dirname(module_path)] - ) - module = imp.load_module("rethinkdb." + module_name, module_file, pathName, desc) + if library == "asyncio": + from rethinkdb.asyncio_net import net_asyncio + self.connection_type = net_asyncio.Connection + + if library == "gevent": + from rethinkdb.gevent_net import net_gevent + self.connection_type = net_gevent.Connection - # set the connection type - self.connection_type = module.Connection + if library == "tornado": + from rethinkdb.tornado_net import net_tornado + self.connection_type = net_tornado.Connection + + if library == "trio": + from rethinkdb.trio_net import net_trio + self.connection_type = net_trio.Connection + + if library == "twisted": + from rethinkdb.twisted_net import net_twisted + self.connection_type = net_twisted.Connection + + if library is None or self.connection_type is None: + self.connection_type = self.net.DefaultConnection - # cleanup - manager.cleanup_resources() + return def connect(self, *args, **kwargs): return self.make_connection(self.connection_type, *args, **kwargs)