Skip to content

Commit 3bbefc1

Browse files
chore: automatically format code using isort and black (#1782)
* chore: automatically format code using isort and black * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 52af91c commit 3bbefc1

39 files changed

+1211
-1004
lines changed

apiclient/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
"""Retain apiclient as an alias for googleapiclient."""
22

33
import googleapiclient
4-
5-
from googleapiclient import channel
6-
from googleapiclient import discovery
7-
from googleapiclient import errors
8-
from googleapiclient import http
9-
from googleapiclient import mimeparse
10-
from googleapiclient import model
4+
from googleapiclient import channel, discovery, errors, http, mimeparse, model
115

126
try:
137
from googleapiclient import sample_tools

describe.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@
3232
import string
3333
import sys
3434

35-
from googleapiclient.discovery import DISCOVERY_URI
36-
from googleapiclient.discovery import build
37-
from googleapiclient.discovery import build_from_document
38-
from googleapiclient.http import build_http
39-
4035
import uritemplate
4136

37+
from googleapiclient.discovery import DISCOVERY_URI, build, build_from_document
38+
from googleapiclient.http import build_http
39+
4240
DISCOVERY_DOC_DIR = (
4341
pathlib.Path(__file__).parent.resolve()
4442
/ "googleapiclient"

googleapiclient/_auth.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,22 @@
4141
def credentials_from_file(filename, scopes=None, quota_project_id=None):
4242
"""Returns credentials loaded from a file."""
4343
if HAS_GOOGLE_AUTH:
44-
credentials, _ = google.auth.load_credentials_from_file(filename, scopes=scopes, quota_project_id=quota_project_id)
44+
credentials, _ = google.auth.load_credentials_from_file(
45+
filename, scopes=scopes, quota_project_id=quota_project_id
46+
)
4547
return credentials
4648
else:
4749
raise EnvironmentError(
48-
"client_options.credentials_file is only supported in google-auth.")
50+
"client_options.credentials_file is only supported in google-auth."
51+
)
4952

5053

5154
def default_credentials(scopes=None, quota_project_id=None):
5255
"""Returns Application Default Credentials."""
5356
if HAS_GOOGLE_AUTH:
54-
credentials, _ = google.auth.default(scopes=scopes, quota_project_id=quota_project_id)
57+
credentials, _ = google.auth.default(
58+
scopes=scopes, quota_project_id=quota_project_id
59+
)
5560
return credentials
5661
elif HAS_OAUTH2CLIENT:
5762
if scopes is not None or quota_project_id is not None:

googleapiclient/_helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import logging
2020
import urllib
2121

22-
2322
logger = logging.getLogger(__name__)
2423

2524
POSITIONAL_WARNING = "WARNING"

googleapiclient/channel.py

Lines changed: 79 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@
7474
import datetime
7575
import uuid
7676

77-
from googleapiclient import errors
7877
from googleapiclient import _helpers as util
79-
78+
from googleapiclient import errors
8079

8180
# The unix time epoch starts at midnight 1970.
8281
EPOCH = datetime.datetime.utcfromtimestamp(0)
@@ -111,28 +110,28 @@ def _upper_header_keys(headers):
111110
class Notification(object):
112111
"""A Notification from a Channel.
113112
114-
Notifications are not usually constructed directly, but are returned
115-
from functions like notification_from_headers().
113+
Notifications are not usually constructed directly, but are returned
114+
from functions like notification_from_headers().
116115
117-
Attributes:
118-
message_number: int, The unique id number of this notification.
119-
state: str, The state of the resource being monitored.
120-
uri: str, The address of the resource being monitored.
121-
resource_id: str, The unique identifier of the version of the resource at
122-
this event.
123-
"""
116+
Attributes:
117+
message_number: int, The unique id number of this notification.
118+
state: str, The state of the resource being monitored.
119+
uri: str, The address of the resource being monitored.
120+
resource_id: str, The unique identifier of the version of the resource at
121+
this event.
122+
"""
124123

125124
@util.positional(5)
126125
def __init__(self, message_number, state, resource_uri, resource_id):
127126
"""Notification constructor.
128127
129-
Args:
130-
message_number: int, The unique id number of this notification.
131-
state: str, The state of the resource being monitored. Can be one
132-
of "exists", "not_exists", or "sync".
133-
resource_uri: str, The address of the resource being monitored.
134-
resource_id: str, The identifier of the watched resource.
135-
"""
128+
Args:
129+
message_number: int, The unique id number of this notification.
130+
state: str, The state of the resource being monitored. Can be one
131+
of "exists", "not_exists", or "sync".
132+
resource_uri: str, The address of the resource being monitored.
133+
resource_id: str, The identifier of the watched resource.
134+
"""
136135
self.message_number = message_number
137136
self.state = state
138137
self.resource_uri = resource_uri
@@ -142,53 +141,17 @@ def __init__(self, message_number, state, resource_uri, resource_id):
142141
class Channel(object):
143142
"""A Channel for notifications.
144143
145-
Usually not constructed directly, instead it is returned from helper
146-
functions like new_webhook_channel().
147-
148-
Attributes:
149-
type: str, The type of delivery mechanism used by this channel. For
150-
example, 'web_hook'.
151-
id: str, A UUID for the channel.
152-
token: str, An arbitrary string associated with the channel that
153-
is delivered to the target address with each event delivered
154-
over this channel.
155-
address: str, The address of the receiving entity where events are
156-
delivered. Specific to the channel type.
157-
expiration: int, The time, in milliseconds from the epoch, when this
158-
channel will expire.
159-
params: dict, A dictionary of string to string, with additional parameters
160-
controlling delivery channel behavior.
161-
resource_id: str, An opaque id that identifies the resource that is
162-
being watched. Stable across different API versions.
163-
resource_uri: str, The canonicalized ID of the watched resource.
164-
"""
165-
166-
@util.positional(5)
167-
def __init__(
168-
self,
169-
type,
170-
id,
171-
token,
172-
address,
173-
expiration=None,
174-
params=None,
175-
resource_id="",
176-
resource_uri="",
177-
):
178-
"""Create a new Channel.
179-
180-
In user code, this Channel constructor will not typically be called
181-
manually since there are functions for creating channels for each specific
182-
type with a more customized set of arguments to pass.
144+
Usually not constructed directly, instead it is returned from helper
145+
functions like new_webhook_channel().
183146
184-
Args:
147+
Attributes:
185148
type: str, The type of delivery mechanism used by this channel. For
186149
example, 'web_hook'.
187150
id: str, A UUID for the channel.
188151
token: str, An arbitrary string associated with the channel that
189152
is delivered to the target address with each event delivered
190153
over this channel.
191-
address: str, The address of the receiving entity where events are
154+
address: str, The address of the receiving entity where events are
192155
delivered. Specific to the channel type.
193156
expiration: int, The time, in milliseconds from the epoch, when this
194157
channel will expire.
@@ -198,6 +161,42 @@ def __init__(
198161
being watched. Stable across different API versions.
199162
resource_uri: str, The canonicalized ID of the watched resource.
200163
"""
164+
165+
@util.positional(5)
166+
def __init__(
167+
self,
168+
type,
169+
id,
170+
token,
171+
address,
172+
expiration=None,
173+
params=None,
174+
resource_id="",
175+
resource_uri="",
176+
):
177+
"""Create a new Channel.
178+
179+
In user code, this Channel constructor will not typically be called
180+
manually since there are functions for creating channels for each specific
181+
type with a more customized set of arguments to pass.
182+
183+
Args:
184+
type: str, The type of delivery mechanism used by this channel. For
185+
example, 'web_hook'.
186+
id: str, A UUID for the channel.
187+
token: str, An arbitrary string associated with the channel that
188+
is delivered to the target address with each event delivered
189+
over this channel.
190+
address: str, The address of the receiving entity where events are
191+
delivered. Specific to the channel type.
192+
expiration: int, The time, in milliseconds from the epoch, when this
193+
channel will expire.
194+
params: dict, A dictionary of string to string, with additional parameters
195+
controlling delivery channel behavior.
196+
resource_id: str, An opaque id that identifies the resource that is
197+
being watched. Stable across different API versions.
198+
resource_uri: str, The canonicalized ID of the watched resource.
199+
"""
201200
self.type = type
202201
self.id = id
203202
self.token = token
@@ -210,12 +209,12 @@ def __init__(
210209
def body(self):
211210
"""Build a body from the Channel.
212211
213-
Constructs a dictionary that's appropriate for passing into watch()
214-
methods as the value of body argument.
212+
Constructs a dictionary that's appropriate for passing into watch()
213+
methods as the value of body argument.
215214
216-
Returns:
217-
A dictionary representation of the channel.
218-
"""
215+
Returns:
216+
A dictionary representation of the channel.
217+
"""
219218
result = {
220219
"id": self.id,
221220
"token": self.token,
@@ -236,13 +235,13 @@ def body(self):
236235
def update(self, resp):
237236
"""Update a channel with information from the response of watch().
238237
239-
When a request is sent to watch() a resource, the response returned
240-
from the watch() request is a dictionary with updated channel information,
241-
such as the resource_id, which is needed when stopping a subscription.
238+
When a request is sent to watch() a resource, the response returned
239+
from the watch() request is a dictionary with updated channel information,
240+
such as the resource_id, which is needed when stopping a subscription.
242241
243-
Args:
244-
resp: dict, The response from a watch() method.
245-
"""
242+
Args:
243+
resp: dict, The response from a watch() method.
244+
"""
246245
for json_name, param_name in CHANNEL_PARAMS.items():
247246
value = resp.get(json_name)
248247
if value is not None:
@@ -251,20 +250,20 @@ def update(self, resp):
251250

252251
def notification_from_headers(channel, headers):
253252
"""Parse a notification from the webhook request headers, validate
254-
the notification, and return a Notification object.
253+
the notification, and return a Notification object.
255254
256-
Args:
257-
channel: Channel, The channel that the notification is associated with.
258-
headers: dict, A dictionary like object that contains the request headers
259-
from the webhook HTTP request.
255+
Args:
256+
channel: Channel, The channel that the notification is associated with.
257+
headers: dict, A dictionary like object that contains the request headers
258+
from the webhook HTTP request.
260259
261-
Returns:
262-
A Notification object.
260+
Returns:
261+
A Notification object.
263262
264-
Raises:
265-
errors.InvalidNotificationError if the notification is invalid.
266-
ValueError if the X-GOOG-MESSAGE-NUMBER can't be converted to an int.
267-
"""
263+
Raises:
264+
errors.InvalidNotificationError if the notification is invalid.
265+
ValueError if the X-GOOG-MESSAGE-NUMBER can't be converted to an int.
266+
"""
268267
headers = _upper_header_keys(headers)
269268
channel_id = headers[X_GOOG_CHANNEL_ID]
270269
if channel.id != channel_id:

0 commit comments

Comments
 (0)