Skip to content

Fix not implemented error #204

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

Merged
merged 3 commits into from
Jun 15, 2020
Merged
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
47 changes: 22 additions & 25 deletions rethinkdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down