Skip to content

Commit aaec0a0

Browse files
committed
Always define the session adapter
This represents no change of behaviour, but it enables us to set more options to the adapter. Signed-off-by: Amador Pahim <[email protected]>
1 parent 34d097c commit aaec0a0

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

github/Requester.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,15 @@ def __init__(
9090
self.timeout = timeout
9191
self.verify = kwargs.get("verify", True)
9292
self.session = requests.Session()
93-
# Code to support retries
94-
if retry:
93+
94+
if retry is None:
95+
self.retry = requests.adapters.DEFAULT_RETRIES
96+
else:
9597
self.retry = retry
96-
self.adapter = requests.adapters.HTTPAdapter(max_retries=self.retry)
97-
self.session.mount("https://", self.adapter)
98+
self.adapter = requests.adapters.HTTPAdapter(
99+
max_retries=self.retry,
100+
)
101+
self.session.mount("https://", self.adapter)
98102

99103
def request(self, verb, url, input, headers):
100104
self.verb = verb
@@ -130,11 +134,15 @@ def __init__(
130134
self.timeout = timeout
131135
self.verify = kwargs.get("verify", True)
132136
self.session = requests.Session()
133-
# Code to support retries
134-
if retry:
137+
138+
if retry is None:
139+
self.retry = requests.adapters.DEFAULT_RETRIES
140+
else:
135141
self.retry = retry
136-
self.adapter = requests.adapters.HTTPAdapter(max_retries=self.retry)
137-
self.session.mount("http://", self.adapter)
142+
self.adapter = requests.adapters.HTTPAdapter(
143+
max_retries=self.retry,
144+
)
145+
self.session.mount("http://", self.adapter)
138146

139147
def request(self, verb, url, input, headers):
140148
self.verb = verb
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
http
2+
GET
3+
my.enterprise.com
4+
None
5+
/repos/PyGithub/PyGithub
6+
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
7+
None
8+
200
9+
[('Date', 'Fri, 08 Jan 2021 10:42:45 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('Cache-Control', 'public, max-age=60, s-maxage=60'), ('Vary', 'Accept, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('ETag', 'W/"e132b35ca5ec517feb3106720dceb9394b5bf1f333ef886f8c407d3f2d5de3b2"'), ('Last-Modified', 'Fri, 08 Jan 2021 09:41:41 GMT'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '60'), ('X-RateLimit-Remaining', '32'), ('X-RateLimit-Reset', '1610104719'), ('X-RateLimit-Used', '28'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '9588:CCCC:9EFCE:B6C13:5FF83725')]
10+
{"id":3544490,"node_id":"MDEwOlJlcG9zaXRvcnkzNTQ0NDkw","name":"PyGithub","full_name":"PyGithub/PyGithub","private":false,"owner":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars0.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"http://my.enterprise.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"http://my.enterprise.com/users/PyGithub/followers","following_url":"http://my.enterprise.com/users/PyGithub/following{/other_user}","gists_url":"http://my.enterprise.com/users/PyGithub/gists{/gist_id}","starred_url":"http://my.enterprise.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"http://my.enterprise.com/users/PyGithub/subscriptions","organizations_url":"http://my.enterprise.com/users/PyGithub/orgs","repos_url":"http://my.enterprise.com/users/PyGithub/repos","events_url":"http://my.enterprise.com/users/PyGithub/events{/privacy}","received_events_url":"http://my.enterprise.com/users/PyGithub/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/PyGithub/PyGithub","description":"Typed interactions with the GitHub API v3","fork":false,"url":"http://my.enterprise.com/repos/PyGithub/PyGithub","forks_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/forks","keys_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/keys{/key_id}","collaborators_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/collaborators{/collaborator}","teams_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/teams","hooks_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/hooks","issue_events_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/issues/events{/number}","events_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/events","assignees_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/assignees{/user}","branches_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/branches{/branch}","tags_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/tags","blobs_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/blobs{/sha}","git_tags_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/tags{/sha}","git_refs_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/refs{/sha}","trees_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/trees{/sha}","statuses_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/statuses/{sha}","languages_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/languages","stargazers_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/stargazers","contributors_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/contributors","subscribers_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/subscribers","subscription_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/subscription","commits_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/commits{/sha}","git_commits_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/git/commits{/sha}","comments_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/comments{/number}","issue_comment_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/issues/comments{/number}","contents_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/contents/{+path}","compare_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/compare/{base}...{head}","merges_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/merges","archive_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/{archive_format}{/ref}","downloads_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/downloads","issues_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/issues{/number}","pulls_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/pulls{/number}","milestones_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/milestones{/number}","notifications_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/notifications{?since,all,participating}","labels_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/labels{/name}","releases_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/releases{/id}","deployments_url":"http://my.enterprise.com/repos/PyGithub/PyGithub/deployments","created_at":"2012-02-25T12:53:47Z","updated_at":"2021-01-08T09:41:41Z","pushed_at":"2021-01-07T18:49:51Z","git_url":"git://github.com/PyGithub/PyGithub.git","ssh_url":"[email protected]:PyGithub/PyGithub.git","clone_url":"https://github.com/PyGithub/PyGithub.git","svn_url":"https://github.com/PyGithub/PyGithub","homepage":"https://pygithub.readthedocs.io/","size":13251,"stargazers_count":4000,"watchers_count":4000,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1245,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":82,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"http://my.enterprise.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":1245,"open_issues":82,"watchers":4000,"default_branch":"master","temp_clone_token":null,"organization":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars0.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"http://my.enterprise.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"http://my.enterprise.com/users/PyGithub/followers","following_url":"http://my.enterprise.com/users/PyGithub/following{/other_user}","gists_url":"http://my.enterprise.com/users/PyGithub/gists{/gist_id}","starred_url":"http://my.enterprise.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"http://my.enterprise.com/users/PyGithub/subscriptions","organizations_url":"http://my.enterprise.com/users/PyGithub/orgs","repos_url":"http://my.enterprise.com/users/PyGithub/repos","events_url":"http://my.enterprise.com/users/PyGithub/events{/privacy}","received_events_url":"http://my.enterprise.com/users/PyGithub/received_events","type":"Organization","site_admin":false},"network_count":1245,"subscribers_count":105}
11+

tests/Retry.py

+11
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@ def testRaisesRetryErrorAfterMaxRetries(self):
7575
self.assertEqual(len(httpretty.latest_requests), 4)
7676
for request in httpretty.latest_requests:
7777
self.assertEqual(request.path, "/repos/PyGithub/PyGithub")
78+
79+
def testReturnsRepoAfterSettingRetryHttp(self):
80+
g = github.Github(
81+
self.login,
82+
self.password,
83+
base_url="http://my.enterprise.com",
84+
retry=0,
85+
) # http here
86+
repository = g.get_repo(REPO_NAME)
87+
self.assertIsInstance(repository, github.Repository.Repository)
88+
self.assertEqual(repository.full_name, REPO_NAME)

0 commit comments

Comments
 (0)