anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: ably/ably-python
Issue: HTTP connection pooling

A customer has reported that when doing this they get expected reuse of the HTTP connection pooling:

```python
client = AblyRest('api:key')
channel = client.channels.get('channel_name')
channel.publish('foo', 'bar')
# Slower request expected as new TCP TLS connection needed 
channel.publish('foo', 'bar')
# Faster as previous connection reused automatically
```

However, when they do this, they don't get HTTP connection reuse:

```python
client = AblyRest('api:key')
channel = client.channels.get('channel_name')
channel.publish('foo', 'bar')
# Slower request expected as new TCP TLS connection needed 
client2 = AblyRest('api:key')
channel2 = client2.channels.get('channel_name')
channel2.publish('foo', 'bar')
# Equally slow request as first
```

In other libraries, the underlying HTTP library automatically handles connection reuse so long as the requests are in the same process, whereas with Python it seems this is not the case and the pooling is only done with the instance REST client.

This is not the intended behaviour.

Changed files:
ably/http/http.py, ably/rest/rest.py

diff --git a/ably/http/http.py b/ably/http/http.py
index 8f077e5..a01e693 100644
--- a/ably/http/http.py
+++ b/ably/http/http.py
@@ -105,12 +105,13 @@ class Http(object):
         'http_max_retry_duration': 15,
     }
 
+    __session = requests.Session()
+
     def __init__(self, ably, options):
         options = options or {}
         self.__ably = ably
         self.__options = options
 
-        self.__session = requests.Session()
         self.__auth = None
 
     def dump_body(self, body):
diff --git a/ably/rest/rest.py b/ably/rest/rest.py
index c6749f3..2068564 100644
--- a/ably/rest/rest.py
+++ b/ably/rest/rest.py
@@ -64,11 +64,6 @@ class AblyRest(object):
         else:
             options = Options(**kwargs)
 
-        # if self.__keep_alive:
-        #     self.__session = requests.Session()
-        # else:
-        #     self.__session = None
-
         self.__http = Http(self, options)
         self.__auth = Auth(self, options)
         self.__http.auth = self.__auth
Repository: ably/ably-python
Issue: Do not persist authorise attributes force & timestamp 

A recent discovery in the iOS library has unearthed a small shortcoming in the spec, corrected at https://github.com/ably/docs/commit/f768f0db76020d945cf34974ef7d14d36113f0cd


Changed files:
ably/rest/auth.py, ably/types/authoptions.py, test/ably/restauth_test.py

diff --git a/ably/rest/auth.py b/ably/rest/auth.py
index 49a1201..c4c8a86 100644
--- a/ably/rest/auth.py
+++ b/ably/rest/auth.py
@@ -81,6 +81,7 @@ class Auth(object):
             token_params = dict(self.auth_options.default_token_params,
                                 **token_params)
             self.auth_options.default_token_params = dict(token_params)
+            self.auth_options.default_token_params.pop('timestamp', None)
 
         if auth_options is not None:
             force = auth_options.pop('force', None) or force
diff --git a/ably/types/authoptions.py b/ably/types/authoptions.py
index bda7f65..4516e8c 100644
--- a/ably/types/authoptions.py
+++ b/ably/types/authoptions.py
@@ -20,7 +20,9 @@ class AuthOptions(object):
         self.auth_options['auth_params'] = auth_params
         self.__token_details = token_details
         self.__use_token_auth = use_token_auth
-        self.default_token_params = default_token_params or {}
+        default_token_params = default_token_params or {}
+        default_token_params.pop('timestamp', None)
+        self.default_token_params = default_token_params
         if key is not None:
             self.auth_options['key_name'], self.auth_options['key_secret'] = (
                 self.parse_key(key))
diff --git a/test/ably/restauth_test.py b/test/ably/restauth_test.py
index ba029b0..41fc8b8 100644
--- a/test/ably/restauth_test.py
+++ b/test/ably/restauth_test.py
@@ -284,6 +284,18 @@ class TestAuthAuthorize(BaseTestCase):
         self.assertEqual(token_called[0], {'ttl': 555, 'client_id': 'new_id'})
         self.assertEqual(auth_called['auth_headers'], {'a_headers': 'a_value'})
 
+    def test_force_and_timestamp_are_not_stored(self):
+        time = self.ably.time()
+        self.ably.auth.authorise(
+            {'ttl': 555, 'client_id': 'new_id', 'timestamp': time},
+            {'auth_headers': {'a_headers': 'a_value'}, 'force': True})
+        with mock.patch('ably.rest.auth.Auth.request_token') as request_mock:
+            self.ably.auth.authorise(force=True)
+
+        token_called, auth_called = request_mock.call_args
+        self.assertEqual(token_called[0], {'ttl': 555, 'client_id': 'new_id'})
+        self.assertEqual(auth_called['auth_headers'], {'a_headers': 'a_value'})
+
 @six.add_metaclass(VaryByProtocolTestsMetaclass)
 class TestRequestToken(BaseTestCase):