|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | | -import imp |
15 | | -import os |
16 | | - |
17 | | -import pkg_resources |
18 | 14 |
|
19 | 15 | from rethinkdb import errors, version |
20 | 16 |
|
@@ -65,29 +61,30 @@ def __init__(self): |
65 | 61 | self.set_loop_type(None) |
66 | 62 |
|
67 | 63 | def set_loop_type(self, library=None): |
68 | | - if library is None: |
69 | | - self.connection_type = self.net.DefaultConnection |
70 | | - return |
71 | | - |
72 | | - # find module file |
73 | | - manager = pkg_resources.ResourceManager() |
74 | | - lib_path = "%(library)s_net/net_%(library)s.py" % {"library": library} |
75 | | - if not manager.resource_exists(__name__, lib_path): |
76 | | - raise ValueError("Unknown loop type: %r" % library) |
77 | | - |
78 | | - # load the module |
79 | | - module_path = manager.resource_filename(__name__, lib_path) |
80 | | - module_name = "net_%s" % library |
81 | | - module_file, pathName, desc = imp.find_module( |
82 | | - module_name, [os.path.dirname(module_path)] |
83 | | - ) |
84 | | - module = imp.load_module("rethinkdb." + module_name, module_file, pathName, desc) |
| 64 | + if library == "asyncio": |
| 65 | + from rethinkdb.asyncio_net import net_asyncio |
| 66 | + self.connection_type = net_asyncio.Connection |
| 67 | + |
| 68 | + if library == "gevent": |
| 69 | + from rethinkdb.gevent_net import net_gevent |
| 70 | + self.connection_type = net_gevent.Connection |
85 | 71 |
|
86 | | - # set the connection type |
87 | | - self.connection_type = module.Connection |
| 72 | + if library == "tornado": |
| 73 | + from rethinkdb.tornado_net import net_tornado |
| 74 | + self.connection_type = net_tornado.Connection |
| 75 | + |
| 76 | + if library == "trio": |
| 77 | + from rethinkdb.trio_net import net_trio |
| 78 | + self.connection_type = net_trio.Connection |
| 79 | + |
| 80 | + if library == "twisted": |
| 81 | + from rethinkdb.twisted_net import net_twisted |
| 82 | + self.connection_type = net_twisted.Connection |
| 83 | + |
| 84 | + if library is None or self.connection_type is None: |
| 85 | + self.connection_type = self.net.DefaultConnection |
88 | 86 |
|
89 | | - # cleanup |
90 | | - manager.cleanup_resources() |
| 87 | + return |
91 | 88 |
|
92 | 89 | def connect(self, *args, **kwargs): |
93 | 90 | return self.make_connection(self.connection_type, *args, **kwargs) |
|
0 commit comments