116 |
116 |
117 `database` may be: |
117 `database` may be: |
118 |
118 |
119 * a simple instance id for in-memory connection |
119 * a simple instance id for in-memory connection |
120 |
120 |
121 * a uri like scheme://host:port/instanceid where scheme may be one of |
121 * a uri like scheme://host:port/instanceid where scheme must be |
122 'inmemory' or 'zmqpickle' |
122 'inmemory' |
123 |
|
124 * if scheme is handled by ZMQ (eg 'tcp'), you should not specify an |
|
125 instance id |
|
126 |
123 |
127 Other arguments: |
124 Other arguments: |
128 |
125 |
129 :login: |
126 :login: |
130 the user login to use to authenticate. |
127 the user login to use to authenticate. |
131 |
128 |
132 :cnxprops: |
129 :cnxprops: |
133 a :class:`ConnectionProperties` instance, allowing to specify |
130 a :class:`ConnectionProperties` instance, allowing to specify |
134 the connection method (eg in memory or zmq). |
131 the connection method (eg in memory). |
135 |
132 |
136 :setvreg: |
133 :setvreg: |
137 flag telling if a registry should be initialized for the connection. |
134 flag telling if a registry should be initialized for the connection. |
138 Don't change this unless you know what you're doing. |
135 Don't change this unless you know what you're doing. |
139 |
136 |
148 where it's already initialized. |
145 where it's already initialized. |
149 |
146 |
150 :kwargs: |
147 :kwargs: |
151 there goes authentication tokens. You usually have to specify a password |
148 there goes authentication tokens. You usually have to specify a password |
152 for the given user, using a named 'password' argument. |
149 for the given user, using a named 'password' argument. |
|
150 |
153 """ |
151 """ |
154 if not urlparse(database).scheme: |
152 if not urlparse(database).scheme: |
155 warn('[3.16] give an qualified URI as database instead of using ' |
153 warn('[3.16] give an qualified URI as database instead of using ' |
156 'host/cnxprops to specify the connection method', |
154 'host/cnxprops to specify the connection method', |
157 DeprecationWarning, stacklevel=2) |
155 DeprecationWarning, stacklevel=2) |
158 if cnxprops and cnxprops.cnxtype == 'zmq': |
|
159 database = kwargs.pop('host') |
|
160 elif cnxprops and cnxprops.cnxtype == 'inmemory': |
|
161 database = 'inmemory://' + database |
|
162 puri = urlparse(database) |
156 puri = urlparse(database) |
163 method = puri.scheme.lower() |
157 method = puri.scheme.lower() |
164 if method == 'inmemory': |
158 assert method == 'inmemory' |
165 config = cwconfig.instance_configuration(puri.netloc) |
159 config = cwconfig.instance_configuration(puri.netloc) |
166 else: |
|
167 config = cwconfig.CubicWebNoAppConfiguration() |
|
168 repo = get_repository(database, config=config) |
160 repo = get_repository(database, config=config) |
169 if method == 'inmemory': |
161 vreg = repo.vreg |
170 vreg = repo.vreg |
|
171 elif setvreg: |
|
172 if mulcnx: |
|
173 multiple_connections_fix() |
|
174 vreg = cwvreg.CWRegistryStore(config, initlog=initlog) |
|
175 schema = repo.get_schema() |
|
176 for oldetype, newetype in ETYPE_NAME_MAP.items(): |
|
177 if oldetype in schema: |
|
178 print 'aliasing', newetype, 'to', oldetype |
|
179 schema._entities[newetype] = schema._entities[oldetype] |
|
180 vreg.set_schema(schema) |
|
181 else: |
|
182 vreg = None |
|
183 cnx = _repo_connect(repo, login, cnxprops=cnxprops, **kwargs) |
162 cnx = _repo_connect(repo, login, cnxprops=cnxprops, **kwargs) |
184 cnx.vreg = vreg |
163 cnx.vreg = vreg |
185 return cnx |
164 return cnx |
186 |
165 |
187 def in_memory_repo(config): |
166 def in_memory_repo(config): |