PyGithub-asyncio 3.0.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- githubasyncio/AccessToken.py +159 -0
- githubasyncio/AdvisoryBase.py +163 -0
- githubasyncio/AdvisoryCredit.py +131 -0
- githubasyncio/AdvisoryCreditDetailed.py +110 -0
- githubasyncio/AdvisoryVulnerability.py +191 -0
- githubasyncio/AdvisoryVulnerabilityPackage.py +93 -0
- githubasyncio/AppAuthentication.py +58 -0
- githubasyncio/ApplicationOAuth.py +200 -0
- githubasyncio/Artifact.py +183 -0
- githubasyncio/Auth.py +560 -0
- githubasyncio/AuthenticatedUser.py +1251 -0
- githubasyncio/Authorization.py +192 -0
- githubasyncio/AuthorizationApplication.py +73 -0
- githubasyncio/Autolink.py +104 -0
- githubasyncio/Branch.py +689 -0
- githubasyncio/BranchProtection.py +224 -0
- githubasyncio/CVSS.py +83 -0
- githubasyncio/CWE.py +75 -0
- githubasyncio/CheckRun.py +315 -0
- githubasyncio/CheckRunAnnotation.py +134 -0
- githubasyncio/CheckRunOutput.py +108 -0
- githubasyncio/CheckSuite.py +319 -0
- githubasyncio/Clones.py +97 -0
- githubasyncio/CodeScanAlert.py +215 -0
- githubasyncio/CodeScanAlertInstance.py +134 -0
- githubasyncio/CodeScanAlertInstanceLocation.py +102 -0
- githubasyncio/CodeScanRule.py +134 -0
- githubasyncio/CodeScanTool.py +94 -0
- githubasyncio/CodeSecurityConfig.py +301 -0
- githubasyncio/CodeSecurityConfigRepository.py +70 -0
- githubasyncio/Commit.py +442 -0
- githubasyncio/CommitCombinedStatus.py +126 -0
- githubasyncio/CommitComment.py +270 -0
- githubasyncio/CommitStats.py +78 -0
- githubasyncio/CommitStatus.py +169 -0
- githubasyncio/Comparison.py +219 -0
- githubasyncio/Consts.py +197 -0
- githubasyncio/ContentFile.py +304 -0
- githubasyncio/Copilot.py +97 -0
- githubasyncio/CopilotSeat.py +132 -0
- githubasyncio/DefaultCodeSecurityConfig.py +93 -0
- githubasyncio/DependabotAlert.py +184 -0
- githubasyncio/DependabotAlertAdvisory.py +82 -0
- githubasyncio/DependabotAlertDependency.py +100 -0
- githubasyncio/DependabotAlertVulnerability.py +85 -0
- githubasyncio/Deployment.py +314 -0
- githubasyncio/DeploymentBranchPolicy.py +102 -0
- githubasyncio/DeploymentStatus.py +201 -0
- githubasyncio/DiscussionBase.py +140 -0
- githubasyncio/DiscussionCommentBase.py +140 -0
- githubasyncio/Download.py +256 -0
- githubasyncio/Enterprise.py +175 -0
- githubasyncio/EnterpriseConsumedLicenses.py +138 -0
- githubasyncio/Environment.py +354 -0
- githubasyncio/EnvironmentDeploymentBranchPolicy.py +87 -0
- githubasyncio/EnvironmentProtectionRule.py +117 -0
- githubasyncio/EnvironmentProtectionRuleReviewer.py +110 -0
- githubasyncio/Event.py +134 -0
- githubasyncio/File.py +142 -0
- githubasyncio/GeneratedReleaseNotes.py +68 -0
- githubasyncio/Gist.py +373 -0
- githubasyncio/GistComment.py +162 -0
- githubasyncio/GistFile.py +106 -0
- githubasyncio/GistHistoryState.py +245 -0
- githubasyncio/GitAuthor.py +94 -0
- githubasyncio/GitBlob.py +123 -0
- githubasyncio/GitCommit.py +208 -0
- githubasyncio/GitCommitVerification.py +103 -0
- githubasyncio/GitObject.py +84 -0
- githubasyncio/GitRef.py +122 -0
- githubasyncio/GitRelease.py +476 -0
- githubasyncio/GitReleaseAsset.py +232 -0
- githubasyncio/GitTag.py +143 -0
- githubasyncio/GitTree.py +113 -0
- githubasyncio/GitTreeElement.py +104 -0
- githubasyncio/GithubApp.py +236 -0
- githubasyncio/GithubException.py +226 -0
- githubasyncio/GithubIntegration.py +365 -0
- githubasyncio/GithubObject.py +910 -0
- githubasyncio/GithubRetry.py +253 -0
- githubasyncio/GitignoreTemplate.py +88 -0
- githubasyncio/GlobalAdvisory.py +141 -0
- githubasyncio/Hook.py +238 -0
- githubasyncio/HookDelivery.py +243 -0
- githubasyncio/HookDescription.py +85 -0
- githubasyncio/HookResponse.py +83 -0
- githubasyncio/InputFileContent.py +63 -0
- githubasyncio/InputGitAuthor.py +71 -0
- githubasyncio/InputGitTreeElement.py +79 -0
- githubasyncio/Installation.py +298 -0
- githubasyncio/InstallationAuthorization.py +138 -0
- githubasyncio/Invitation.py +171 -0
- githubasyncio/Issue.py +955 -0
- githubasyncio/IssueComment.py +309 -0
- githubasyncio/IssueDependenciesSummary.py +77 -0
- githubasyncio/IssueEvent.py +296 -0
- githubasyncio/IssuePullRequest.py +97 -0
- githubasyncio/IssueType.py +123 -0
- githubasyncio/Label.py +186 -0
- githubasyncio/License.py +169 -0
- githubasyncio/MainClass.py +1142 -0
- githubasyncio/Membership.py +154 -0
- githubasyncio/MergedUpstream.py +71 -0
- githubasyncio/Migration.py +281 -0
- githubasyncio/Milestone.py +255 -0
- githubasyncio/NamedEnterpriseUser.py +207 -0
- githubasyncio/NamedUser.py +841 -0
- githubasyncio/Notification.py +182 -0
- githubasyncio/NotificationSubject.py +96 -0
- githubasyncio/Organization.py +2462 -0
- githubasyncio/OrganizationCodeScanAlert.py +65 -0
- githubasyncio/OrganizationCustomProperty.py +215 -0
- githubasyncio/OrganizationDependabotAlert.py +75 -0
- githubasyncio/OrganizationSecret.py +191 -0
- githubasyncio/OrganizationSecretScanAlert.py +112 -0
- githubasyncio/OrganizationVariable.py +141 -0
- githubasyncio/PaginatedList.py +652 -0
- githubasyncio/Path.py +102 -0
- githubasyncio/Permissions.py +113 -0
- githubasyncio/Plan.py +108 -0
- githubasyncio/Project.py +286 -0
- githubasyncio/ProjectCard.py +257 -0
- githubasyncio/ProjectColumn.py +227 -0
- githubasyncio/PublicKey.py +138 -0
- githubasyncio/PullRequest.py +1202 -0
- githubasyncio/PullRequestComment.py +401 -0
- githubasyncio/PullRequestMergeStatus.py +89 -0
- githubasyncio/PullRequestPart.py +110 -0
- githubasyncio/PullRequestReview.py +214 -0
- githubasyncio/Rate.py +123 -0
- githubasyncio/RateLimit.py +210 -0
- githubasyncio/RateLimitOverview.py +104 -0
- githubasyncio/Reaction.py +128 -0
- githubasyncio/Referrer.py +94 -0
- githubasyncio/RepoCodeSecurityConfig.py +93 -0
- githubasyncio/Repository.py +5211 -0
- githubasyncio/RepositoryAdvisory.py +431 -0
- githubasyncio/RepositoryDiscussion.py +221 -0
- githubasyncio/RepositoryDiscussionCategory.py +150 -0
- githubasyncio/RepositoryDiscussionComment.py +159 -0
- githubasyncio/RepositoryKey.py +166 -0
- githubasyncio/RepositoryPreferences.py +82 -0
- githubasyncio/RepositoryRulesetBypassActor.py +75 -0
- githubasyncio/Requester.py +1518 -0
- githubasyncio/RequiredPullRequestReviews.py +269 -0
- githubasyncio/RequiredStatusChecks.py +153 -0
- githubasyncio/Rule.py +134 -0
- githubasyncio/Ruleset.py +292 -0
- githubasyncio/Secret.py +139 -0
- githubasyncio/SecretScanAlert.py +317 -0
- githubasyncio/SecretScanAlertInstance.py +128 -0
- githubasyncio/SecurityAndAnalysis.py +188 -0
- githubasyncio/SecurityAndAnalysisFeature.py +79 -0
- githubasyncio/SelfHostedActionsRunner.py +129 -0
- githubasyncio/SelfHostedActionsRunnerApplication.py +92 -0
- githubasyncio/SelfHostedActionsRunnerJitConfig.py +74 -0
- githubasyncio/SelfHostedActionsRunnerToken.py +118 -0
- githubasyncio/SourceImport.py +260 -0
- githubasyncio/Stargazer.py +88 -0
- githubasyncio/StatsCodeFrequency.py +81 -0
- githubasyncio/StatsCommitActivity.py +86 -0
- githubasyncio/StatsContributor.py +138 -0
- githubasyncio/StatsParticipation.py +78 -0
- githubasyncio/StatsPunchCard.py +76 -0
- githubasyncio/SubIssueSummary.py +70 -0
- githubasyncio/Tag.py +108 -0
- githubasyncio/Team.py +618 -0
- githubasyncio/TeamDiscussion.py +137 -0
- githubasyncio/TimelineEvent.py +164 -0
- githubasyncio/TimelineEventSource.py +81 -0
- githubasyncio/Topic.py +177 -0
- githubasyncio/Traffic.py +95 -0
- githubasyncio/UserKey.py +141 -0
- githubasyncio/Variable.py +155 -0
- githubasyncio/View.py +97 -0
- githubasyncio/Workflow.py +335 -0
- githubasyncio/WorkflowJob.py +253 -0
- githubasyncio/WorkflowRun.py +480 -0
- githubasyncio/WorkflowStep.py +118 -0
- githubasyncio/__init__.py +38 -0
- githubasyncio/compat/__init__.py +52 -0
- githubasyncio/requestlib/__init__.py +29 -0
- pygithub_asyncio-3.0.0b1.dist-info/METADATA +102 -0
- pygithub_asyncio-3.0.0b1.dist-info/RECORD +188 -0
- pygithub_asyncio-3.0.0b1.dist-info/WHEEL +5 -0
- pygithub_asyncio-3.0.0b1.dist-info/licenses/COPYING +674 -0
- pygithub_asyncio-3.0.0b1.dist-info/licenses/COPYING.LESSER +165 -0
- pygithub_asyncio-3.0.0b1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1518 @@
|
|
|
1
|
+
# FILE AUTO GENERATED DO NOT TOUCH
|
|
2
|
+
############################ Copyrights and license ############################
|
|
3
|
+
# #
|
|
4
|
+
# Copyright 2012 Andrew Bettison <andrewb@zip.com.au> #
|
|
5
|
+
# Copyright 2012 Dima Kukushkin <dima@kukushkin.me> #
|
|
6
|
+
# Copyright 2012 Michael Woodworth <mwoodworth@upverter.com> #
|
|
7
|
+
# Copyright 2012 Petteri Muilu <pmuilu@xena.(none)> #
|
|
8
|
+
# Copyright 2012 Steve English <steve.english@navetas.com> #
|
|
9
|
+
# Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> #
|
|
10
|
+
# Copyright 2012 Zearin <zearin@gonk.net> #
|
|
11
|
+
# Copyright 2013 AKFish <akfish@gmail.com> #
|
|
12
|
+
# Copyright 2013 Cameron White <cawhite@pdx.edu> #
|
|
13
|
+
# Copyright 2013 Ed Jackson <ed.jackson@gmail.com> #
|
|
14
|
+
# Copyright 2013 Jonathan J Hunt <hunt@braincorporation.com> #
|
|
15
|
+
# Copyright 2013 Mark Roddy <markroddy@gmail.com> #
|
|
16
|
+
# Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
|
|
17
|
+
# Copyright 2014 Jimmy Zelinskie <jimmyzelinskie@gmail.com> #
|
|
18
|
+
# Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> #
|
|
19
|
+
# Copyright 2015 Brian Eugley <Brian.Eugley@capitalone.com> #
|
|
20
|
+
# Copyright 2015 Daniel Pocock <daniel@pocock.pro> #
|
|
21
|
+
# Copyright 2016 Denis K <f1nal@cgaming.org> #
|
|
22
|
+
# Copyright 2016 Jared K. Smith <jaredsmith@jaredsmith.net> #
|
|
23
|
+
# Copyright 2016 Mathieu Mitchell <mmitchell@iweb.com> #
|
|
24
|
+
# Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> #
|
|
25
|
+
# Copyright 2017 Chris McBride <thehighlander@users.noreply.github.com> #
|
|
26
|
+
# Copyright 2017 Hugo <hugovk@users.noreply.github.com> #
|
|
27
|
+
# Copyright 2017 Simon <spam@esemi.ru> #
|
|
28
|
+
# Copyright 2018 Arda Kuyumcu <kuyumcuarda@gmail.com> #
|
|
29
|
+
# Copyright 2018 Dylan <djstein@ncsu.edu> #
|
|
30
|
+
# Copyright 2018 Maarten Fonville <mfonville@users.noreply.github.com> #
|
|
31
|
+
# Copyright 2018 Mike Miller <github@mikeage.net> #
|
|
32
|
+
# Copyright 2018 R1kk3r <R1kk3r@users.noreply.github.com> #
|
|
33
|
+
# Copyright 2018 Shubham Singh <41840111+singh811@users.noreply.github.com> #
|
|
34
|
+
# Copyright 2018 Steve Kowalik <steven@wedontsleep.org> #
|
|
35
|
+
# Copyright 2018 Tuuu Nya <yuzesheji@qq.com> #
|
|
36
|
+
# Copyright 2018 Wan Liuyang <tsfdye@gmail.com> #
|
|
37
|
+
# Copyright 2018 sfdye <tsfdye@gmail.com> #
|
|
38
|
+
# Copyright 2019 Isac Souza <isouza@daitan.com> #
|
|
39
|
+
# Copyright 2019 Rigas Papathanasopoulos <rigaspapas@gmail.com> #
|
|
40
|
+
# Copyright 2019 Steve Kowalik <steven@wedontsleep.org> #
|
|
41
|
+
# Copyright 2019 Wan Liuyang <tsfdye@gmail.com> #
|
|
42
|
+
# Copyright 2020 Jesse Li <jesse.li2002@gmail.com> #
|
|
43
|
+
# Copyright 2020 Steve Kowalik <steven@wedontsleep.org> #
|
|
44
|
+
# Copyright 2021 Amador Pahim <apahim@redhat.com> #
|
|
45
|
+
# Copyright 2021 Mark Walker <mark.walker@realbuzz.com> #
|
|
46
|
+
# Copyright 2021 Steve Kowalik <steven@wedontsleep.org> #
|
|
47
|
+
# Copyright 2022 Liuyang Wan <tsfdye@gmail.com> #
|
|
48
|
+
# Copyright 2023 Denis Blanchette <dblanchette@coveo.com> #
|
|
49
|
+
# Copyright 2023 Enrico Minack <github@enrico.minack.dev> #
|
|
50
|
+
# Copyright 2023 Heitor Polidoro <heitor.polidoro@gmail.com> #
|
|
51
|
+
# Copyright 2023 Hemslo Wang <hemslo.wang@gmail.com> #
|
|
52
|
+
# Copyright 2023 Jirka Borovec <6035284+Borda@users.noreply.github.com> #
|
|
53
|
+
# Copyright 2023 Phillip Tran <phillip.qtr@gmail.com> #
|
|
54
|
+
# Copyright 2023 Trim21 <trim21.me@gmail.com> #
|
|
55
|
+
# Copyright 2023 adosibalo <94008816+adosibalo@users.noreply.github.com> #
|
|
56
|
+
# Copyright 2024 Enrico Minack <github@enrico.minack.dev> #
|
|
57
|
+
# Copyright 2024 Jirka Borovec <6035284+Borda@users.noreply.github.com> #
|
|
58
|
+
# Copyright 2024 Jonathan Kliem <jonathan.kliem@gmail.com> #
|
|
59
|
+
# Copyright 2024 Kobbi Gal <85439776+kgal-pan@users.noreply.github.com> #
|
|
60
|
+
# Copyright 2024 Min RK <benjaminrk@gmail.com> #
|
|
61
|
+
# Copyright 2025 Alec Ostrander <alec.ostrander@gmail.com> #
|
|
62
|
+
# Copyright 2025 Chris Kuehl <ckuehl@ckuehl.me> #
|
|
63
|
+
# Copyright 2025 Enrico Minack <github@enrico.minack.dev> #
|
|
64
|
+
# Copyright 2025 Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> #
|
|
65
|
+
# Copyright 2025 Jakub Smolar <jakub.smolar@scylladb.com> #
|
|
66
|
+
# Copyright 2025 Neel Malik <41765022+neel-m@users.noreply.github.com> #
|
|
67
|
+
# Copyright 2025 Timothy Klopotoski <tklopotoski@ebsco.com> #
|
|
68
|
+
# Copyright 2026 Enrico Minack <github@enrico.minack.dev> #
|
|
69
|
+
# Copyright 2026 Noethix <ryuga.rago1111@gmail.com> #
|
|
70
|
+
# Copyright 2026 Ville Skyttä <ville.skytta@iki.fi> #
|
|
71
|
+
# #
|
|
72
|
+
# This file is part of PyGithub. #
|
|
73
|
+
# http://pygithub.readthedocs.io/ #
|
|
74
|
+
# #
|
|
75
|
+
# PyGithub is free software: you can redistribute it and/or modify it under #
|
|
76
|
+
# the terms of the GNU Lesser General Public License as published by the Free #
|
|
77
|
+
# Software Foundation, either version 3 of the License, or (at your option) #
|
|
78
|
+
# any later version. #
|
|
79
|
+
# #
|
|
80
|
+
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
|
|
81
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
|
82
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
|
|
83
|
+
# details. #
|
|
84
|
+
# #
|
|
85
|
+
# You should have received a copy of the GNU Lesser General Public License #
|
|
86
|
+
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
|
|
87
|
+
# #
|
|
88
|
+
################################################################################
|
|
89
|
+
|
|
90
|
+
from __future__ import annotations
|
|
91
|
+
|
|
92
|
+
import asyncio
|
|
93
|
+
import io
|
|
94
|
+
import json
|
|
95
|
+
import logging
|
|
96
|
+
import mimetypes
|
|
97
|
+
import os
|
|
98
|
+
import urllib
|
|
99
|
+
import urllib.parse
|
|
100
|
+
from collections import deque
|
|
101
|
+
from collections.abc import Callable, Iterator
|
|
102
|
+
from datetime import datetime, timezone
|
|
103
|
+
from io import IOBase
|
|
104
|
+
from typing import TYPE_CHECKING, Any, BinaryIO, Generic, TypeVar
|
|
105
|
+
|
|
106
|
+
from niquests import AsyncSession as Session
|
|
107
|
+
|
|
108
|
+
import githubasyncio.GithubException
|
|
109
|
+
import githubasyncio.RateLimitOverview
|
|
110
|
+
from githubasyncio import Consts, GithubException
|
|
111
|
+
from githubasyncio.GithubObject import Opt, as_rest_api_attributes, is_undefined, rate_limit_from_headers
|
|
112
|
+
from githubasyncio.requestlib import PreparedRequest, Response, Retry, adapters
|
|
113
|
+
|
|
114
|
+
if TYPE_CHECKING:
|
|
115
|
+
from .AppAuthentication import AppAuthentication
|
|
116
|
+
from .Auth import Auth
|
|
117
|
+
from .GithubObject import GithubObject
|
|
118
|
+
from .InstallationAuthorization import InstallationAuthorization
|
|
119
|
+
from .RateLimitOverview import RateLimitOverview
|
|
120
|
+
|
|
121
|
+
T = TypeVar("T")
|
|
122
|
+
T_gh = TypeVar("T_gh", bound="GithubObject")
|
|
123
|
+
|
|
124
|
+
# For App authentication, time remaining before token expiration to request a new one
|
|
125
|
+
ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS = 20
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class RequestsResponse:
|
|
129
|
+
# mimic the httplib response object
|
|
130
|
+
def __init__(self, r: Response):
|
|
131
|
+
self.status = r.status_code
|
|
132
|
+
self.headers = r.headers
|
|
133
|
+
self.response = r
|
|
134
|
+
|
|
135
|
+
def getheaders(self) -> Iterator[tuple[str, str]]:
|
|
136
|
+
return self.headers.items()
|
|
137
|
+
|
|
138
|
+
def read(self) -> str:
|
|
139
|
+
return self.response.text or ""
|
|
140
|
+
|
|
141
|
+
def iter_content(self, chunk_size: int | None = -1) -> Iterator:
|
|
142
|
+
return self.response.iter_content(chunk_size=chunk_size or -1)
|
|
143
|
+
|
|
144
|
+
def raise_for_status(self) -> None:
|
|
145
|
+
self.response.raise_for_status()
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class HTTPSRequestsConnectionClass:
|
|
149
|
+
retry: int | Retry
|
|
150
|
+
|
|
151
|
+
# mimic the httplib connection object
|
|
152
|
+
def __init__(
|
|
153
|
+
self,
|
|
154
|
+
host: str,
|
|
155
|
+
port: int | None = None,
|
|
156
|
+
strict: bool = False,
|
|
157
|
+
timeout: int | None = None,
|
|
158
|
+
retry: int | Retry | None = None,
|
|
159
|
+
pool_size: int | None = None,
|
|
160
|
+
**kwargs: Any,
|
|
161
|
+
) -> None:
|
|
162
|
+
self.port = port if port else 443
|
|
163
|
+
self.host = host
|
|
164
|
+
self.protocol = "https"
|
|
165
|
+
self.timeout = timeout
|
|
166
|
+
self.verify = kwargs.get("verify", True)
|
|
167
|
+
|
|
168
|
+
if retry is None:
|
|
169
|
+
self.retry = adapters.DEFAULT_RETRIES
|
|
170
|
+
else:
|
|
171
|
+
self.retry = retry
|
|
172
|
+
|
|
173
|
+
if pool_size is None:
|
|
174
|
+
self.pool_size = adapters.DEFAULT_POOLSIZE
|
|
175
|
+
else:
|
|
176
|
+
self.pool_size = pool_size
|
|
177
|
+
|
|
178
|
+
# breaking change (with niquest only):
|
|
179
|
+
# self.session = Session(
|
|
180
|
+
# retries=self.retry, pool_connections=self.pool_size, pool_maxsize=self.pool_size
|
|
181
|
+
# )
|
|
182
|
+
self.adapter = adapters.AsyncHTTPAdapter(
|
|
183
|
+
max_retries=self.retry,
|
|
184
|
+
pool_connections=self.pool_size,
|
|
185
|
+
pool_maxsize=self.pool_size,
|
|
186
|
+
)
|
|
187
|
+
self.session = Session()
|
|
188
|
+
self.session.mount("https://", self.adapter)
|
|
189
|
+
# having Session.auth set something other than None disables falling back to .netrc file
|
|
190
|
+
# https://github.com/psf/requests/blob/d63e94f552ebf77ccf45d97e5863ac46500fa2c7/src/requests/sessions.py#L480-L481
|
|
191
|
+
# see https://github.com/PyGithub/PyGithub/pull/2703
|
|
192
|
+
self.session.auth = Requester.noopAuth
|
|
193
|
+
|
|
194
|
+
def request(
|
|
195
|
+
self,
|
|
196
|
+
verb: str,
|
|
197
|
+
url: str,
|
|
198
|
+
input: str | io.BufferedReader | None,
|
|
199
|
+
headers: dict[str, str],
|
|
200
|
+
stream: bool = False,
|
|
201
|
+
) -> None:
|
|
202
|
+
self.verb = verb
|
|
203
|
+
self.url = url
|
|
204
|
+
self.input = input
|
|
205
|
+
self.headers = headers
|
|
206
|
+
self.stream = stream
|
|
207
|
+
|
|
208
|
+
async def getresponse(self) -> RequestsResponse:
|
|
209
|
+
verb = getattr(self.session, self.verb.lower())
|
|
210
|
+
url = f"{self.protocol}://{self.host}:{self.port}{self.url}"
|
|
211
|
+
r = await verb(
|
|
212
|
+
url,
|
|
213
|
+
headers=self.headers,
|
|
214
|
+
data=self.input,
|
|
215
|
+
timeout=self.timeout,
|
|
216
|
+
verify=self.verify,
|
|
217
|
+
allow_redirects=False,
|
|
218
|
+
)
|
|
219
|
+
return RequestsResponse(r)
|
|
220
|
+
|
|
221
|
+
async def close(self) -> None:
|
|
222
|
+
await self.session.close()
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
class HTTPRequestsConnectionClass:
|
|
226
|
+
# mimic the httplib connection object
|
|
227
|
+
def __init__(
|
|
228
|
+
self,
|
|
229
|
+
host: str,
|
|
230
|
+
port: int | None = None,
|
|
231
|
+
strict: bool = False,
|
|
232
|
+
timeout: int | None = None,
|
|
233
|
+
retry: int | Retry | None = None,
|
|
234
|
+
pool_size: int | None = None,
|
|
235
|
+
**kwargs: Any,
|
|
236
|
+
):
|
|
237
|
+
self.port = port if port else 80
|
|
238
|
+
self.host = host
|
|
239
|
+
self.protocol = "http"
|
|
240
|
+
self.timeout = timeout
|
|
241
|
+
self.verify = kwargs.get("verify", True)
|
|
242
|
+
|
|
243
|
+
if retry is None:
|
|
244
|
+
self.retry = adapters.DEFAULT_RETRIES
|
|
245
|
+
else:
|
|
246
|
+
self.retry = retry # type: ignore
|
|
247
|
+
|
|
248
|
+
if pool_size is None:
|
|
249
|
+
self.pool_size = adapters.DEFAULT_POOLSIZE
|
|
250
|
+
else:
|
|
251
|
+
self.pool_size = pool_size
|
|
252
|
+
|
|
253
|
+
# breaking change (with niquest only):
|
|
254
|
+
# self.session = Session(
|
|
255
|
+
# retries=self.retry, pool_connections=self.pool_size, pool_maxsize=self.pool_size
|
|
256
|
+
# )
|
|
257
|
+
self.adapter = adapters.AsyncHTTPAdapter(
|
|
258
|
+
max_retries=self.retry,
|
|
259
|
+
pool_connections=self.pool_size,
|
|
260
|
+
pool_maxsize=self.pool_size,
|
|
261
|
+
)
|
|
262
|
+
self.session = Session()
|
|
263
|
+
self.session.mount("http://", self.adapter)
|
|
264
|
+
# having Session.auth set something other than None disables falling back to .netrc file
|
|
265
|
+
# https://github.com/psf/requests/blob/d63e94f552ebf77ccf45d97e5863ac46500fa2c7/src/requests/sessions.py#L480-L481
|
|
266
|
+
# see https://github.com/PyGithub/PyGithub/pull/2703
|
|
267
|
+
self.session.auth = Requester.noopAuth
|
|
268
|
+
|
|
269
|
+
def request(self, verb: str, url: str, input: None, headers: dict[str, str], stream: bool = False) -> None:
|
|
270
|
+
self.verb = verb
|
|
271
|
+
self.url = url
|
|
272
|
+
self.input = input
|
|
273
|
+
self.headers = headers
|
|
274
|
+
self.stream = stream
|
|
275
|
+
|
|
276
|
+
async def getresponse(self) -> RequestsResponse:
|
|
277
|
+
verb = getattr(self.session, self.verb.lower())
|
|
278
|
+
url = f"{self.protocol}://{self.host}:{self.port}{self.url}"
|
|
279
|
+
r = await verb(
|
|
280
|
+
url,
|
|
281
|
+
headers=self.headers,
|
|
282
|
+
data=self.input,
|
|
283
|
+
timeout=self.timeout,
|
|
284
|
+
verify=self.verify,
|
|
285
|
+
allow_redirects=False,
|
|
286
|
+
)
|
|
287
|
+
return RequestsResponse(r)
|
|
288
|
+
|
|
289
|
+
async def close(self) -> None:
|
|
290
|
+
await self.session.close()
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
class Requester:
|
|
294
|
+
__installation_authorization: InstallationAuthorization | None
|
|
295
|
+
__app_auth: AppAuthentication | None
|
|
296
|
+
|
|
297
|
+
__httpConnectionClass = HTTPRequestsConnectionClass
|
|
298
|
+
__httpsConnectionClass = HTTPSRequestsConnectionClass
|
|
299
|
+
__persist = True
|
|
300
|
+
__logger: logging.Logger | None = None
|
|
301
|
+
|
|
302
|
+
_frameBuffer: list[Any]
|
|
303
|
+
|
|
304
|
+
@staticmethod
|
|
305
|
+
def noopAuth(request: PreparedRequest) -> PreparedRequest:
|
|
306
|
+
return request
|
|
307
|
+
|
|
308
|
+
@classmethod
|
|
309
|
+
def injectConnectionClasses(
|
|
310
|
+
cls,
|
|
311
|
+
httpConnectionClass: type[HTTPRequestsConnectionClass],
|
|
312
|
+
httpsConnectionClass: type[HTTPSRequestsConnectionClass],
|
|
313
|
+
) -> None:
|
|
314
|
+
cls.__persist = False
|
|
315
|
+
cls.__httpConnectionClass = httpConnectionClass
|
|
316
|
+
cls.__httpsConnectionClass = httpsConnectionClass
|
|
317
|
+
|
|
318
|
+
@classmethod
|
|
319
|
+
def resetConnectionClasses(cls) -> None:
|
|
320
|
+
cls.__persist = True
|
|
321
|
+
cls.__httpConnectionClass = HTTPRequestsConnectionClass
|
|
322
|
+
cls.__httpsConnectionClass = HTTPSRequestsConnectionClass
|
|
323
|
+
|
|
324
|
+
@classmethod
|
|
325
|
+
def injectLogger(cls, logger: logging.Logger) -> None:
|
|
326
|
+
cls.__logger = logger
|
|
327
|
+
|
|
328
|
+
@classmethod
|
|
329
|
+
def resetLogger(cls) -> None:
|
|
330
|
+
cls.__logger = None
|
|
331
|
+
|
|
332
|
+
#############################################################
|
|
333
|
+
# For Debug
|
|
334
|
+
@classmethod
|
|
335
|
+
def setDebugFlag(cls, flag: bool) -> None:
|
|
336
|
+
cls.DEBUG_FLAG = flag
|
|
337
|
+
|
|
338
|
+
@classmethod
|
|
339
|
+
def setOnCheckMe(cls, onCheckMe: Callable) -> None:
|
|
340
|
+
cls.ON_CHECK_ME = onCheckMe
|
|
341
|
+
|
|
342
|
+
DEBUG_FLAG = False
|
|
343
|
+
|
|
344
|
+
DEBUG_FRAME_BUFFER_SIZE = 1024
|
|
345
|
+
|
|
346
|
+
DEBUG_HEADER_KEY = "DEBUG_FRAME"
|
|
347
|
+
|
|
348
|
+
ON_CHECK_ME: Callable | None = None
|
|
349
|
+
|
|
350
|
+
def NEW_DEBUG_FRAME(self, requestHeader: dict[str, str]) -> None:
|
|
351
|
+
"""
|
|
352
|
+
Initialize a debug frame with requestHeader
|
|
353
|
+
Frame count is updated and will be attached to respond header
|
|
354
|
+
The structure of a frame: [requestHeader, statusCode, responseHeader, raw_data]
|
|
355
|
+
Some of them may be None
|
|
356
|
+
"""
|
|
357
|
+
if self.DEBUG_FLAG: # pragma no branch (Flag always set in tests)
|
|
358
|
+
new_frame = [requestHeader, None, None, None]
|
|
359
|
+
if self._frameCount < self.DEBUG_FRAME_BUFFER_SIZE - 1: # pragma no branch (Should be covered)
|
|
360
|
+
self._frameBuffer.append(new_frame)
|
|
361
|
+
else:
|
|
362
|
+
self._frameBuffer[0] = new_frame # pragma no cover (Should be covered)
|
|
363
|
+
|
|
364
|
+
self._frameCount = len(self._frameBuffer) - 1
|
|
365
|
+
|
|
366
|
+
def DEBUG_ON_RESPONSE(self, statusCode: int, responseHeader: dict[str, str | int], data: str) -> None:
|
|
367
|
+
"""
|
|
368
|
+
Update current frame with response Current frame index will be attached to responseHeader.
|
|
369
|
+
"""
|
|
370
|
+
if self.DEBUG_FLAG: # pragma no branch (Flag always set in tests)
|
|
371
|
+
self._frameBuffer[self._frameCount][1:4] = [
|
|
372
|
+
statusCode,
|
|
373
|
+
responseHeader,
|
|
374
|
+
data,
|
|
375
|
+
]
|
|
376
|
+
responseHeader[self.DEBUG_HEADER_KEY] = self._frameCount
|
|
377
|
+
|
|
378
|
+
def check_me(self, obj: GithubObject) -> None:
|
|
379
|
+
if self.DEBUG_FLAG and self.ON_CHECK_ME is not None: # pragma no branch (Flag always set in tests)
|
|
380
|
+
frame = None
|
|
381
|
+
if self.DEBUG_HEADER_KEY in obj._headers:
|
|
382
|
+
frame_index = obj._headers[self.DEBUG_HEADER_KEY]
|
|
383
|
+
frame = self._frameBuffer[frame_index] # type: ignore
|
|
384
|
+
self.ON_CHECK_ME(obj, frame)
|
|
385
|
+
|
|
386
|
+
def _initializeDebugFeature(self) -> None:
|
|
387
|
+
self._frameCount = 0
|
|
388
|
+
self._frameBuffer = []
|
|
389
|
+
|
|
390
|
+
#############################################################
|
|
391
|
+
|
|
392
|
+
_frameCount: int
|
|
393
|
+
__connectionClass: type[HTTPRequestsConnectionClass] | type[HTTPSRequestsConnectionClass]
|
|
394
|
+
__hostname: str
|
|
395
|
+
__authorizationHeader: str | None
|
|
396
|
+
__seconds_between_requests: float | None
|
|
397
|
+
__seconds_between_writes: float | None
|
|
398
|
+
|
|
399
|
+
# keep arguments in-sync with github.MainClass and GithubIntegration
|
|
400
|
+
def __init__(
|
|
401
|
+
self,
|
|
402
|
+
auth: Auth | None,
|
|
403
|
+
base_url: str,
|
|
404
|
+
timeout: int,
|
|
405
|
+
user_agent: str,
|
|
406
|
+
per_page: int,
|
|
407
|
+
verify: bool | str,
|
|
408
|
+
retry: int | Retry | None,
|
|
409
|
+
pool_size: int | None,
|
|
410
|
+
seconds_between_requests: float | None = None,
|
|
411
|
+
seconds_between_writes: float | None = None,
|
|
412
|
+
lazy: bool = False,
|
|
413
|
+
api_version: str | None = None,
|
|
414
|
+
):
|
|
415
|
+
self._initializeDebugFeature()
|
|
416
|
+
|
|
417
|
+
self.__auth = auth
|
|
418
|
+
self.__base_url = base_url
|
|
419
|
+
|
|
420
|
+
o = urllib.parse.urlparse(base_url)
|
|
421
|
+
self.__graphql_prefix = self.get_graphql_prefix(o.path)
|
|
422
|
+
self.__graphql_url = urllib.parse.urlunparse(o._replace(path=self.__graphql_prefix))
|
|
423
|
+
self.__hostname = o.hostname # type: ignore
|
|
424
|
+
if base_url == Consts.DEFAULT_BASE_URL:
|
|
425
|
+
self.__domains = ["github.com", "githubusercontent.com"]
|
|
426
|
+
else:
|
|
427
|
+
self.__domains = list({o.hostname, o.hostname.removeprefix("api.")}) # type: ignore
|
|
428
|
+
self.__port = o.port
|
|
429
|
+
self.__prefix = o.path.rstrip("/")
|
|
430
|
+
self.__timeout = timeout
|
|
431
|
+
self.__retry = retry # NOTE: retry can be either int or an urllib3 Retry object
|
|
432
|
+
self.__pool_size = pool_size
|
|
433
|
+
self.__seconds_between_requests = seconds_between_requests
|
|
434
|
+
self.__seconds_between_writes = seconds_between_writes
|
|
435
|
+
self.__last_requests: dict[str, float] = dict()
|
|
436
|
+
self.__scheme = o.scheme
|
|
437
|
+
if o.scheme == "https":
|
|
438
|
+
self.__connectionClass = self.__httpsConnectionClass
|
|
439
|
+
elif o.scheme == "http":
|
|
440
|
+
self.__connectionClass = self.__httpConnectionClass
|
|
441
|
+
else:
|
|
442
|
+
assert False, "Unknown URL scheme"
|
|
443
|
+
self.__connection: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None = None
|
|
444
|
+
self.__connection_lock = asyncio.Lock()
|
|
445
|
+
self.__custom_connections: deque[HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass] = deque()
|
|
446
|
+
self.rate_limiting = (-1, -1)
|
|
447
|
+
self.rate_limiting_resettime = 0
|
|
448
|
+
self.__rate_limit_resources: dict[str, dict[str, int]] = {}
|
|
449
|
+
self.FIX_REPO_GET_GIT_REF = True
|
|
450
|
+
assert isinstance(per_page, int) and per_page > 0, per_page
|
|
451
|
+
self.per_page = per_page
|
|
452
|
+
|
|
453
|
+
self.oauth_scopes = None
|
|
454
|
+
|
|
455
|
+
assert user_agent is not None, (
|
|
456
|
+
"github now requires a user-agent. "
|
|
457
|
+
"See https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required"
|
|
458
|
+
)
|
|
459
|
+
self.__userAgent = user_agent
|
|
460
|
+
self.__verify = verify
|
|
461
|
+
self.__lazy = lazy
|
|
462
|
+
self.__apiVersion = api_version
|
|
463
|
+
|
|
464
|
+
self.__installation_authorization = None
|
|
465
|
+
|
|
466
|
+
# provide auth implementations that require a requester with this requester
|
|
467
|
+
if isinstance(self.__auth, WithRequester):
|
|
468
|
+
self.__auth.withRequester(self)
|
|
469
|
+
|
|
470
|
+
def __getstate__(self) -> dict[str, Any]:
|
|
471
|
+
state = self.__dict__.copy()
|
|
472
|
+
# __connection_lock is not picklable
|
|
473
|
+
del state["_Requester__connection_lock"]
|
|
474
|
+
# __connection is not usable on remote, so ignore it
|
|
475
|
+
del state["_Requester__connection"]
|
|
476
|
+
# __custom_connections is not usable on remote, so ignore it
|
|
477
|
+
del state["_Requester__custom_connections"]
|
|
478
|
+
return state
|
|
479
|
+
|
|
480
|
+
def __setstate__(self, state: dict[str, Any]) -> None:
|
|
481
|
+
self.__dict__.update(state)
|
|
482
|
+
self.__connection_lock = asyncio.Lock()
|
|
483
|
+
self.__connection = None
|
|
484
|
+
self.__custom_connections = deque()
|
|
485
|
+
|
|
486
|
+
@staticmethod
|
|
487
|
+
# replace with str.removesuffix once support for Python 3.8 is dropped
|
|
488
|
+
def remove_suffix(string: str, suffix: str) -> str:
|
|
489
|
+
if string.endswith(suffix):
|
|
490
|
+
return string[: -len(suffix)]
|
|
491
|
+
return string
|
|
492
|
+
|
|
493
|
+
@staticmethod
|
|
494
|
+
def get_graphql_prefix(path: str | None) -> str:
|
|
495
|
+
if path is None or path in ["", "/"]:
|
|
496
|
+
path = ""
|
|
497
|
+
path = path.rstrip("/")
|
|
498
|
+
if path.endswith("/v3"):
|
|
499
|
+
path = Requester.remove_suffix(path, "/v3")
|
|
500
|
+
return path + "/graphql"
|
|
501
|
+
|
|
502
|
+
@staticmethod
|
|
503
|
+
def get_parameters_of_url(url: str) -> dict[str, list]:
|
|
504
|
+
query = urllib.parse.urlparse(url)[4]
|
|
505
|
+
return urllib.parse.parse_qs(query)
|
|
506
|
+
|
|
507
|
+
@staticmethod
|
|
508
|
+
def add_parameters_to_url(
|
|
509
|
+
url: str,
|
|
510
|
+
parameters: dict[str, Any],
|
|
511
|
+
) -> str:
|
|
512
|
+
scheme, netloc, url, params, query, fragment = urllib.parse.urlparse(url)
|
|
513
|
+
url_params = urllib.parse.parse_qs(query)
|
|
514
|
+
# union parameters in url with given parameters, the latter has precedence
|
|
515
|
+
url_params.update(**{k: v if isinstance(v, list) else [v] for k, v in parameters.items()})
|
|
516
|
+
# GitHub expects lowercase booleans (true/false) in the query string
|
|
517
|
+
parameter_list = [
|
|
518
|
+
(key, str(value).lower() if isinstance(value, bool) else value)
|
|
519
|
+
for key, values in url_params.items()
|
|
520
|
+
for value in values
|
|
521
|
+
]
|
|
522
|
+
# remove query from url
|
|
523
|
+
url = urllib.parse.urlunparse((scheme, netloc, url, params, "", fragment))
|
|
524
|
+
|
|
525
|
+
if len(parameter_list) == 0:
|
|
526
|
+
return url
|
|
527
|
+
else:
|
|
528
|
+
# we need deterministic URLs for stable test assertions
|
|
529
|
+
return f"{url}?{urllib.parse.urlencode(sorted(parameter_list))}"
|
|
530
|
+
|
|
531
|
+
async def close(self) -> None:
|
|
532
|
+
"""
|
|
533
|
+
Close the connection to the server.
|
|
534
|
+
"""
|
|
535
|
+
async with self.__connection_lock:
|
|
536
|
+
if self.__connection is not None:
|
|
537
|
+
await self.__connection.close()
|
|
538
|
+
self.__connection = None
|
|
539
|
+
while self.__custom_connections:
|
|
540
|
+
await self.__custom_connections.popleft().close()
|
|
541
|
+
|
|
542
|
+
@property
|
|
543
|
+
def current_rate_limits(self) -> RateLimitOverview:
|
|
544
|
+
"""
|
|
545
|
+
Latest rate limits known to this requester, per resource.
|
|
546
|
+
|
|
547
|
+
Values come from the response headers of requests made through this requester and any requester sharing them
|
|
548
|
+
(see :meth:`useCurrentRateLimits`), e.g. derived via :meth:`withLazy` and :meth:`withApiVersion`, and from
|
|
549
|
+
calls to :meth:`get_rate_limits`, which provide values for all resources. This does not send any request, use
|
|
550
|
+
:meth:`githubasyncio.RateLimitOverview.RateLimitOverview.update` to fetch current values.
|
|
551
|
+
|
|
552
|
+
Attributes of ``resources`` are ``None`` until values for that resource are known or if the resource is unknown
|
|
553
|
+
to :class:`githubasyncio.RateLimit.RateLimit`, ``rate`` holds the values of the ``core`` resource.
|
|
554
|
+
|
|
555
|
+
"""
|
|
556
|
+
resources = {resource: dict(rate) for resource, rate in list(self.__rate_limit_resources.items())}
|
|
557
|
+
attributes: dict[str, Any] = {"resources": resources}
|
|
558
|
+
if "core" in resources:
|
|
559
|
+
attributes["rate"] = resources["core"]
|
|
560
|
+
return githubasyncio.RateLimitOverview.RateLimitOverview(self, {}, attributes)
|
|
561
|
+
|
|
562
|
+
async def get_rate_limits(self) -> RateLimitOverview:
|
|
563
|
+
"""
|
|
564
|
+
Fetch all rate limits.
|
|
565
|
+
|
|
566
|
+
This updates the respective values provided by :attr:`current_rate_limits`.
|
|
567
|
+
|
|
568
|
+
"""
|
|
569
|
+
headers, data = await self.requestJsonAndCheck("GET", "/rate_limit")
|
|
570
|
+
for resource, rate in data.get("resources", {}).items():
|
|
571
|
+
self.__rate_limit_resources[resource] = dict(rate)
|
|
572
|
+
return githubasyncio.RateLimitOverview.RateLimitOverview(self, headers, data)
|
|
573
|
+
|
|
574
|
+
@property
|
|
575
|
+
def kwargs(self) -> dict[str, Any]:
|
|
576
|
+
"""
|
|
577
|
+
Returns arguments required to recreate this Requester with Requester.__init__, as well as with
|
|
578
|
+
MainClass.__init__ and GithubIntegration.__init__.
|
|
579
|
+
"""
|
|
580
|
+
return dict(
|
|
581
|
+
auth=self.__auth,
|
|
582
|
+
base_url=self.__base_url,
|
|
583
|
+
timeout=self.__timeout,
|
|
584
|
+
user_agent=self.__userAgent,
|
|
585
|
+
per_page=self.per_page,
|
|
586
|
+
verify=self.__verify,
|
|
587
|
+
retry=self.__retry,
|
|
588
|
+
pool_size=self.__pool_size,
|
|
589
|
+
seconds_between_requests=self.__seconds_between_requests,
|
|
590
|
+
seconds_between_writes=self.__seconds_between_writes,
|
|
591
|
+
lazy=self.__lazy,
|
|
592
|
+
api_version=self.__apiVersion,
|
|
593
|
+
)
|
|
594
|
+
|
|
595
|
+
@property
|
|
596
|
+
def base_url(self) -> str:
|
|
597
|
+
return self.__base_url
|
|
598
|
+
|
|
599
|
+
@property
|
|
600
|
+
def graphql_url(self) -> str:
|
|
601
|
+
return self.__graphql_url
|
|
602
|
+
|
|
603
|
+
@property
|
|
604
|
+
def scheme(self) -> str:
|
|
605
|
+
return self.__scheme
|
|
606
|
+
|
|
607
|
+
@property
|
|
608
|
+
def hostname(self) -> str:
|
|
609
|
+
return self.__hostname
|
|
610
|
+
|
|
611
|
+
@property
|
|
612
|
+
def hostname_and_port(self) -> str:
|
|
613
|
+
if self.__port is None:
|
|
614
|
+
return self.hostname
|
|
615
|
+
return f"{self.hostname}:{self.__port}"
|
|
616
|
+
|
|
617
|
+
@property
|
|
618
|
+
def auth(self) -> Auth | None:
|
|
619
|
+
return self.__auth
|
|
620
|
+
|
|
621
|
+
def withAuth(self, auth: Auth | None) -> Requester:
|
|
622
|
+
"""
|
|
623
|
+
Create a new requester instance with identical configuration but the given authentication method.
|
|
624
|
+
|
|
625
|
+
:param auth: authentication method
|
|
626
|
+
:return: new Requester instance
|
|
627
|
+
|
|
628
|
+
"""
|
|
629
|
+
return self.__withArguments(auth=auth)
|
|
630
|
+
|
|
631
|
+
@property
|
|
632
|
+
def is_lazy(self) -> bool:
|
|
633
|
+
return self.__lazy
|
|
634
|
+
|
|
635
|
+
@property
|
|
636
|
+
def is_not_lazy(self) -> bool:
|
|
637
|
+
return not self.__lazy
|
|
638
|
+
|
|
639
|
+
def withLazy(self, lazy: Opt[bool]) -> Requester:
|
|
640
|
+
"""
|
|
641
|
+
Create a new requester instance with identical configuration but the given lazy setting.
|
|
642
|
+
|
|
643
|
+
:param lazy: if True, completable objects created from this instance are lazy, as well as completable objects
|
|
644
|
+
created from those, and so on.
|
|
645
|
+
:return: new Requester instance if is_defined(lazy) and lazy != self.is_lazy, this instance otherwise
|
|
646
|
+
|
|
647
|
+
"""
|
|
648
|
+
if is_undefined(lazy) or self.is_lazy == lazy:
|
|
649
|
+
return self
|
|
650
|
+
|
|
651
|
+
return self.__withArguments(lazy=lazy)
|
|
652
|
+
|
|
653
|
+
@property
|
|
654
|
+
def api_version(self) -> str | None:
|
|
655
|
+
return self.__apiVersion
|
|
656
|
+
|
|
657
|
+
def withApiVersion(self, api_version: str | None) -> Requester:
|
|
658
|
+
"""
|
|
659
|
+
Create a new requester instance with identical configuration but the given API version setting.
|
|
660
|
+
|
|
661
|
+
:param api_version: string, GitHub API version to use (see https://docs.github.com/en/rest/about-the-rest-
|
|
662
|
+
api/api-versions). Note that some PyGithub methods might downgrade this version if it is not supported by
|
|
663
|
+
the implementation. Set to None to not specify any version
|
|
664
|
+
:return: new Requester instance if is_defined(lazy) and lazy != self.is_lazy, this instance otherwise
|
|
665
|
+
|
|
666
|
+
"""
|
|
667
|
+
if api_version == self.api_version:
|
|
668
|
+
return self
|
|
669
|
+
|
|
670
|
+
return self.__withArguments(api_version=api_version)
|
|
671
|
+
|
|
672
|
+
def __withArguments(self, **kwargs: Any) -> Requester:
|
|
673
|
+
requester = Requester(**{**self.kwargs, **kwargs})
|
|
674
|
+
# rate limits are bound to the authentication and the server, none of the other arguments affect them
|
|
675
|
+
if not kwargs.keys() & {"auth", "base_url"}:
|
|
676
|
+
requester.useCurrentRateLimits(self)
|
|
677
|
+
return requester
|
|
678
|
+
|
|
679
|
+
def useCurrentRateLimits(self, requester: Requester) -> None:
|
|
680
|
+
"""
|
|
681
|
+
Make this requester share :attr:`current_rate_limits` with the given requester, dropping its own known values.
|
|
682
|
+
|
|
683
|
+
Rate limits are bound to the authentication and the server, so only use this with a requester of the same
|
|
684
|
+
authentication and base url.
|
|
685
|
+
|
|
686
|
+
:param requester: requester to share rate limits with
|
|
687
|
+
|
|
688
|
+
"""
|
|
689
|
+
self.__rate_limit_resources = requester.__rate_limit_resources
|
|
690
|
+
|
|
691
|
+
async def requestJsonAndCheck(
|
|
692
|
+
self,
|
|
693
|
+
verb: str,
|
|
694
|
+
url: str,
|
|
695
|
+
parameters: dict[str, Any] | None = None,
|
|
696
|
+
headers: dict[str, str] | None = None,
|
|
697
|
+
input: Any | None = None,
|
|
698
|
+
follow_302_redirect: bool = False,
|
|
699
|
+
) -> tuple[dict[str, Any], Any]:
|
|
700
|
+
"""
|
|
701
|
+
Send a request with JSON body.
|
|
702
|
+
|
|
703
|
+
:param input: request body, serialized to JSON if specified
|
|
704
|
+
|
|
705
|
+
:return: ``(headers: dict, JSON Response: Any)``
|
|
706
|
+
:raises: :class:`GithubException` for error status codes
|
|
707
|
+
|
|
708
|
+
"""
|
|
709
|
+
return await self.__postProcess(
|
|
710
|
+
verb,
|
|
711
|
+
url,
|
|
712
|
+
*await self.__check(
|
|
713
|
+
*await self.requestJson(
|
|
714
|
+
verb,
|
|
715
|
+
url,
|
|
716
|
+
parameters,
|
|
717
|
+
headers,
|
|
718
|
+
input,
|
|
719
|
+
self.__customConnection(url),
|
|
720
|
+
follow_302_redirect=follow_302_redirect,
|
|
721
|
+
)
|
|
722
|
+
),
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
async def requestMultipartAndCheck(
|
|
726
|
+
self,
|
|
727
|
+
verb: str,
|
|
728
|
+
url: str,
|
|
729
|
+
parameters: dict[str, Any] | None = None,
|
|
730
|
+
headers: dict[str, Any] | None = None,
|
|
731
|
+
input: dict[str, str] | None = None,
|
|
732
|
+
) -> tuple[dict[str, Any], dict[str, Any] | None]:
|
|
733
|
+
"""
|
|
734
|
+
Send a request with multi-part-encoded body.
|
|
735
|
+
|
|
736
|
+
:param input: request body, will be multi-part encoded if specified
|
|
737
|
+
|
|
738
|
+
:return: ``(headers: dict, JSON Response: Any)``
|
|
739
|
+
:raises: :class:`GithubException` for error status codes
|
|
740
|
+
|
|
741
|
+
"""
|
|
742
|
+
return await self.__postProcess(
|
|
743
|
+
verb,
|
|
744
|
+
url,
|
|
745
|
+
*await self.__check(
|
|
746
|
+
*await self.requestMultipart(verb, url, parameters, headers, input, self.__customConnection(url))
|
|
747
|
+
),
|
|
748
|
+
)
|
|
749
|
+
|
|
750
|
+
async def requestBlobAndCheck(
|
|
751
|
+
self,
|
|
752
|
+
verb: str,
|
|
753
|
+
url: str,
|
|
754
|
+
parameters: dict[str, str] | None = None,
|
|
755
|
+
headers: dict[str, str] | None = None,
|
|
756
|
+
input: str | None = None,
|
|
757
|
+
cnx: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None = None,
|
|
758
|
+
) -> tuple[dict[str, Any], dict[str, Any]]:
|
|
759
|
+
"""
|
|
760
|
+
Send a request with a file for the body.
|
|
761
|
+
|
|
762
|
+
:param input: path to a file to use for the request body
|
|
763
|
+
|
|
764
|
+
:return: ``(headers: dict, JSON Response: Any)``
|
|
765
|
+
:raises: :class:`GithubException` for error status codes
|
|
766
|
+
|
|
767
|
+
"""
|
|
768
|
+
return await self.__postProcess(
|
|
769
|
+
verb,
|
|
770
|
+
url,
|
|
771
|
+
*await self.__check(
|
|
772
|
+
*await self.requestBlob(verb, url, parameters, headers, input, self.__customConnection(url))
|
|
773
|
+
),
|
|
774
|
+
)
|
|
775
|
+
|
|
776
|
+
@classmethod
|
|
777
|
+
def paths_of_dict(cls, d: dict) -> dict:
|
|
778
|
+
return {key: cls.paths_of_dict(val) if isinstance(val, dict) else None for key, val in d.items()}
|
|
779
|
+
|
|
780
|
+
def data_as_class(
|
|
781
|
+
self, headers: dict[str, Any], data: dict[str, Any], data_path: list[str], klass: type[T_gh]
|
|
782
|
+
) -> T_gh:
|
|
783
|
+
for item in data_path:
|
|
784
|
+
if item not in data:
|
|
785
|
+
raise RuntimeError(f"GraphQL path {data_path} not found in data: {self.paths_of_dict(data)}")
|
|
786
|
+
data = data[item]
|
|
787
|
+
if klass.is_rest():
|
|
788
|
+
data = as_rest_api_attributes(data)
|
|
789
|
+
return klass(self, headers, data)
|
|
790
|
+
|
|
791
|
+
async def graphql_query(self, query: str, variables: dict[str, Any]) -> tuple[dict[str, Any], dict[str, Any]]:
|
|
792
|
+
"""
|
|
793
|
+
Queries the GraphQL API.
|
|
794
|
+
|
|
795
|
+
:param query: GraphQL query
|
|
796
|
+
:param variables: GraphQL variables
|
|
797
|
+
:return: ``(headers: dict, JSON Response: dict)``
|
|
798
|
+
:raises: :class:`GithubException` for error status codes
|
|
799
|
+
|
|
800
|
+
"""
|
|
801
|
+
input_ = {"query": query, "variables": variables}
|
|
802
|
+
|
|
803
|
+
response_headers, data = await self.requestJsonAndCheck("POST", self.graphql_url, input=input_)
|
|
804
|
+
if "errors" in data:
|
|
805
|
+
if len(data["errors"]) == 1:
|
|
806
|
+
error = data["errors"][0]
|
|
807
|
+
if error.get("type") == "NOT_FOUND":
|
|
808
|
+
raise githubasyncio.GithubException.UnknownObjectException(
|
|
809
|
+
404, data, response_headers, error.get("message")
|
|
810
|
+
)
|
|
811
|
+
raise self.createException(400, response_headers, data)
|
|
812
|
+
return response_headers, data
|
|
813
|
+
|
|
814
|
+
async def graphql_query_class(
|
|
815
|
+
self, query: str, variables: dict[str, Any], data_path: list[str], klass: type[T_gh]
|
|
816
|
+
) -> T_gh:
|
|
817
|
+
"""
|
|
818
|
+
Queries the GraphQL API, extracts data from a given path, populates and returns a PyGithub class instance.
|
|
819
|
+
|
|
820
|
+
Uses :func:`graphql_query` to query the GraphQL API.
|
|
821
|
+
|
|
822
|
+
:param query: GraphQL query
|
|
823
|
+
:param data_path: GraphQL path in the response to extract the properties for the class to return
|
|
824
|
+
:param klass: PyGithub class
|
|
825
|
+
:return: PyGithub class instance
|
|
826
|
+
:raises: :class:`GithubException` for error status codes
|
|
827
|
+
|
|
828
|
+
"""
|
|
829
|
+
headers, data = await self.graphql_query(query, variables)
|
|
830
|
+
return self.data_as_class(headers, data, ["data"] + data_path, klass)
|
|
831
|
+
|
|
832
|
+
async def graphql_node(
|
|
833
|
+
self, node_id: str, output_schema: str, node_type: str
|
|
834
|
+
) -> tuple[dict[str, Any], dict[str, Any]]:
|
|
835
|
+
"""
|
|
836
|
+
Fetches a GraphQL node by id in the give schema.
|
|
837
|
+
|
|
838
|
+
This sends the following GraphQL request::
|
|
839
|
+
|
|
840
|
+
query Q($id. ID!) {
|
|
841
|
+
node(id: $id) {
|
|
842
|
+
__typename
|
|
843
|
+
... on <node_type> {
|
|
844
|
+
<output_schema>
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
:param node_id: GraphQL node id
|
|
850
|
+
:param output_schema: The schema of the retrieved properties of the node, without enclosing curly brackets
|
|
851
|
+
:param node_type: The GraphQL node type
|
|
852
|
+
:return: ``(headers: dict, JSON Response: dict)``
|
|
853
|
+
:raises: :class:`GithubException` for error status codes
|
|
854
|
+
|
|
855
|
+
"""
|
|
856
|
+
if not output_schema.startswith("\n"):
|
|
857
|
+
output_schema = f" {output_schema} "
|
|
858
|
+
query = (
|
|
859
|
+
"""
|
|
860
|
+
query Q($id: ID!) {
|
|
861
|
+
node(id: $id) {
|
|
862
|
+
__typename
|
|
863
|
+
... on """
|
|
864
|
+
+ f"{node_type} {{{output_schema}}}"
|
|
865
|
+
+ """
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
"""
|
|
869
|
+
)
|
|
870
|
+
|
|
871
|
+
headers, data = await self.graphql_query(query, {"id": node_id})
|
|
872
|
+
actual_node_type = data.get("data", {}).get("node", {}).get("__typename", node_type)
|
|
873
|
+
if actual_node_type != node_type:
|
|
874
|
+
raise githubasyncio.GithubException.GithubException(
|
|
875
|
+
400,
|
|
876
|
+
data,
|
|
877
|
+
message=f"Retrieved {node_type} object is of different type: {actual_node_type}",
|
|
878
|
+
)
|
|
879
|
+
return headers, data
|
|
880
|
+
|
|
881
|
+
async def graphql_node_class(
|
|
882
|
+
self, node_id: str, output_schema: str, klass: type[T_gh], node_type: str | None = None
|
|
883
|
+
) -> T_gh:
|
|
884
|
+
"""
|
|
885
|
+
Fetches a GraphQL node by id in the give schema, and returns a PyGithub instance of the given class populated
|
|
886
|
+
with the retrieved properties.
|
|
887
|
+
|
|
888
|
+
Uses :func:`graph_node` to retrieve the GraphQl node.
|
|
889
|
+
|
|
890
|
+
:param node_id: GraphQL node id
|
|
891
|
+
:param output_schema: The schema of the retrieved properties of the node, without enclosing curly brackets
|
|
892
|
+
:param klass: PyGithub class
|
|
893
|
+
:param node_type: Optional GraphQL node type, defaults to the name of the PyGithub class
|
|
894
|
+
:return: PyGithub class instance
|
|
895
|
+
:raises: :class:`GithubException` for error status codes
|
|
896
|
+
|
|
897
|
+
"""
|
|
898
|
+
if node_type is None:
|
|
899
|
+
node_type = klass.__name__
|
|
900
|
+
|
|
901
|
+
headers, data = await self.graphql_node(node_id, output_schema, node_type)
|
|
902
|
+
return self.data_as_class(headers, data, ["data", "node"], klass)
|
|
903
|
+
|
|
904
|
+
async def graphql_named_mutation(
|
|
905
|
+
self, mutation_name: str, mutation_input: dict[str, Any], output_schema: str
|
|
906
|
+
) -> tuple[dict[str, Any], dict[str, Any]]:
|
|
907
|
+
"""
|
|
908
|
+
Send a GraphQL mutation to the GraphQL API.
|
|
909
|
+
|
|
910
|
+
This sends the following GraphQL request::
|
|
911
|
+
|
|
912
|
+
mutation Mutation($input: MutationNameInput!) {
|
|
913
|
+
mutationName(input: $input) {
|
|
914
|
+
<output_schema>
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
Uses :func:`graphql_query` to send the request to the GraphQL API.
|
|
919
|
+
|
|
920
|
+
:param mutation_name: name of the mutation
|
|
921
|
+
:param mutation_input: input data for the mutation
|
|
922
|
+
:param output_schema: The schema of the retrieved properties of the mutation, without enclosing curly brackets
|
|
923
|
+
:return: ``(headers: dict, JSON Response: dict)``
|
|
924
|
+
:raises: :class:`GithubException` for error status codes
|
|
925
|
+
|
|
926
|
+
"""
|
|
927
|
+
mutation_input_name = mutation_name[:1].upper() + mutation_name[1:] + "Input!"
|
|
928
|
+
query = f"mutation Mutation($input: {mutation_input_name}) {{ {mutation_name}(input: $input) {{ {output_schema} }} }}"
|
|
929
|
+
headers, data = await self.graphql_query(query, {"input": mutation_input})
|
|
930
|
+
return headers, data.get("data", {}).get(mutation_name, {})
|
|
931
|
+
|
|
932
|
+
async def graphql_named_mutation_class(
|
|
933
|
+
self, mutation_name: str, mutation_input: dict[str, Any], output_schema: str, item: str, klass: type[T_gh]
|
|
934
|
+
) -> T_gh:
|
|
935
|
+
"""
|
|
936
|
+
Send a GraphQL mutation to the GraphQL API, populates and returns a PyGithub class instance.
|
|
937
|
+
|
|
938
|
+
Uses :func:`graphql_named_mutation` to send the mutation to the GraphQL API.
|
|
939
|
+
|
|
940
|
+
:param mutation_name: name of the mutation
|
|
941
|
+
:param mutation_input: input data for the mutation
|
|
942
|
+
:param output_schema: The schema of the retrieved properties of the mutation, without enclosing curly brackets
|
|
943
|
+
:param item: property in the response to extract the properties for the class to return
|
|
944
|
+
:return: PyGithub class instance
|
|
945
|
+
:raises: :class:`GithubException` for error status codes
|
|
946
|
+
|
|
947
|
+
"""
|
|
948
|
+
headers, data = await self.graphql_named_mutation(mutation_name, mutation_input, output_schema)
|
|
949
|
+
return self.data_as_class(headers, data, [item], klass)
|
|
950
|
+
|
|
951
|
+
async def __check(
|
|
952
|
+
self,
|
|
953
|
+
status: int,
|
|
954
|
+
responseHeaders: dict[str, Any],
|
|
955
|
+
output: str,
|
|
956
|
+
) -> tuple[dict[str, Any], Any]:
|
|
957
|
+
data = self.__structuredFromJson(output)
|
|
958
|
+
if status >= 400:
|
|
959
|
+
raise self.createException(status, responseHeaders, data)
|
|
960
|
+
return responseHeaders, data
|
|
961
|
+
|
|
962
|
+
async def __postProcess(
|
|
963
|
+
self, verb: str, url: str, responseHeaders: dict[str, Any], data: Any
|
|
964
|
+
) -> tuple[dict[str, Any], Any]:
|
|
965
|
+
# make GET url available as "url" attribute
|
|
966
|
+
if verb == "GET" and isinstance(data, dict) and "url" not in data:
|
|
967
|
+
data["url"] = url
|
|
968
|
+
return responseHeaders, data
|
|
969
|
+
|
|
970
|
+
@classmethod
|
|
971
|
+
def __hostnameHasDomain(cls, hostname: str, domain_or_domains: str | list[str]) -> bool:
|
|
972
|
+
if isinstance(domain_or_domains, str):
|
|
973
|
+
if hostname == domain_or_domains:
|
|
974
|
+
return True
|
|
975
|
+
domain_suffix = f".{domain_or_domains}"
|
|
976
|
+
return hostname.endswith(domain_suffix)
|
|
977
|
+
return any(cls.__hostnameHasDomain(hostname, d) for d in domain_or_domains)
|
|
978
|
+
|
|
979
|
+
def __assertUrlAllowed(self, url: str) -> None:
|
|
980
|
+
o = urllib.parse.urlparse(url)
|
|
981
|
+
assert o.hostname is not None
|
|
982
|
+
if o.hostname == self.__hostname:
|
|
983
|
+
prefixes = [self.__prefix, self.__graphql_prefix, "/api/", "/login/oauth"]
|
|
984
|
+
assert o.path.startswith(tuple(prefixes)), o.path
|
|
985
|
+
assert o.port == self.__port, o.port
|
|
986
|
+
else:
|
|
987
|
+
assert self.__hostnameHasDomain(o.hostname, self.__domains), o.hostname
|
|
988
|
+
|
|
989
|
+
def __customConnection(self, url: str) -> HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None:
|
|
990
|
+
cnx: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None = None
|
|
991
|
+
if not url.startswith("/"):
|
|
992
|
+
# check URL is allowed
|
|
993
|
+
self.__assertUrlAllowed(url)
|
|
994
|
+
|
|
995
|
+
# only return connection if url deviates from base_url
|
|
996
|
+
o = urllib.parse.urlparse(url)
|
|
997
|
+
if (
|
|
998
|
+
o.hostname != self.__hostname
|
|
999
|
+
or (o.port and o.port != self.__port)
|
|
1000
|
+
or (o.scheme != self.__scheme and not (o.scheme == "https" and self.__scheme == "http"))
|
|
1001
|
+
): # issue80
|
|
1002
|
+
if o.scheme == "http":
|
|
1003
|
+
cnx = self.__httpConnectionClass(
|
|
1004
|
+
o.hostname, # type: ignore
|
|
1005
|
+
o.port,
|
|
1006
|
+
retry=self.__retry,
|
|
1007
|
+
pool_size=self.__pool_size,
|
|
1008
|
+
)
|
|
1009
|
+
self.__custom_connections.append(cnx)
|
|
1010
|
+
elif o.scheme == "https":
|
|
1011
|
+
cnx = self.__httpsConnectionClass(
|
|
1012
|
+
o.hostname, # type: ignore
|
|
1013
|
+
o.port,
|
|
1014
|
+
retry=self.__retry,
|
|
1015
|
+
pool_size=self.__pool_size,
|
|
1016
|
+
)
|
|
1017
|
+
self.__custom_connections.append(cnx)
|
|
1018
|
+
return cnx
|
|
1019
|
+
|
|
1020
|
+
@classmethod
|
|
1021
|
+
def createException(
|
|
1022
|
+
cls,
|
|
1023
|
+
status: int,
|
|
1024
|
+
headers: dict[str, Any],
|
|
1025
|
+
output: dict[str, Any],
|
|
1026
|
+
) -> GithubException.GithubException:
|
|
1027
|
+
message = output.get("message") if output else None
|
|
1028
|
+
lc_message = message.lower() if message else ""
|
|
1029
|
+
|
|
1030
|
+
msg = None
|
|
1031
|
+
exc = GithubException.GithubException
|
|
1032
|
+
if status == 401 and lc_message == "bad credentials":
|
|
1033
|
+
exc = GithubException.BadCredentialsException
|
|
1034
|
+
elif status == 401 and Consts.headerOTP in headers and "required" in headers[Consts.headerOTP]:
|
|
1035
|
+
exc = GithubException.TwoFactorException
|
|
1036
|
+
elif status == 403 and lc_message.startswith("missing or invalid user agent string"):
|
|
1037
|
+
exc = GithubException.BadUserAgentException
|
|
1038
|
+
elif status == 403 and cls.isRateLimitError(lc_message):
|
|
1039
|
+
exc = GithubException.RateLimitExceededException
|
|
1040
|
+
elif status == 404 and ("not found" in lc_message or "no object found" in lc_message):
|
|
1041
|
+
exc = GithubException.UnknownObjectException
|
|
1042
|
+
if lc_message != "not found":
|
|
1043
|
+
msg = message
|
|
1044
|
+
else:
|
|
1045
|
+
# for general GithubException, provide the actual message
|
|
1046
|
+
msg = message
|
|
1047
|
+
|
|
1048
|
+
return exc(status, output, headers, msg)
|
|
1049
|
+
|
|
1050
|
+
@classmethod
|
|
1051
|
+
def isRateLimitError(cls, message: str) -> bool:
|
|
1052
|
+
return cls.isPrimaryRateLimitError(message) or cls.isSecondaryRateLimitError(message)
|
|
1053
|
+
|
|
1054
|
+
@classmethod
|
|
1055
|
+
def isPrimaryRateLimitError(cls, message: str) -> bool:
|
|
1056
|
+
if not message:
|
|
1057
|
+
return False
|
|
1058
|
+
|
|
1059
|
+
message = message.lower()
|
|
1060
|
+
return message.startswith("api rate limit exceeded")
|
|
1061
|
+
|
|
1062
|
+
@classmethod
|
|
1063
|
+
def isSecondaryRateLimitError(cls, message: str) -> bool:
|
|
1064
|
+
if not message:
|
|
1065
|
+
return False
|
|
1066
|
+
|
|
1067
|
+
message = message.lower()
|
|
1068
|
+
return (
|
|
1069
|
+
message.startswith("you have exceeded a secondary rate limit")
|
|
1070
|
+
or message.endswith("please retry your request again later.")
|
|
1071
|
+
or message.endswith("please wait a few minutes before you try again.")
|
|
1072
|
+
)
|
|
1073
|
+
|
|
1074
|
+
def __structuredFromJson(self, data: str) -> Any:
|
|
1075
|
+
if len(data) == 0:
|
|
1076
|
+
return None
|
|
1077
|
+
else:
|
|
1078
|
+
if isinstance(data, bytes):
|
|
1079
|
+
data = data.decode("utf-8")
|
|
1080
|
+
try:
|
|
1081
|
+
return json.loads(data)
|
|
1082
|
+
except ValueError:
|
|
1083
|
+
if data.startswith("{") or data.startswith("["):
|
|
1084
|
+
raise
|
|
1085
|
+
return {"data": data}
|
|
1086
|
+
|
|
1087
|
+
async def getFile(
|
|
1088
|
+
self,
|
|
1089
|
+
url: str,
|
|
1090
|
+
path: str,
|
|
1091
|
+
parameters: dict[str, Any] | None = None,
|
|
1092
|
+
headers: dict[str, str] | None = None,
|
|
1093
|
+
cnx: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None = None,
|
|
1094
|
+
chunk_size: int | None | None = 1,
|
|
1095
|
+
) -> None:
|
|
1096
|
+
"""
|
|
1097
|
+
GET a file from the server and save it to the given path, which includes the filename.
|
|
1098
|
+
"""
|
|
1099
|
+
_, _, stream_chunk_iterator = await self.getStream(url, parameters, headers, cnx, chunk_size=chunk_size)
|
|
1100
|
+
with open(path, "wb") as f:
|
|
1101
|
+
for chunk in stream_chunk_iterator:
|
|
1102
|
+
if chunk:
|
|
1103
|
+
f.write(chunk)
|
|
1104
|
+
|
|
1105
|
+
async def getStream(
|
|
1106
|
+
self,
|
|
1107
|
+
url: str,
|
|
1108
|
+
parameters: dict[str, Any] | None = None,
|
|
1109
|
+
headers: dict[str, str] | None = None,
|
|
1110
|
+
cnx: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None = None,
|
|
1111
|
+
chunk_size: int | None | None = 1,
|
|
1112
|
+
) -> tuple[int, dict[str, Any], Iterator]:
|
|
1113
|
+
"""
|
|
1114
|
+
GET a stream from the server.
|
|
1115
|
+
|
|
1116
|
+
:returns:``(status, headers, stream_chunk_iterator)``
|
|
1117
|
+
|
|
1118
|
+
"""
|
|
1119
|
+
if headers is None:
|
|
1120
|
+
headers = {}
|
|
1121
|
+
headers["Accept"] = "application/octet-stream"
|
|
1122
|
+
|
|
1123
|
+
def encode(_: Any) -> tuple[str, str]:
|
|
1124
|
+
return "", ""
|
|
1125
|
+
|
|
1126
|
+
status, responseHeaders, output = await self.__requestEncode(
|
|
1127
|
+
cnx, "GET", url, parameters, headers, None, encode, stream=True, follow_302_redirect=True
|
|
1128
|
+
)
|
|
1129
|
+
if isinstance(output, RequestsResponse) or (
|
|
1130
|
+
hasattr(output, "iter_content") and hasattr(output, "raise_for_status")
|
|
1131
|
+
):
|
|
1132
|
+
output.raise_for_status()
|
|
1133
|
+
return status, responseHeaders, output.iter_content(chunk_size=chunk_size)
|
|
1134
|
+
raise TypeError(f"Expected a RequestsResponse object: {type(output)}")
|
|
1135
|
+
|
|
1136
|
+
async def requestJson(
|
|
1137
|
+
self,
|
|
1138
|
+
verb: str,
|
|
1139
|
+
url: str,
|
|
1140
|
+
parameters: dict[str, Any] | None = None,
|
|
1141
|
+
headers: dict[str, Any] | None = None,
|
|
1142
|
+
input: Any | None = None,
|
|
1143
|
+
cnx: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None = None,
|
|
1144
|
+
follow_302_redirect: bool = False,
|
|
1145
|
+
) -> tuple[int, dict[str, Any], str]:
|
|
1146
|
+
"""
|
|
1147
|
+
Send a request with JSON input.
|
|
1148
|
+
|
|
1149
|
+
:param input: request body, will be serialized as JSON
|
|
1150
|
+
:returns:``(status, headers, body)``
|
|
1151
|
+
|
|
1152
|
+
"""
|
|
1153
|
+
|
|
1154
|
+
def encode(input: Any) -> tuple[str, str]:
|
|
1155
|
+
return "application/json", json.dumps(input)
|
|
1156
|
+
|
|
1157
|
+
status, responseHeaders, output = await self.__requestEncode(
|
|
1158
|
+
cnx, verb, url, parameters, headers, input, encode, follow_302_redirect=follow_302_redirect
|
|
1159
|
+
)
|
|
1160
|
+
if isinstance(output, str):
|
|
1161
|
+
return status, responseHeaders, output
|
|
1162
|
+
raise ValueError("requestJson() Expected a str, should never happen")
|
|
1163
|
+
|
|
1164
|
+
async def requestMultipart(
|
|
1165
|
+
self,
|
|
1166
|
+
verb: str,
|
|
1167
|
+
url: str,
|
|
1168
|
+
parameters: dict[str, Any] | None = None,
|
|
1169
|
+
headers: dict[str, Any] | None = None,
|
|
1170
|
+
input: dict[str, str] | None = None,
|
|
1171
|
+
cnx: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None = None,
|
|
1172
|
+
) -> tuple[int, dict[str, Any], str]:
|
|
1173
|
+
"""
|
|
1174
|
+
Send a request with multi-part encoding.
|
|
1175
|
+
|
|
1176
|
+
:param input: request body, will be serialized as multipart form data
|
|
1177
|
+
:returns:``(status, headers, body)``
|
|
1178
|
+
|
|
1179
|
+
"""
|
|
1180
|
+
|
|
1181
|
+
def encode(input: dict[str, Any]) -> tuple[str, str]:
|
|
1182
|
+
boundary = "----------------------------3c3ba8b523b2"
|
|
1183
|
+
eol = "\r\n"
|
|
1184
|
+
|
|
1185
|
+
encoded_input = ""
|
|
1186
|
+
for name, value in input.items():
|
|
1187
|
+
encoded_input += f"--{boundary}{eol}"
|
|
1188
|
+
encoded_input += f'Content-Disposition: form-data; name="{name}"{eol}'
|
|
1189
|
+
encoded_input += eol
|
|
1190
|
+
encoded_input += value + eol
|
|
1191
|
+
encoded_input += f"--{boundary}--{eol}"
|
|
1192
|
+
return f"multipart/form-data; boundary={boundary}", encoded_input
|
|
1193
|
+
|
|
1194
|
+
status, responseHeaders, output = await self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
|
|
1195
|
+
if isinstance(output, str):
|
|
1196
|
+
return status, responseHeaders, output
|
|
1197
|
+
raise ValueError("requestMultipart() Expected a str, should never happen")
|
|
1198
|
+
|
|
1199
|
+
async def requestBlob(
|
|
1200
|
+
self,
|
|
1201
|
+
verb: str,
|
|
1202
|
+
url: str,
|
|
1203
|
+
parameters: dict[str, str] | None = None,
|
|
1204
|
+
headers: dict[str, str] | None = None,
|
|
1205
|
+
input: str | None = None,
|
|
1206
|
+
cnx: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None = None,
|
|
1207
|
+
) -> tuple[int, dict[str, Any], str]:
|
|
1208
|
+
"""
|
|
1209
|
+
Send a request with a file as request body.
|
|
1210
|
+
|
|
1211
|
+
:param input: path to a local file to use for request body
|
|
1212
|
+
:returns:``(status, headers, body)``
|
|
1213
|
+
|
|
1214
|
+
"""
|
|
1215
|
+
if headers is None:
|
|
1216
|
+
headers = {}
|
|
1217
|
+
|
|
1218
|
+
def encode(local_path: str) -> tuple[str, Any]:
|
|
1219
|
+
if "Content-Type" in headers: # type: ignore
|
|
1220
|
+
mime_type = headers["Content-Type"] # type: ignore
|
|
1221
|
+
else:
|
|
1222
|
+
guessed_type = mimetypes.guess_type(local_path)
|
|
1223
|
+
mime_type = guessed_type[0] if guessed_type[0] is not None else Consts.defaultMediaType
|
|
1224
|
+
f = open(local_path, "rb")
|
|
1225
|
+
return mime_type, f
|
|
1226
|
+
|
|
1227
|
+
if input:
|
|
1228
|
+
headers["Content-Length"] = str(os.path.getsize(input))
|
|
1229
|
+
|
|
1230
|
+
status, responseHeaders, output = await self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
|
|
1231
|
+
if isinstance(output, str):
|
|
1232
|
+
return status, responseHeaders, output
|
|
1233
|
+
raise ValueError("requestBlob() Expected a str, should never happen")
|
|
1234
|
+
|
|
1235
|
+
async def requestMemoryBlobAndCheck(
|
|
1236
|
+
self,
|
|
1237
|
+
verb: str,
|
|
1238
|
+
url: str,
|
|
1239
|
+
parameters: Any,
|
|
1240
|
+
headers: dict[str, Any],
|
|
1241
|
+
file_like: BinaryIO,
|
|
1242
|
+
cnx: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None = None,
|
|
1243
|
+
) -> tuple[dict[str, Any], Any]:
|
|
1244
|
+
"""
|
|
1245
|
+
Send a request with a binary file-like for the body.
|
|
1246
|
+
|
|
1247
|
+
:param file_like: file-like object to use for the request body
|
|
1248
|
+
:return: ``(headers: dict, JSON Response: Any)``
|
|
1249
|
+
:raises: :class:`GithubException` for error status codes
|
|
1250
|
+
|
|
1251
|
+
"""
|
|
1252
|
+
|
|
1253
|
+
# The expected signature of encode means that the argument is ignored.
|
|
1254
|
+
def encode(_: Any) -> tuple[str, Any]:
|
|
1255
|
+
return headers["Content-Type"], file_like
|
|
1256
|
+
|
|
1257
|
+
if not cnx:
|
|
1258
|
+
cnx = self.__customConnection(url)
|
|
1259
|
+
|
|
1260
|
+
status, responseHeaders, output = await self.__requestEncode(
|
|
1261
|
+
cnx, verb, url, parameters, headers, file_like, encode
|
|
1262
|
+
)
|
|
1263
|
+
if isinstance(output, str):
|
|
1264
|
+
return await self.__postProcess(verb, url, *await self.__check(status, responseHeaders, output))
|
|
1265
|
+
raise ValueError("requestMemoryBlobAndCheck() Expected a str, should never happen")
|
|
1266
|
+
|
|
1267
|
+
async def __requestEncode(
|
|
1268
|
+
self,
|
|
1269
|
+
cnx: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None,
|
|
1270
|
+
verb: str,
|
|
1271
|
+
url: str,
|
|
1272
|
+
parameters: dict[str, str] | None,
|
|
1273
|
+
requestHeaders: dict[str, str] | None,
|
|
1274
|
+
input: T | None,
|
|
1275
|
+
encode: Callable[[T], tuple[str, Any]],
|
|
1276
|
+
stream: bool = False,
|
|
1277
|
+
follow_302_redirect: bool = False,
|
|
1278
|
+
) -> tuple[int, dict[str, Any], str | object]:
|
|
1279
|
+
assert verb in ["HEAD", "GET", "POST", "PATCH", "PUT", "DELETE"]
|
|
1280
|
+
if parameters is None:
|
|
1281
|
+
parameters = {}
|
|
1282
|
+
if requestHeaders is None:
|
|
1283
|
+
requestHeaders = {}
|
|
1284
|
+
|
|
1285
|
+
if self.__auth is not None:
|
|
1286
|
+
authenticated = self.__auth.authentication(requestHeaders)
|
|
1287
|
+
if asyncio.iscoroutine(authenticated):
|
|
1288
|
+
await authenticated
|
|
1289
|
+
requestHeaders["User-Agent"] = self.__userAgent
|
|
1290
|
+
if self.__apiVersion is not None:
|
|
1291
|
+
requestHeaders[Consts.headerApiVersion] = self.__apiVersion
|
|
1292
|
+
|
|
1293
|
+
url = self.__makeAbsoluteUrl(url)
|
|
1294
|
+
url = Requester.add_parameters_to_url(url, parameters)
|
|
1295
|
+
|
|
1296
|
+
encoded_input = None
|
|
1297
|
+
if input is not None:
|
|
1298
|
+
requestHeaders["Content-Type"], encoded_input = encode(input)
|
|
1299
|
+
|
|
1300
|
+
self.NEW_DEBUG_FRAME(requestHeaders)
|
|
1301
|
+
|
|
1302
|
+
status, responseHeaders, output = await self.__requestRaw(
|
|
1303
|
+
cnx, verb, url, requestHeaders, encoded_input, stream=stream, follow_302_redirect=follow_302_redirect
|
|
1304
|
+
)
|
|
1305
|
+
|
|
1306
|
+
if Consts.headerRateRemaining in responseHeaders and Consts.headerRateLimit in responseHeaders:
|
|
1307
|
+
self.rate_limiting = (
|
|
1308
|
+
# ints expected but sometimes floats returned: https://github.com/PyGithub/PyGithub/pull/2697
|
|
1309
|
+
int(float(responseHeaders[Consts.headerRateRemaining])),
|
|
1310
|
+
int(float(responseHeaders[Consts.headerRateLimit])),
|
|
1311
|
+
)
|
|
1312
|
+
if Consts.headerRateReset in responseHeaders:
|
|
1313
|
+
# ints expected but sometimes floats returned: https://github.com/PyGithub/PyGithub/pull/2697
|
|
1314
|
+
self.rate_limiting_resettime = int(float(responseHeaders[Consts.headerRateReset]))
|
|
1315
|
+
if Consts.headerRateResource in responseHeaders:
|
|
1316
|
+
self.__rate_limit_resources[responseHeaders[Consts.headerRateResource]] = rate_limit_from_headers(
|
|
1317
|
+
responseHeaders
|
|
1318
|
+
)
|
|
1319
|
+
|
|
1320
|
+
if Consts.headerOAuthScopes in responseHeaders:
|
|
1321
|
+
self.oauth_scopes = responseHeaders[Consts.headerOAuthScopes].split(", ")
|
|
1322
|
+
|
|
1323
|
+
self.DEBUG_ON_RESPONSE(status, responseHeaders, output if isinstance(output, str) else "stream")
|
|
1324
|
+
|
|
1325
|
+
return status, responseHeaders, output
|
|
1326
|
+
|
|
1327
|
+
async def __requestRaw(
|
|
1328
|
+
self,
|
|
1329
|
+
cnx: HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass | None,
|
|
1330
|
+
verb: str,
|
|
1331
|
+
url: str,
|
|
1332
|
+
requestHeaders: dict[str, str],
|
|
1333
|
+
input: Any | None,
|
|
1334
|
+
stream: bool = False,
|
|
1335
|
+
follow_302_redirect: bool = False,
|
|
1336
|
+
) -> tuple[int, dict[str, Any], str | object]:
|
|
1337
|
+
await self.__deferRequest(verb)
|
|
1338
|
+
|
|
1339
|
+
try:
|
|
1340
|
+
original_cnx = cnx
|
|
1341
|
+
if cnx is None:
|
|
1342
|
+
cnx = await self.__createConnection()
|
|
1343
|
+
cnx.request(verb, url, input, requestHeaders, stream)
|
|
1344
|
+
response = await cnx.getresponse()
|
|
1345
|
+
output = response if stream else response.read()
|
|
1346
|
+
status = response.status
|
|
1347
|
+
responseHeaders = {k.lower(): v for k, v in response.getheaders()}
|
|
1348
|
+
|
|
1349
|
+
if input:
|
|
1350
|
+
if isinstance(input, IOBase):
|
|
1351
|
+
input.close()
|
|
1352
|
+
|
|
1353
|
+
self.__log(verb, url, requestHeaders, input, status, responseHeaders, output)
|
|
1354
|
+
|
|
1355
|
+
if status == 202 and (
|
|
1356
|
+
verb == "GET" or verb == "HEAD"
|
|
1357
|
+
): # only for requests that are considered 'safe' in RFC 2616
|
|
1358
|
+
await asyncio.sleep(Consts.PROCESSING_202_WAIT_TIME)
|
|
1359
|
+
return await self.__requestRaw(original_cnx, verb, url, requestHeaders, input, stream=stream)
|
|
1360
|
+
|
|
1361
|
+
if status == 301 and "location" in responseHeaders:
|
|
1362
|
+
location = responseHeaders["location"]
|
|
1363
|
+
o = urllib.parse.urlparse(location)
|
|
1364
|
+
if o.scheme != self.__scheme:
|
|
1365
|
+
raise RuntimeError(
|
|
1366
|
+
f"Github server redirected from {self.__scheme} protocol to {o.scheme}, "
|
|
1367
|
+
f"please correct your Github server URL via base_url: Github(base_url=...)"
|
|
1368
|
+
)
|
|
1369
|
+
if o.hostname != self.__hostname:
|
|
1370
|
+
raise RuntimeError(
|
|
1371
|
+
f"Github server redirected from host {self.__hostname} to {o.hostname}, "
|
|
1372
|
+
f"please correct your Github server URL via base_url: Github(base_url=...)"
|
|
1373
|
+
)
|
|
1374
|
+
if o.path == url:
|
|
1375
|
+
port = ":" + str(self.__port) if self.__port is not None else ""
|
|
1376
|
+
requested_location = f"{self.__scheme}://{self.__hostname}{port}{url}"
|
|
1377
|
+
raise RuntimeError(
|
|
1378
|
+
f"Requested {requested_location} but server redirected to {location}, "
|
|
1379
|
+
f"you may need to correct your Github server URL "
|
|
1380
|
+
f"via base_url: Github(base_url=...)"
|
|
1381
|
+
)
|
|
1382
|
+
if self._logger.isEnabledFor(logging.INFO):
|
|
1383
|
+
self._logger.info(f"Following Github server redirection from {url} to {o.path}")
|
|
1384
|
+
return await self.__requestRaw(original_cnx, verb, o.path, requestHeaders, input, stream=stream)
|
|
1385
|
+
if status == 302 and follow_302_redirect and "location" in responseHeaders:
|
|
1386
|
+
location = responseHeaders["location"]
|
|
1387
|
+
o = urllib.parse.urlparse(location)
|
|
1388
|
+
cnx = self.__customConnection(location)
|
|
1389
|
+
path = self.__makeAbsoluteUrl(location)
|
|
1390
|
+
if self._logger.isEnabledFor(logging.DEBUG):
|
|
1391
|
+
self._logger.debug(f"Following Github server redirection (302) from {url} to {o.path}")
|
|
1392
|
+
# remove auth to not leak authentication to redirection location
|
|
1393
|
+
if o.hostname != self.__hostname:
|
|
1394
|
+
requestHeaders = {k: v for k, v in requestHeaders.items() if k != "Authorization"}
|
|
1395
|
+
return await self.__requestRaw(
|
|
1396
|
+
cnx, verb, path, requestHeaders, input, stream=stream, follow_302_redirect=True
|
|
1397
|
+
)
|
|
1398
|
+
return status or 0, responseHeaders, output
|
|
1399
|
+
finally:
|
|
1400
|
+
# we record the time of this request after it finished
|
|
1401
|
+
# to defer next request starting from this request's end, not start
|
|
1402
|
+
self.__recordRequestTime(verb)
|
|
1403
|
+
|
|
1404
|
+
async def __deferRequest(self, verb: str) -> None:
|
|
1405
|
+
# Ensures at least self.__seconds_between_requests seconds have passed since any last request
|
|
1406
|
+
# and self.__seconds_between_writes seconds have passed since last write request (if verb refers to a write).
|
|
1407
|
+
# Uses self.__last_requests.
|
|
1408
|
+
requests = self.__last_requests.values()
|
|
1409
|
+
writes = [last for method, last in self.__last_requests.items() if method != "GET"]
|
|
1410
|
+
|
|
1411
|
+
last_request = max(requests) if requests else 0
|
|
1412
|
+
last_write = max(writes) if writes else 0
|
|
1413
|
+
|
|
1414
|
+
next_request = (last_request + self.__seconds_between_requests) if self.__seconds_between_requests else 0
|
|
1415
|
+
next_write = (last_write + self.__seconds_between_writes) if self.__seconds_between_writes else 0
|
|
1416
|
+
|
|
1417
|
+
next = next_request if verb == "GET" else max(next_request, next_write)
|
|
1418
|
+
defer = max(next - datetime.now(timezone.utc).timestamp(), 0)
|
|
1419
|
+
if defer > 0:
|
|
1420
|
+
if self.__logger is None:
|
|
1421
|
+
self.__logger = logging.getLogger(__name__)
|
|
1422
|
+
self.__logger.debug(f"sleeping {defer}s before next GitHub request")
|
|
1423
|
+
await asyncio.sleep(defer)
|
|
1424
|
+
|
|
1425
|
+
def __recordRequestTime(self, verb: str) -> None:
|
|
1426
|
+
# Updates self.__last_requests with current timestamp for given verb
|
|
1427
|
+
self.__last_requests[verb] = datetime.now(timezone.utc).timestamp()
|
|
1428
|
+
|
|
1429
|
+
def __makeAbsoluteUrl(self, url: str) -> str:
|
|
1430
|
+
# URLs generated locally will be relative to __base_url
|
|
1431
|
+
# URLs returned from the server will start with __base_url
|
|
1432
|
+
if url.startswith("/"):
|
|
1433
|
+
url = f"{self.__prefix}{url}"
|
|
1434
|
+
else:
|
|
1435
|
+
o = urllib.parse.urlparse(url)
|
|
1436
|
+
url = o.path
|
|
1437
|
+
if o.query != "":
|
|
1438
|
+
url += f"?{o.query}"
|
|
1439
|
+
return url
|
|
1440
|
+
|
|
1441
|
+
async def __createConnection(
|
|
1442
|
+
self, hostname: str | None = None
|
|
1443
|
+
) -> HTTPRequestsConnectionClass | HTTPSRequestsConnectionClass:
|
|
1444
|
+
if hostname is None:
|
|
1445
|
+
hostname = self.__hostname
|
|
1446
|
+
|
|
1447
|
+
if self.__persist and self.__connection is not None and hostname == self.__connection.host:
|
|
1448
|
+
return self.__connection
|
|
1449
|
+
|
|
1450
|
+
async with self.__connection_lock:
|
|
1451
|
+
if self.__persist and self.__connection is not None and hostname == self.__connection.host:
|
|
1452
|
+
return self.__connection
|
|
1453
|
+
if self.__connection is not None:
|
|
1454
|
+
await self.__connection.close()
|
|
1455
|
+
self.__connection = None
|
|
1456
|
+
self.__connection = self.__connectionClass(
|
|
1457
|
+
hostname,
|
|
1458
|
+
self.__port,
|
|
1459
|
+
retry=self.__retry,
|
|
1460
|
+
pool_size=self.__pool_size,
|
|
1461
|
+
timeout=self.__timeout,
|
|
1462
|
+
verify=self.__verify,
|
|
1463
|
+
)
|
|
1464
|
+
|
|
1465
|
+
return self.__connection
|
|
1466
|
+
|
|
1467
|
+
@property
|
|
1468
|
+
def _logger(self) -> logging.Logger:
|
|
1469
|
+
if self.__logger is None:
|
|
1470
|
+
self.__logger = logging.getLogger(__name__)
|
|
1471
|
+
return self.__logger
|
|
1472
|
+
|
|
1473
|
+
def __log(
|
|
1474
|
+
self,
|
|
1475
|
+
verb: str,
|
|
1476
|
+
url: str,
|
|
1477
|
+
requestHeaders: dict[str, str],
|
|
1478
|
+
input: Any | None,
|
|
1479
|
+
status: int | None,
|
|
1480
|
+
responseHeaders: dict[str, Any],
|
|
1481
|
+
output: str | object | None,
|
|
1482
|
+
) -> None:
|
|
1483
|
+
if self._logger.isEnabledFor(logging.DEBUG):
|
|
1484
|
+
headersForRequest = requestHeaders.copy()
|
|
1485
|
+
if self.__auth:
|
|
1486
|
+
self.__auth.mask_authentication(headersForRequest)
|
|
1487
|
+
self._logger.debug(
|
|
1488
|
+
"%s %s://%s%s %s %s ==> %i %s %s",
|
|
1489
|
+
verb,
|
|
1490
|
+
self.__scheme,
|
|
1491
|
+
self.__hostname,
|
|
1492
|
+
url,
|
|
1493
|
+
headersForRequest,
|
|
1494
|
+
input,
|
|
1495
|
+
status,
|
|
1496
|
+
responseHeaders,
|
|
1497
|
+
output if isinstance(output, str) else "stream",
|
|
1498
|
+
)
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
class WithRequester(Generic[T]):
|
|
1502
|
+
"""
|
|
1503
|
+
Mixin class that allows to set a requester.
|
|
1504
|
+
"""
|
|
1505
|
+
|
|
1506
|
+
__requester: Requester
|
|
1507
|
+
|
|
1508
|
+
def __init__(self) -> None:
|
|
1509
|
+
self.__requester: Requester | None = None # type: ignore
|
|
1510
|
+
|
|
1511
|
+
@property
|
|
1512
|
+
def requester(self) -> Requester:
|
|
1513
|
+
return self.__requester
|
|
1514
|
+
|
|
1515
|
+
def withRequester(self, requester: Requester) -> WithRequester[T]:
|
|
1516
|
+
assert isinstance(requester, Requester), requester
|
|
1517
|
+
self.__requester = requester
|
|
1518
|
+
return self
|