Skip to content

Commit 7ba97e9

Browse files
authored
Fix not implemented error (#204)
* ensure modules are loaded by pyinstaller * removed unused imports * ensure DefaultConnection in case connection_type returns None
1 parent 6d53f0e commit 7ba97e9

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

rethinkdb/__init__.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import imp
15-
import os
16-
17-
import pkg_resources
1814

1915
from rethinkdb import errors, version
2016

@@ -65,29 +61,30 @@ def __init__(self):
6561
self.set_loop_type(None)
6662

6763
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
8571

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
8886

89-
# cleanup
90-
manager.cleanup_resources()
87+
return
9188

9289
def connect(self, *args, **kwargs):
9390
return self.make_connection(self.connection_type, *args, **kwargs)

0 commit comments

Comments
 (0)