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

Commit48b422d

Browse files
authored
Add client options. (#8265)
1 parent957d580 commit48b422d

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Client options class.
16+
17+
Client options provide a consistent interface for user options to be defined
18+
across clients.
19+
"""
20+
21+
22+
classClientOptions(object):
23+
"""Client Options used to set options on clients.
24+
25+
Args:
26+
api_endpoint (str): The desired API endpoint, e.g., compute.googleapis.com
27+
"""
28+
29+
def__init__(self,api_endpoint=None):
30+
self.api_endpoint=api_endpoint
31+
32+
33+
deffrom_dict(options):
34+
"""Construct a client options object from a dictionary.
35+
36+
Args:
37+
options (dict): A dictionary with client options.
38+
"""
39+
40+
client_options=ClientOptions()
41+
42+
forkey,valueinoptions.items():
43+
ifhasattr(client_options,key):
44+
setattr(client_options,key,value)
45+
else:
46+
raiseValueError("ClientOptions does not accept an option '"+key+"'")
47+
48+
returnclient_options
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
importpytest
16+
17+
fromgoogle.api_coreimportclient_options
18+
19+
20+
deftest_constructor():
21+
options=client_options.ClientOptions(api_endpoint="foo.googleapis.com")
22+
23+
assertoptions.api_endpoint=="foo.googleapis.com"
24+
25+
26+
deftest_from_dict():
27+
options=client_options.from_dict({"api_endpoint":"foo.googleapis.com"})
28+
29+
assertoptions.api_endpoint=="foo.googleapis.com"
30+
31+
32+
deftest_from_dict_bad_argument():
33+
withpytest.raises(ValueError):
34+
client_options.from_dict(
35+
{"api_endpoint":"foo.googleapis.com","bad_arg":"1234"}
36+
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp