1066
1066
super(ConnectedTransport, self).__init__(base)
1067
1067
if from_transport is None:
1068
# We use a list as a container for the connection so that the
1069
# connection will be shared even if a transport is cloned before
1070
# the first effective connection (generally the first request
1071
# made). It also guarantees that the connection will still be
1072
# shared if a transport needs to reconnect after a temporary
1074
self._connection = [None]
1068
self._init_connection()
1070
# set_connection MUST not be used here, see set_connection for an
1076
1072
self._connection = from_transport._connection
1078
1074
def clone(self, offset=None):
1212
1208
remote_path = self._combine_paths(self._path, relative)
1213
1209
return remote_path
1215
def set_connection(self, connection):
1211
def _init_connection(self):
1212
self._connection = [(None, None)]
1214
def _set_connection(self, connection, credentials=None):
1216
1215
"""Set the transport specific connection object.
1218
1217
Note: To ensure that connection is still shared after a temporary
1219
1218
failure and a new one needs to be created, daughter classes should
1220
always call this method to set the connection. No assumptions are made
1221
about the object type of the connection object.
1219
always call this method to set the connection.
1221
:param connection: An opaque object representing the connection used by
1224
:param credentials: An opaque object representing the credentials
1225
needed to create the connection.
1223
self._connection[0] = connection
1225
def get_connection(self):
1227
# We use a list as a container for the connection so that the
1228
# connection will be shared even if a transport is cloned before the
1229
# first effective connection (generally the first request made). It
1230
# also guarantees that the connection will still be shared if a
1231
# transport needs to reconnect after a temporary failure.
1233
self._connection[0] = (connection, credentials)
1235
def _get_connection(self):
1226
1236
"""Returns the transport specific connection object."""
1227
return self._connection[0]
1237
return self._connection[0][0]
1239
def _get_credentials(self):
1240
"""Returns the credentials needed to establish a connection."""
1241
(connection, credentials) = self._connection[0]
1242
return self._connection[0][1]
1231
1245
# jam 20060426 For compatibility we copy the functions here