@@ -29,12 +29,12 @@ class which can be used to obtain `Driver` instances that are used for
2929from __future__ import division
3030
3131from collections import deque , namedtuple
32- from ssl import SSLContext , PROTOCOL_SSLv23 , OP_NO_SSLv2 , CERT_REQUIRED
3332
3433from .compat import integer , string , urlparse
3534from .connection import connect , Response , RUN , PULL_ALL
3635from .constants import ENCRYPTED_DEFAULT , TRUST_DEFAULT , TRUST_SIGNED_CERTIFICATES
3736from .exceptions import CypherError
37+ from .ssl_compat import SSL_AVAILABLE , SSLContext , PROTOCOL_SSLv23 , OP_NO_SSLv2 , CERT_REQUIRED
3838from .types import hydrated
3939
4040
@@ -84,6 +84,18 @@ def driver(url, **config):
8484 return Driver (url , ** config )
8585
8686
87+ _warned_about_insecure_default = False
88+
89+
90+ def _warn_about_insecure_default ():
91+ global _warned_about_insecure_default
92+ if not SSL_AVAILABLE and not _warned_about_insecure_default :
93+ from warnings import warn
94+ warn ("Bolt over TLS is only available in Python 2.7.9+ and Python 3.3+ "
95+ "so communications are not secure" )
96+ _warned_about_insecure_default = True
97+
98+
8799class Driver (object ):
88100 """ Accessor for a specific graph database resource.
89101 """
@@ -99,9 +111,15 @@ def __init__(self, url, **config):
99111 self .config = config
100112 self .max_pool_size = config .get ("max_pool_size" , DEFAULT_MAX_POOL_SIZE )
101113 self .session_pool = deque ()
102- self .encrypted = encrypted = config .get ("encrypted" , ENCRYPTED_DEFAULT )
114+ try :
115+ self .encrypted = encrypted = config ["encrypted" ]
116+ except KeyError :
117+ _warn_about_insecure_default ()
118+ self .encrypted = encrypted = ENCRYPTED_DEFAULT
103119 self .trust = trust = config .get ("trust" , TRUST_DEFAULT )
104120 if encrypted :
121+ if not SSL_AVAILABLE :
122+ raise RuntimeError ("Bolt over TLS is only available in Python 2.7.9+ and Python 3.3+" )
105123 ssl_context = SSLContext (PROTOCOL_SSLv23 )
106124 ssl_context .options |= OP_NO_SSLv2
107125 if trust >= TRUST_SIGNED_CERTIFICATES :
0 commit comments