15
15
# This file incorporates work covered by the following copyright:
16
16
# Copyright 2010-2016 RethinkDB, all rights reserved.
17
17
18
- # pylint: disable=redefined-builtin, unused-import
19
18
20
- from types import SimpleNamespace
21
- import warnings
22
-
23
- from rethinkdb import net
24
- from rethinkdb .ast import expr
25
- from rethinkdb .query import (
26
- add ,
27
- and_ ,
28
- april ,
29
- args ,
30
- asc ,
31
- august ,
32
- avg ,
33
- binary ,
34
- bit_and ,
35
- bit_not ,
36
- bit_or ,
37
- bit_sal ,
38
- bit_sar ,
39
- bit_xor ,
40
- branch ,
41
- ceil ,
42
- circle ,
43
- contains ,
44
- count ,
45
- db ,
46
- db_create ,
47
- db_drop ,
48
- db_list ,
49
- december ,
50
- desc ,
51
- distance ,
52
- distinct ,
53
- div ,
54
- do ,
55
- epoch_time ,
56
- eq ,
57
- error ,
58
- february ,
59
- floor ,
60
- format ,
61
- friday ,
62
- ge ,
63
- geojson ,
64
- grant ,
65
- group ,
66
- gt ,
67
- http ,
68
- info ,
69
- intersects ,
70
- iso8601 ,
71
- january ,
72
- js ,
73
- json ,
74
- july ,
75
- june ,
76
- le ,
77
- line ,
78
- literal ,
79
- lt ,
80
- make_timezone ,
81
- map ,
82
- march ,
83
- max ,
84
- maxval ,
85
- may ,
86
- min ,
87
- minval ,
88
- mod ,
89
- monday ,
90
- mul ,
91
- ne ,
92
- not_ ,
93
- november ,
94
- now ,
95
- object ,
96
- october ,
97
- or_ ,
98
- point ,
99
- polygon ,
100
- random ,
101
- range ,
102
- reduce ,
103
- round ,
104
- row ,
105
- saturday ,
106
- september ,
107
- sub ,
108
- sum ,
109
- sunday ,
110
- table ,
111
- table_create ,
112
- table_drop ,
113
- table_list ,
114
- thursday ,
115
- time ,
116
- tuesday ,
117
- type_of ,
118
- union ,
119
- uuid ,
120
- wednesday ,
121
- )
122
-
123
- # pylint: enable=redefined-builtin, unused-import
124
-
125
- __version__ = "2.5.0"
126
-
127
- # Create the r namespace object containing all query functions
128
- r = SimpleNamespace ()
129
-
130
- query_functions = {
131
- "add" : add ,
132
- "and_" : and_ ,
133
- "april" : april ,
134
- "args" : args ,
135
- "asc" : asc ,
136
- "august" : august ,
137
- "avg" : avg ,
138
- "binary" : binary ,
139
- "bit_and" : bit_and ,
140
- "bit_not" : bit_not ,
141
- "bit_or" : bit_or ,
142
- "bit_sal" : bit_sal ,
143
- "bit_sar" : bit_sar ,
144
- "bit_xor" : bit_xor ,
145
- "branch" : branch ,
146
- "ceil" : ceil ,
147
- "circle" : circle ,
148
- "contains" : contains ,
149
- "count" : count ,
150
- "db" : db ,
151
- "db_create" : db_create ,
152
- "db_drop" : db_drop ,
153
- "db_list" : db_list ,
154
- "december" : december ,
155
- "desc" : desc ,
156
- "distance" : distance ,
157
- "distinct" : distinct ,
158
- "div" : div ,
159
- "do" : do ,
160
- "epoch_time" : epoch_time ,
161
- "eq" : eq ,
162
- "expr" : expr ,
163
- "error" : error ,
164
- "february" : february ,
165
- "floor" : floor ,
166
- "format" : format ,
167
- "friday" : friday ,
168
- "ge" : ge ,
169
- "geojson" : geojson ,
170
- "grant" : grant ,
171
- "group" : group ,
172
- "gt" : gt ,
173
- "http" : http ,
174
- "info" : info ,
175
- "intersects" : intersects ,
176
- "iso8601" : iso8601 ,
177
- "january" : january ,
178
- "json" : json ,
179
- "july" : july ,
180
- "june" : june ,
181
- "le" : le ,
182
- "line" : line ,
183
- "literal" : literal ,
184
- "lt" : lt ,
185
- "make_timezone" : make_timezone ,
186
- "map" : map ,
187
- "march" : march ,
188
- "max" : max ,
189
- "maxval" : maxval ,
190
- "may" : may ,
191
- "min" : min ,
192
- "minval" : minval ,
193
- "mod" : mod ,
194
- "monday" : monday ,
195
- "mul" : mul ,
196
- "ne" : ne ,
197
- "not_" : not_ ,
198
- "november" : november ,
199
- "now" : now ,
200
- "object" : object ,
201
- "october" : october ,
202
- "or_" : or_ ,
203
- "point" : point ,
204
- "polygon" : polygon ,
205
- "random" : random ,
206
- "range" : range ,
207
- "reduce" : reduce ,
208
- "round" : round ,
209
- "row" : row ,
210
- "saturday" : saturday ,
211
- "september" : september ,
212
- "sub" : sub ,
213
- "sum" : sum ,
214
- "sunday" : sunday ,
215
- "table" : table ,
216
- "table_create" : table_create ,
217
- "table_drop" : table_drop ,
218
- "table_list" : table_list ,
219
- "thursday" : thursday ,
220
- "time" : time ,
221
- "tuesday" : tuesday ,
222
- "type_of" : type_of ,
223
- "union" : union ,
224
- "uuid" : uuid ,
225
- "wednesday" : wednesday ,
226
- "js" : js ,
227
- }
228
-
229
- for name , func in query_functions .items ():
230
- setattr (r , name , func )
231
-
232
-
233
- class Client :
19
+ class RethinkDB :
234
20
"""
235
- Client is a wrapper around RethinkDB connection handling.
21
+ RethinkDB is a wrapper around RethinkDB connection handling.
236
22
237
23
It constructs the connection handlers and event loops, re-exports internal modules for easier
238
24
use, and sets the event loop.
@@ -241,9 +27,22 @@ class Client:
241
27
def __init__ (self ):
242
28
super ().__init__ ()
243
29
30
+ # pylint: disable=import-outside-toplevel
31
+ from rethinkdb import ast , errors , net , query
32
+
33
+ self .ast = ast
34
+ self .errors = errors
35
+ self .net = net
36
+ self .query = query
37
+
244
38
net .Connection ._r = self
245
39
self .connection_type = None
246
40
41
+ # Dynamically assign every re-exported internal module's function to self
42
+ for module in (self .net , self .query , self .ast , self .errors ):
43
+ for function_name in module .__all__ :
44
+ setattr (self , function_name , getattr (module , function_name ))
45
+
247
46
self .make_connection = net .make_connection
248
47
self .set_loop_type (None )
249
48
@@ -253,8 +52,10 @@ def set_loop_type(self, library=None) -> None:
253
52
"""
254
53
255
54
if library == "asyncio" :
256
- warnings .warn (f"{ library } is not yet supported, using the default one" )
257
- library = None
55
+ # pylint: disable=import-outside-toplevel
56
+ from rethinkdb .net_asyncio import Connection as AsyncioConnection
57
+
58
+ self .connection_type = AsyncioConnection
258
59
259
60
if library == "gevent" :
260
61
# pylint: disable=import-outside-toplevel
@@ -269,8 +70,10 @@ def set_loop_type(self, library=None) -> None:
269
70
self .connection_type = TornadoConnection
270
71
271
72
if library == "trio" :
272
- warnings .warn (f"{ library } is not yet supported, using the default one" )
273
- library = None
73
+ # pylint: disable=import-outside-toplevel
74
+ from rethinkdb .net_trio import Connection as TrioConnection
75
+
76
+ self .connection_type = TrioConnection
274
77
275
78
if library == "twisted" :
276
79
# pylint: disable=import-outside-toplevel
@@ -279,11 +82,17 @@ def set_loop_type(self, library=None) -> None:
279
82
self .connection_type = TwistedConnection
280
83
281
84
if library is None or self .connection_type is None :
282
- self .connection_type = net .DefaultConnection
85
+ # pylint: disable=import-outside-toplevel
86
+ from rethinkdb .net import DefaultConnection
87
+
88
+ self .connection_type = DefaultConnection
283
89
284
90
def connect (self , * connect_args , ** kwargs ):
285
91
"""
286
92
Make a connection to the database.
287
93
"""
288
94
289
95
return self .make_connection (self .connection_type , * connect_args , ** kwargs )
96
+
97
+
98
+ r = RethinkDB ()
0 commit comments