MCPcopy Create free account
hub / github.com/couchbase/couchbase-python-client / connect

Method connect

src/connection.cxx:129–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127}
128
129PyObject*
130Connection::connect(PyObject* kwargs)
131{
132 PyObject* pyObj_connstr = PyDict_GetItemString(kwargs, "connstr");
133 PyObject* pyObj_auth = PyDict_GetItemString(kwargs, "auth");
134 PyObject* pyObj_options = PyDict_GetItemString(kwargs, "options");
135 PyObject* pyObj_callback = PyDict_GetItemString(kwargs, "callback");
136 PyObject* pyObj_errback = PyDict_GetItemString(kwargs, "errback");
137
138 if (!validate_and_incref_callbacks(pyObj_callback, pyObj_errback)) {
139 return nullptr;
140 }
141
142 std::shared_ptr<std::promise<PyObject*>> barrier = nullptr;
143 std::future<PyObject*> fut;
144 if (nullptr == pyObj_callback && nullptr == pyObj_errback) {
145 barrier = std::make_shared<std::promise<PyObject*>>();
146 fut = barrier->get_future();
147 }
148
149 try {
150 std::string conn_str = std::string(PyUnicode_AsUTF8(pyObj_connstr));
151 auto connstr = couchbase::core::utils::parse_connection_string(conn_str);
152 auto creds = py_to_cbpp<couchbase::core::cluster_credentials>(pyObj_auth);
153
154 update_cluster_options_from_py(connstr.options, pyObj_options, pyObj_auth);
155 couchbase::core::origin origin(creds, connstr);
156
157 Py_BEGIN_ALLOW_THREADS
158 {
159 cluster_.open(
160 origin,
161 [callback = pyObj_callback, errback = pyObj_errback, barrier, this](std::error_code ec) {
162 handle_connection_operation_callback(
163 ec, "connect", callback, errback, barrier, connection_state_action::set_connected);
164 });
165 }
166 Py_END_ALLOW_THREADS
167
168 if (barrier)
169 {
170 PyObject* result = nullptr;
171 Py_BEGIN_ALLOW_THREADS result = fut.get();
172 Py_END_ALLOW_THREADS return result;
173 }
174 Py_RETURN_NONE;
175 } catch (const std::exception& e) {
176 if (barrier) {
177 barrier->set_value(nullptr);
178 }
179 PyErr_SetString(PyExc_RuntimeError, e.what());
180 Py_XDECREF(pyObj_callback);
181 Py_XDECREF(pyObj_errback);
182 return nullptr;
183 }
184}
185
186PyObject*

Callers 11

get_environmentMethod · 0.45
get_environmentMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 1

parse_connection_stringFunction · 0.85

Tested by 2

get_environmentMethod · 0.36
get_environmentMethod · 0.36