99
1010class Options (AuthOptions ):
1111 def __init__ (self , client_id = None , log_level = 0 , tls = True , rest_host = None , realtime_host = None , port = 0 ,
12- tls_port = 0 , use_binary_protocol = True , queue_messages = False , recover = False , environment = None ,
13- http_open_timeout = None , http_request_timeout = None , realtime_request_timeout = None ,
12+ tls_port = 0 , use_binary_protocol = True , queue_messages = False , recover = False , endpoint = None ,
13+ environment = None , http_open_timeout = None , http_request_timeout = None , realtime_request_timeout = None ,
1414 http_max_retry_count = None , http_max_retry_duration = None , fallback_hosts = None ,
1515 fallback_retry_timeout = None , disconnected_retry_timeout = None , idempotent_rest_publishing = None ,
1616 loop = None , auto_connect = True , suspended_retry_timeout = None , connectivity_check_url = None ,
@@ -42,12 +42,18 @@ def __init__(self, client_id=None, log_level=0, tls=True, rest_host=None, realti
4242 if environment is not None and realtime_host is not None :
4343 raise ValueError ('specify realtime_host or environment, not both' )
4444
45+ if environment is not None and endpoint is not None :
46+ raise ValueError ('specify endpoint or environment, not both' )
47+
4548 if idempotent_rest_publishing is None :
4649 from ably import api_version
4750 idempotent_rest_publishing = api_version >= '1.2'
4851
49- if environment is None :
50- environment = Defaults .environment
52+ if environment is not None and endpoint is None :
53+ endpoint = environment
54+
55+ if endpoint is None :
56+ endpoint = Defaults .endpoint
5157
5258 self .__client_id = client_id
5359 self .__log_level = log_level
@@ -59,7 +65,7 @@ def __init__(self, client_id=None, log_level=0, tls=True, rest_host=None, realti
5965 self .__use_binary_protocol = use_binary_protocol
6066 self .__queue_messages = queue_messages
6167 self .__recover = recover
62- self .__environment = environment
68+ self .__endpoint = endpoint
6369 self .__http_open_timeout = http_open_timeout
6470 self .__http_request_timeout = http_request_timeout
6571 self .__realtime_request_timeout = realtime_request_timeout
@@ -163,8 +169,8 @@ def recover(self, value):
163169 self .__recover = value
164170
165171 @property
166- def environment (self ):
167- return self .__environment
172+ def endpoint (self ):
173+ return self .__endpoint
168174
169175 @property
170176 def http_open_timeout (self ):
@@ -268,27 +274,19 @@ def __get_rest_hosts(self):
268274 # Defaults
269275 host = self .rest_host
270276 if host is None :
271- host = Defaults .rest_host
272-
273- environment = self .environment
277+ host = Defaults .get_hostname (self .endpoint )
274278
275279 http_max_retry_count = self .http_max_retry_count
276280 if http_max_retry_count is None :
277281 http_max_retry_count = Defaults .http_max_retry_count
278282
279- # Prepend environment
280- if environment != 'production' :
281- host = '%s-%s' % (environment , host )
282-
283283 # Fallback hosts
284284 fallback_hosts = self .fallback_hosts
285285 if fallback_hosts is None :
286- if host == Defaults .rest_host :
287- fallback_hosts = Defaults .fallback_hosts
288- elif environment != 'production' :
289- fallback_hosts = Defaults .get_environment_fallback_hosts (environment )
290- else :
286+ if self .rest_host :
291287 fallback_hosts = []
288+ else :
289+ fallback_hosts = Defaults .get_fallback_hosts (self .endpoint )
292290
293291 # Shuffle
294292 fallback_hosts = list (fallback_hosts )
@@ -304,11 +302,8 @@ def __get_realtime_hosts(self):
304302 if self .realtime_host is not None :
305303 host = self .realtime_host
306304 return [host ]
307- elif self .environment != "production" :
308- host = f'{ self .environment } -{ Defaults .realtime_host } '
309- else :
310- host = Defaults .realtime_host
311305
306+ host = Defaults .get_hostname (self .endpoint )
312307 return [host ] + self .__fallback_hosts
313308
314309 def get_rest_hosts (self ):
0 commit comments