@@ -28,14 +28,15 @@ class which can be used to obtain `Driver` instances that are used for
2828from __future__ import division
2929
3030from collections import deque , namedtuple
31- from ssl import SSLContext , PROTOCOL_SSLv23 , OP_NO_SSLv2 , CERT_REQUIRED
3231
3332from .compat import integer , string , urlparse
3433from .connection import connect , Response , RUN , PULL_ALL
3534from .constants import ENCRYPTED_DEFAULT , TRUST_DEFAULT , TRUST_SIGNED_CERTIFICATES
3635from .exceptions import CypherError , ProtocolError
36+ from .ssl_compat import SSL_AVAILABLE , SSLContext , PROTOCOL_SSLv23 , OP_NO_SSLv2 , CERT_REQUIRED
3737from .types import hydrated
3838
39+
3940DEFAULT_MAX_POOL_SIZE = 50
4041
4142STATEMENT_TYPE_READ_ONLY = "r"
@@ -82,6 +83,18 @@ def driver(url, **config):
8283 return Driver (url , ** config )
8384
8485
86+ _warned_about_insecure_default = False
87+
88+
89+ def _warn_about_insecure_default ():
90+ global _warned_about_insecure_default
91+ if not SSL_AVAILABLE and not _warned_about_insecure_default :
92+ from warnings import warn
93+ warn ("Bolt over TLS is only available in Python 2.7.9+ and Python 3.3+ "
94+ "so communications are not secure" )
95+ _warned_about_insecure_default = True
96+
97+
8598class Driver (object ):
8699 """ Accessor for a specific graph database resource.
87100 """
@@ -99,9 +112,15 @@ def __init__(self, url, **config):
99112 self .config = config
100113 self .max_pool_size = config .get ("max_pool_size" , DEFAULT_MAX_POOL_SIZE )
101114 self .session_pool = deque ()
102- self .encrypted = encrypted = config .get ("encrypted" , ENCRYPTED_DEFAULT )
115+ try :
116+ self .encrypted = encrypted = config ["encrypted" ]
117+ except KeyError :
118+ _warn_about_insecure_default ()
119+ self .encrypted = encrypted = ENCRYPTED_DEFAULT
103120 self .trust = trust = config .get ("trust" , TRUST_DEFAULT )
104121 if encrypted :
122+ if not SSL_AVAILABLE :
123+ raise RuntimeError ("Bolt over TLS is only available in Python 2.7.9+ and Python 3.3+" )
105124 ssl_context = SSLContext (PROTOCOL_SSLv23 )
106125 ssl_context .options |= OP_NO_SSLv2
107126 if trust >= TRUST_SIGNED_CERTIFICATES :
0 commit comments