18
18
from google .cloud .gapic .pubsub .v1 .subscriber_api import SubscriberApi
19
19
from google .gax import CallOptions
20
20
from google .gax import INITIAL_PAGE
21
- from google .gax .errors import GaxError
22
21
from google .pubsub .v1 .pubsub_pb2 import PubsubMessage
23
22
from google .pubsub .v1 .pubsub_pb2 import PushConfig
24
- from grpc . beta . implementations import insecure_channel
23
+ from grpc import insecure_channel
25
24
from grpc import StatusCode
26
25
27
26
# pylint: disable=ungrouped-imports
28
27
from google .cloud ._helpers import _to_bytes
29
- from google .cloud ._helpers import exc_to_code
30
28
from google .cloud ._helpers import _pb_timestamp_to_rfc3339
31
29
from google .cloud .exceptions import Conflict
30
+ from google .cloud .exceptions import GrpcRendezvous
32
31
from google .cloud .exceptions import NotFound
33
32
# pylint: enable=ungrouped-imports
34
33
@@ -93,8 +92,8 @@ def topic_create(self, topic_path):
93
92
"""
94
93
try :
95
94
topic_pb = self ._gax_api .create_topic (topic_path )
96
- except GaxError as exc :
97
- if exc_to_code ( exc .cause ) == StatusCode .FAILED_PRECONDITION :
95
+ except GrpcRendezvous as exc :
96
+ if exc .code ( ) == StatusCode .FAILED_PRECONDITION :
98
97
raise Conflict (topic_path )
99
98
raise
100
99
return {'name' : topic_pb .name }
@@ -116,8 +115,8 @@ def topic_get(self, topic_path):
116
115
"""
117
116
try :
118
117
topic_pb = self ._gax_api .get_topic (topic_path )
119
- except GaxError as exc :
120
- if exc_to_code ( exc .cause ) == StatusCode .NOT_FOUND :
118
+ except GrpcRendezvous as exc :
119
+ if exc .code ( ) == StatusCode .NOT_FOUND :
121
120
raise NotFound (topic_path )
122
121
raise
123
122
return {'name' : topic_pb .name }
@@ -134,8 +133,8 @@ def topic_delete(self, topic_path):
134
133
"""
135
134
try :
136
135
self ._gax_api .delete_topic (topic_path )
137
- except GaxError as exc :
138
- if exc_to_code ( exc .cause ) == StatusCode .NOT_FOUND :
136
+ except GrpcRendezvous as exc :
137
+ if exc .code ( ) == StatusCode .NOT_FOUND :
139
138
raise NotFound (topic_path )
140
139
raise
141
140
@@ -163,8 +162,8 @@ def topic_publish(self, topic_path, messages):
163
162
try :
164
163
result = self ._gax_api .publish (topic_path , message_pbs ,
165
164
options = options )
166
- except GaxError as exc :
167
- if exc_to_code ( exc .cause ) == StatusCode .NOT_FOUND :
165
+ except GrpcRendezvous as exc :
166
+ if exc .code ( ) == StatusCode .NOT_FOUND :
168
167
raise NotFound (topic_path )
169
168
raise
170
169
return result .message_ids
@@ -201,8 +200,8 @@ def topic_list_subscriptions(self, topic_path, page_size=0,
201
200
try :
202
201
page_iter = self ._gax_api .list_topic_subscriptions (
203
202
topic_path , page_size = page_size , options = options )
204
- except GaxError as exc :
205
- if exc_to_code ( exc .cause ) == StatusCode .NOT_FOUND :
203
+ except GrpcRendezvous as exc :
204
+ if exc .code ( ) == StatusCode .NOT_FOUND :
206
205
raise NotFound (topic_path )
207
206
raise
208
207
subs = page_iter .next ()
@@ -294,8 +293,8 @@ def subscription_create(self, subscription_path, topic_path,
294
293
try :
295
294
sub_pb = self ._gax_api .create_subscription (
296
295
subscription_path , topic_path , push_config , ack_deadline )
297
- except GaxError as exc :
298
- if exc_to_code ( exc .cause ) == StatusCode .FAILED_PRECONDITION :
296
+ except GrpcRendezvous as exc :
297
+ if exc .code ( ) == StatusCode .FAILED_PRECONDITION :
299
298
raise Conflict (topic_path )
300
299
raise
301
300
return _subscription_pb_to_mapping (sub_pb )
@@ -316,8 +315,8 @@ def subscription_get(self, subscription_path):
316
315
"""
317
316
try :
318
317
sub_pb = self ._gax_api .get_subscription (subscription_path )
319
- except GaxError as exc :
320
- if exc_to_code ( exc .cause ) == StatusCode .NOT_FOUND :
318
+ except GrpcRendezvous as exc :
319
+ if exc .code ( ) == StatusCode .NOT_FOUND :
321
320
raise NotFound (subscription_path )
322
321
raise
323
322
return _subscription_pb_to_mapping (sub_pb )
@@ -335,8 +334,8 @@ def subscription_delete(self, subscription_path):
335
334
"""
336
335
try :
337
336
self ._gax_api .delete_subscription (subscription_path )
338
- except GaxError as exc :
339
- if exc_to_code ( exc .cause ) == StatusCode .NOT_FOUND :
337
+ except GrpcRendezvous as exc :
338
+ if exc .code ( ) == StatusCode .NOT_FOUND :
340
339
raise NotFound (subscription_path )
341
340
raise
342
341
@@ -360,8 +359,8 @@ def subscription_modify_push_config(self, subscription_path,
360
359
push_config = PushConfig (push_endpoint = push_endpoint )
361
360
try :
362
361
self ._gax_api .modify_push_config (subscription_path , push_config )
363
- except GaxError as exc :
364
- if exc_to_code ( exc .cause ) == StatusCode .NOT_FOUND :
362
+ except GrpcRendezvous as exc :
363
+ if exc .code ( ) == StatusCode .NOT_FOUND :
365
364
raise NotFound (subscription_path )
366
365
raise
367
366
@@ -392,8 +391,8 @@ def subscription_pull(self, subscription_path, return_immediately=False,
392
391
try :
393
392
response_pb = self ._gax_api .pull (
394
393
subscription_path , max_messages , return_immediately )
395
- except GaxError as exc :
396
- if exc_to_code ( exc .cause ) == StatusCode .NOT_FOUND :
394
+ except GrpcRendezvous as exc :
395
+ if exc .code ( ) == StatusCode .NOT_FOUND :
397
396
raise NotFound (subscription_path )
398
397
raise
399
398
return [_received_message_pb_to_mapping (rmpb )
@@ -415,8 +414,8 @@ def subscription_acknowledge(self, subscription_path, ack_ids):
415
414
"""
416
415
try :
417
416
self ._gax_api .acknowledge (subscription_path , ack_ids )
418
- except GaxError as exc :
419
- if exc_to_code ( exc .cause ) == StatusCode .NOT_FOUND :
417
+ except GrpcRendezvous as exc :
418
+ if exc .code ( ) == StatusCode .NOT_FOUND :
420
419
raise NotFound (subscription_path )
421
420
raise
422
421
@@ -442,8 +441,8 @@ def subscription_modify_ack_deadline(self, subscription_path, ack_ids,
442
441
try :
443
442
self ._gax_api .modify_ack_deadline (
444
443
subscription_path , ack_ids , ack_deadline )
445
- except GaxError as exc :
446
- if exc_to_code ( exc .cause ) == StatusCode .NOT_FOUND :
444
+ except GrpcRendezvous as exc :
445
+ if exc .code ( ) == StatusCode .NOT_FOUND :
447
446
raise NotFound (subscription_path )
448
447
raise
449
448
@@ -520,7 +519,7 @@ def make_gax_publisher_api(connection):
520
519
"""
521
520
channel = None
522
521
if connection .in_emulator :
523
- channel = insecure_channel (connection .host , None )
522
+ channel = insecure_channel (connection .host )
524
523
return PublisherApi (channel = channel )
525
524
526
525
@@ -540,5 +539,5 @@ def make_gax_subscriber_api(connection):
540
539
"""
541
540
channel = None
542
541
if connection .in_emulator :
543
- channel = insecure_channel (connection .host , None )
542
+ channel = insecure_channel (connection .host )
544
543
return SubscriberApi (channel = channel )
0 commit comments