1919# limitations under the License.
2020
2121"""
22- This module contains the main Bolt driver components as well as several
23- helper and exception classes. The main entry point is the `GraphDatabase`
24- class which can be used to obtain `Driver` instances that are used for
25- managing sessions.
22+ This module contains the main user-facing abstractions. The main entry
23+ point is the `GraphDatabase` class which can be used to obtain `Driver`
24+ instances that are in turn used for managing sessions.
2625"""
2726
2827
@@ -42,16 +41,6 @@ class which can be used to obtain `Driver` instances that are used for
4241DEFAULT_MAX_POOL_SIZE = 50
4342
4443
45- def basic_auth (user , password ):
46- """ Generate a basic auth token for a given user and password.
47-
48- :param user: user name
49- :param password: current password
50- :return: auth token for use with :meth:`GraphDatabase.driver`
51- """
52- return AuthToken ("basic" , user , password )
53-
54-
5544class AuthToken (object ):
5645 """ Container for auth information
5746 """
@@ -80,18 +69,6 @@ def driver(url, **config):
8069 return Driver (url , ** config )
8170
8271
83- _warned_about_insecure_default = False
84-
85-
86- def _warn_about_insecure_default ():
87- global _warned_about_insecure_default
88- if not SSL_AVAILABLE and not _warned_about_insecure_default :
89- from warnings import warn
90- warn ("Bolt over TLS is only available in Python 2.7.9+ and Python 3.3+ "
91- "so communications are not secure" )
92- _warned_about_insecure_default = True
93-
94-
9572class Driver (object ):
9673 """ Accessor for a specific graph database resource.
9774 """
@@ -286,41 +263,6 @@ def peek(self):
286263 raise ResultError ("End of stream" )
287264
288265
289- def run (connection , statement , parameters = None ):
290- """ Run a Cypher statement on a given connection.
291-
292- :param connection: connection to carry the request and response
293- :param statement: Cypher statement
294- :param parameters: optional dictionary of parameters
295- :return: statement result
296- """
297- # Ensure the statement is a Unicode value
298- if isinstance (statement , bytes ):
299- statement = statement .decode ("UTF-8" )
300-
301- params = {}
302- for key , value in (parameters or {}).items ():
303- if isinstance (key , bytes ):
304- key = key .decode ("UTF-8" )
305- if isinstance (value , bytes ):
306- params [key ] = value .decode ("UTF-8" )
307- else :
308- params [key ] = value
309- parameters = params
310-
311- run_response = Response (connection )
312- pull_all_response = Response (connection )
313- result = StatementResult (connection , run_response , pull_all_response )
314- result .statement = statement
315- result .parameters = parameters
316-
317- connection .append (RUN , (statement , parameters ), response = run_response )
318- connection .append (PULL_ALL , response = pull_all_response )
319- connection .send ()
320-
321- return result
322-
323-
324266class Session (object ):
325267 """ Logical session carried out over an established TCP connection.
326268 Sessions should generally be constructed using the :meth:`.Driver.session`
@@ -529,3 +471,60 @@ def __eq__(self, other):
529471
530472 def __ne__ (self , other ):
531473 return not self .__eq__ (other )
474+
475+
476+ def basic_auth (user , password ):
477+ """ Generate a basic auth token for a given user and password.
478+
479+ :param user: user name
480+ :param password: current password
481+ :return: auth token for use with :meth:`GraphDatabase.driver`
482+ """
483+ return AuthToken ("basic" , user , password )
484+
485+
486+ def run (connection , statement , parameters = None ):
487+ """ Run a Cypher statement on a given connection.
488+
489+ :param connection: connection to carry the request and response
490+ :param statement: Cypher statement
491+ :param parameters: optional dictionary of parameters
492+ :return: statement result
493+ """
494+ # Ensure the statement is a Unicode value
495+ if isinstance (statement , bytes ):
496+ statement = statement .decode ("UTF-8" )
497+
498+ params = {}
499+ for key , value in (parameters or {}).items ():
500+ if isinstance (key , bytes ):
501+ key = key .decode ("UTF-8" )
502+ if isinstance (value , bytes ):
503+ params [key ] = value .decode ("UTF-8" )
504+ else :
505+ params [key ] = value
506+ parameters = params
507+
508+ run_response = Response (connection )
509+ pull_all_response = Response (connection )
510+ result = StatementResult (connection , run_response , pull_all_response )
511+ result .statement = statement
512+ result .parameters = parameters
513+
514+ connection .append (RUN , (statement , parameters ), response = run_response )
515+ connection .append (PULL_ALL , response = pull_all_response )
516+ connection .send ()
517+
518+ return result
519+
520+
521+ _warned_about_insecure_default = False
522+
523+
524+ def _warn_about_insecure_default ():
525+ global _warned_about_insecure_default
526+ if not SSL_AVAILABLE and not _warned_about_insecure_default :
527+ from warnings import warn
528+ warn ("Bolt over TLS is only available in Python 2.7.9+ and Python 3.3+ "
529+ "so communications are not secure" )
530+ _warned_about_insecure_default = True
0 commit comments