7474import datetime
7575import uuid
7676
77- from googleapiclient import errors
7877from googleapiclient import _helpers as util
79-
78+ from googleapiclient import errors
8079
8180# The unix time epoch starts at midnight 1970.
8281EPOCH = datetime .datetime .utcfromtimestamp (0 )
@@ -111,28 +110,28 @@ def _upper_header_keys(headers):
111110class 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):
142141class 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
252251def 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