1616# Copyright 2010-2016 RethinkDB, all rights reserved.
1717
1818import warnings
19+ from types import SimpleNamespace
20+
21+ from rethinkdb import net
22+ # pylint: disable=redefined-builtin
23+ from rethinkdb .query import (
24+ add ,and_ ,april ,args ,asc ,august ,avg ,binary ,bit_and ,bit_not ,bit_or ,
25+ bit_sal ,bit_sar ,bit_xor ,branch ,ceil ,circle ,contains ,count ,db ,
26+ db_create ,db_drop ,db_list ,december ,desc ,distance ,distinct ,div ,do ,
27+ epoch_time ,eq ,error ,february ,floor ,format ,friday ,ge ,geojson ,grant ,
28+ group ,gt ,http ,info ,intersects ,iso8601 ,january ,json ,july ,june ,le ,
29+ line ,literal ,lt ,make_timezone ,map ,march ,max ,maxval ,may ,min ,minval ,
30+ mod ,monday ,mul ,ne ,not_ ,november ,now ,object ,october ,or_ ,point ,
31+ polygon ,random ,range ,reduce ,round ,row ,saturday ,september ,sub ,sum ,
32+ sunday ,table ,table_create ,table_drop ,table_list ,thursday ,time ,tuesday ,
33+ type_of ,union ,uuid ,wednesday ,js
34+ )
35+ # pylint: enable=redefined-builtin
1936
20- from rethinkdb import errors # , version
21-
22- __all__ = ["r" ,"RethinkDB" ]
2337__version__ = "2.5.0"
2438
25-
26- class RethinkDB :
39+ # Create the r namespace object containing all query functions
40+ r = SimpleNamespace ()
41+
42+ query_functions = {
43+ 'add' :add ,'and_' :and_ ,'april' :april ,'args' :args ,'asc' :asc ,
44+ 'august' :august ,'avg' :avg ,'binary' :binary ,'bit_and' :bit_and ,
45+ 'bit_not' :bit_not ,'bit_or' :bit_or ,'bit_sal' :bit_sal ,'bit_sar' :bit_sar ,
46+ 'bit_xor' :bit_xor ,'branch' :branch ,'ceil' :ceil ,'circle' :circle ,
47+ 'contains' :contains ,'count' :count ,'db' :db ,'db_create' :db_create ,
48+ 'db_drop' :db_drop ,'db_list' :db_list ,'december' :december ,'desc' :desc ,
49+ 'distance' :distance ,'distinct' :distinct ,'div' :div ,'do' :do ,
50+ 'epoch_time' :epoch_time ,'eq' :eq ,'error' :error ,'february' :february ,
51+ 'floor' :floor ,'format' :format ,'friday' :friday ,'ge' :ge ,'geojson' :geojson ,
52+ 'grant' :grant ,'group' :group ,'gt' :gt ,'http' :http ,'info' :info ,
53+ 'intersects' :intersects ,'iso8601' :iso8601 ,'january' :january ,'json' :json ,
54+ 'july' :july ,'june' :june ,'le' :le ,'line' :line ,'literal' :literal ,
55+ 'lt' :lt ,'make_timezone' :make_timezone ,'map' :map ,'march' :march ,
56+ 'max' :max ,'maxval' :maxval ,'may' :may ,'min' :min ,'minval' :minval ,
57+ 'mod' :mod ,'monday' :monday ,'mul' :mul ,'ne' :ne ,'not_' :not_ ,
58+ 'november' :november ,'now' :now ,'object' :object ,'october' :october ,
59+ 'or_' :or_ ,'point' :point ,'polygon' :polygon ,'random' :random ,
60+ 'range' :range ,'reduce' :reduce ,'round' :round ,'row' :row ,
61+ 'saturday' :saturday ,'september' :september ,'sub' :sub ,'sum' :sum ,
62+ 'sunday' :sunday ,'table' :table ,'table_create' :table_create ,
63+ 'table_drop' :table_drop ,'table_list' :table_list ,'thursday' :thursday ,
64+ 'time' :time ,'tuesday' :tuesday ,'type_of' :type_of ,'union' :union ,
65+ 'uuid' :uuid ,'wednesday' :wednesday ,'js' :js
66+ }
67+
68+ for name ,func in query_functions .items ():
69+ setattr (r ,name ,func )
70+
71+
72+ class Client :
2773"""
28- RethinkDB serves as an entrypoint for queries .
74+ Client is a wrapper around RethinkDB connection handling .
2975
3076 It constructs the connection handlers and event loops, re-exports internal modules for easier
3177 use, and sets the event loop.
@@ -34,23 +80,11 @@ class RethinkDB:
3480def __init__ (self ):
3581super ().__init__ ()
3682
37- # pylint: disable=import-outside-toplevel
38- from rethinkdb import ast ,net ,query
39-
40- # Re-export internal modules for backward compatibility
41- self .ast = ast
42- self .errors = errors
4383self .net = net
44- self .query = query
4584
4685net .Connection ._r = self
4786self .connection_type = None
4887
49- # Dynamically assign every re-exported internal module's function to self
50- for module in (self .net ,self .query ,self .ast ,self .errors ):
51- for function_name in module .__all__ :
52- setattr (self ,function_name ,getattr (module ,function_name ))
53-
5488# Ensure the `make_connection` function is not overridden accidentally
5589self .make_connection = self .net .make_connection
5690self .set_loop_type (None )
@@ -83,12 +117,9 @@ def set_loop_type(self, library=None) -> None:
83117if library is None or self .connection_type is None :
84118self .connection_type = self .net .DefaultConnection
85119
86- def connect (self ,* args ,** kwargs ):
120+ def connect (self ,* connect_args ,** kwargs ):
87121"""
88122 Make a connection to the database.
89123 """
90124
91- return self .make_connection (self .connection_type ,* args ,** kwargs )
92-
93-
94- r = RethinkDB ()
125+ return self .make_connection (self .connection_type ,* connect_args ,** kwargs )