Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcb61181

Browse files
reduce repetition in request calls
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parentae93e9d commitcb61181

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

‎src/databricks/sql/backend/utils/http_client.py‎

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
importjson
22
importlogging
33
importrequests
4-
fromtypingimportDict,Any,Optional,Union,List,Tuple
4+
fromtypingimportCallable,Dict,Any,Optional,Union,List,Tuple
55
fromurllib.parseimporturljoin
66

77
fromdatabricks.sql.auth.authenticatorsimportAuthProvider
@@ -87,6 +87,18 @@ def _get_auth_headers(self) -> Dict[str, str]:
8787
self.auth_provider.add_headers(headers)
8888
returnheaders
8989

90+
def_get_call(self,method:str)->Callable:
91+
"""Get the appropriate HTTP method function."""
92+
method=method.upper()
93+
ifmethod=="GET":
94+
returnself.session.get
95+
elifmethod=="POST":
96+
returnself.session.post
97+
elifmethod=="DELETE":
98+
returnself.session.delete
99+
else:
100+
raiseValueError(f"Unsupported HTTP method:{method}")
101+
90102
def_make_request(
91103
self,
92104
method:str,
@@ -116,29 +128,13 @@ def _make_request(
116128
logger.debug(f"making{method} request to{url}")
117129

118130
try:
119-
ifmethod.upper()=="GET":
120-
response=self.session.get(
121-
url=url,
122-
headers=headers,
123-
json=data,
124-
params=params,
125-
)
126-
elifmethod.upper()=="POST":
127-
response=self.session.post(
128-
url=url,
129-
headers=headers,
130-
json=data,
131-
params=params,
132-
)
133-
elifmethod.upper()=="DELETE":
134-
response=self.session.delete(
135-
url=url,
136-
headers=headers,
137-
json=data,
138-
params=params,
139-
)
140-
else:
141-
raiseValueError(f"Unsupported HTTP method:{method}")
131+
call=self._get_call(method)
132+
response=call(
133+
url=url,
134+
headers=headers,
135+
json=data,
136+
params=params,
137+
)
142138

143139
# Check for HTTP errors
144140
response.raise_for_status()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp