11#!/usr/bin/env python
2- # Copyright (c ) 2015, 2016 IBM. All rights reserved.
2+ # Copyright (C ) 2015, 2016 IBM Corp . All rights reserved.
33#
44# Licensed under the Apache License, Version 2.0 (the "License");
55# you may not use this file except in compliance with the License.
2121import posixpath
2222import requests
2323
24- from requests .adapters import HTTPAdapter
25- from requests .packages .urllib3 .util import Retry
2624from ._2to3 import bytes_ , unicode_
2725from .database import CloudantDatabase , CouchDatabase
2826from .feed import Feed , InfiniteFeed
@@ -46,6 +44,7 @@ class CouchDB(dict):
4644 CouchDB. Defaults to ``False``.
4745 :param str encoder: Optional json Encoder object used to encode
4846 documents for storage. Defaults to json.JSONEncoder.
47+ :param requests.HTTPAdapter adapter: Optional adapter to use for configuring requests.
4948 """
5049 _DATABASE_CLASS = CouchDatabase
5150
@@ -58,6 +57,7 @@ def __init__(self, user, auth_token, admin_party=False, **kwargs):
5857 self ._client_user_header = None
5958 self .admin_party = admin_party
6059 self .encoder = kwargs .get ('encoder' ) or json .JSONEncoder
60+ self .adapter = kwargs .get ('adapter' )
6161 self .r_session = None
6262
6363 def connect (self ):
@@ -66,21 +66,9 @@ def connect(self):
6666 authentication.
6767 """
6868 self .r_session = requests .Session ()
69- # Configure a Transport Adapter for custom retry behaviour
70- self .r_session .mount (self .server_url , HTTPAdapter (
71- max_retries = Retry (
72- # Allow 10 retries for status
73- total = 10 ,
74- # No retries for connect|read errors
75- connect = 0 ,
76- read = 0 ,
77- # Allow retries for all the CouchDB HTTP method types
78- method_whitelist = frozenset (['GET' , 'HEAD' , 'PUT' , 'POST' ,
79- 'DELETE' , 'COPY' ]),
80- # Only retry for a 429 too many requests status code
81- status_forcelist = [429 ],
82- # Configure the doubling backoff to start at 0.25 s
83- backoff_factor = 0.25 )))
69+ # If a Transport Adapter was supplied add it to the session
70+ if self .adapter is not None :
71+ self .r_session .mount (self .server_url , self .adapter )
8472 if self ._client_user_header is not None :
8573 self .r_session .headers .update (self ._client_user_header )
8674 if not self .admin_party :
@@ -394,6 +382,7 @@ class Cloudant(CouchDB):
394382 the x_cloudant_user parameter setting is ignored.
395383 :param str encoder: Optional json Encoder object used to encode
396384 documents for storage. Defaults to json.JSONEncoder.
385+ :param requests.HTTPAdapter adapter: Optional adapter to use for configuring requests.
397386 """
398387 _DATABASE_CLASS = CloudantDatabase
399388
0 commit comments