| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 52af91c commit 3bbefc1
39 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,7 @@ | |||
| 1 | 1 | """Retain apiclient as an alias for googleapiclient.""" | |
| 2 | 2 | ||
| 3 | 3 | 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 | ||
| 11 | 5 | ||
| 12 | 6 | try: | |
| 13 | 7 | from googleapiclient import sample_tools | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,13 +32,11 @@ | |||
| 32 | 32 | import string | |
| 33 | 33 | import sys | |
| 34 | 34 | ||
| 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 | - | ||
| 40 | 35 | import uritemplate | |
| 41 | 36 | ||
| 37 | + from googleapiclient.discovery import DISCOVERY_URI, build, build_from_document | ||
| 38 | + from googleapiclient.http import build_http | ||
| 39 | + | ||
| 42 | 40 | DISCOVERY_DOC_DIR = ( | |
| 43 | 41 | pathlib.Path(__file__).parent.resolve() | |
| 44 | 42 | / "googleapiclient" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,17 +41,22 @@ | |||
| 41 | 41 | def credentials_from_file(filename, scopes=None, quota_project_id=None): | |
| 42 | 42 | """Returns credentials loaded from a file.""" | |
| 43 | 43 | 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 | + ) | ||
| 45 | 47 | return credentials | |
| 46 | 48 | else: | |
| 47 | 49 | 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 | + ) | ||
| 49 | 52 | ||
| 50 | 53 | ||
| 51 | 54 | def default_credentials(scopes=None, quota_project_id=None): | |
| 52 | 55 | """Returns Application Default Credentials.""" | |
| 53 | 56 | 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 | + ) | ||
| 55 | 60 | return credentials | |
| 56 | 61 | elif HAS_OAUTH2CLIENT: | |
| 57 | 62 | if scopes is not None or quota_project_id is not None: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,6 @@ | |||
| 19 | 19 | import logging | |
| 20 | 20 | import urllib | |
| 21 | 21 | ||
| 22 | - | ||
| 23 | 22 | logger = logging.getLogger(__name__) | |
| 24 | 23 | ||
| 25 | 24 | POSITIONAL_WARNING = "WARNING" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,9 +74,8 @@ | |||
| 74 | 74 | import datetime | |
| 75 | 75 | import uuid | |
| 76 | 76 | ||
| 77 | - from googleapiclient import errors | ||
| 78 | 77 | from googleapiclient import _helpers as util | |
| 79 | - | ||
| 78 | + from googleapiclient import errors | ||
| 80 | 79 | ||
| 81 | 80 | # The unix time epoch starts at midnight 1970. | |
| 82 | 81 | EPOCH = datetime.datetime.utcfromtimestamp(0) | |
@@ -111,28 +110,28 @@ def _upper_header_keys(headers): | |||
| 111 | 110 | class Notification(object): | |
| 112 | 111 | """A Notification from a Channel. | |
| 113 | 112 | ||
| 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(). | ||
| 116 | 115 | ||
| 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 | + """ | ||
| 124 | 123 | ||
| 125 | 124 | @util.positional(5) | |
| 126 | 125 | def __init__(self, message_number, state, resource_uri, resource_id): | |
| 127 | 126 | """Notification constructor. | |
| 128 | 127 | ||
| 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 | + """ | ||
| 136 | 135 | self.message_number = message_number | |
| 137 | 136 | self.state = state | |
| 138 | 137 | self.resource_uri = resource_uri | |
@@ -142,53 +141,17 @@ def __init__(self, message_number, state, resource_uri, resource_id): | |||
| 142 | 141 | class Channel(object): | |
| 143 | 142 | """A Channel for notifications. | |
| 144 | 143 | ||
| 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(). | ||
| 183 | 146 | ||
| 184 | - Args: | ||
| 147 | + Attributes: | ||
| 185 | 148 | type: str, The type of delivery mechanism used by this channel. For | |
| 186 | 149 | example, 'web_hook'. | |
| 187 | 150 | id: str, A UUID for the channel. | |
| 188 | 151 | token: str, An arbitrary string associated with the channel that | |
| 189 | 152 | is delivered to the target address with each event delivered | |
| 190 | 153 | 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 | ||
| 192 | 155 | delivered. Specific to the channel type. | |
| 193 | 156 | expiration: int, The time, in milliseconds from the epoch, when this | |
| 194 | 157 | channel will expire. | |
@@ -198,6 +161,42 @@ def __init__( | |||
| 198 | 161 | being watched. Stable across different API versions. | |
| 199 | 162 | resource_uri: str, The canonicalized ID of the watched resource. | |
| 200 | 163 | """ | |
| 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 | + """ | ||
| 201 | 200 | self.type = type | |
| 202 | 201 | self.id = id | |
| 203 | 202 | self.token = token | |
@@ -210,12 +209,12 @@ def __init__( | |||
| 210 | 209 | def body(self): | |
| 211 | 210 | """Build a body from the Channel. | |
| 212 | 211 | ||
| 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. | ||
| 215 | 214 | ||
| 216 | - Returns: | ||
| 217 | - A dictionary representation of the channel. | ||
| 218 | - """ | ||
| 215 | + Returns: | ||
| 216 | + A dictionary representation of the channel. | ||
| 217 | + """ | ||
| 219 | 218 | result = { | |
| 220 | 219 | "id": self.id, | |
| 221 | 220 | "token": self.token, | |
@@ -236,13 +235,13 @@ def body(self): | |||
| 236 | 235 | def update(self, resp): | |
| 237 | 236 | """Update a channel with information from the response of watch(). | |
| 238 | 237 | ||
| 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. | ||
| 242 | 241 | ||
| 243 | - Args: | ||
| 244 | - resp: dict, The response from a watch() method. | ||
| 245 | - """ | ||
| 242 | + Args: | ||
| 243 | + resp: dict, The response from a watch() method. | ||
| 244 | + """ | ||
| 246 | 245 | for json_name, param_name in CHANNEL_PARAMS.items(): | |
| 247 | 246 | value = resp.get(json_name) | |
| 248 | 247 | if value is not None: | |
@@ -251,20 +250,20 @@ def update(self, resp): | |||
| 251 | 250 | ||
| 252 | 251 | def notification_from_headers(channel, headers): | |
| 253 | 252 | """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. | ||
| 255 | 254 | ||
| 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. | ||
| 260 | 259 | ||
| 261 | - Returns: | ||
| 262 | - A Notification object. | ||
| 260 | + Returns: | ||
| 261 | + A Notification object. | ||
| 263 | 262 | ||
| 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 | + """ | ||
| 268 | 267 | headers = _upper_header_keys(headers) | |
| 269 | 268 | channel_id = headers[X_GOOG_CHANNEL_ID] | |
| 270 | 269 | if channel.id != channel_id: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments