@@ -25,10 +25,13 @@ def __init__(self, auth, host, impersonate_subuser, region='global'):
2525 """
2626 from . import __version__
2727 self .auth = auth
28- self .host = host
2928 self .impersonate_subuser = impersonate_subuser
3029 self .version = __version__
3130 self .useragent = 'sendgrid/{};python' .format (self .version )
31+ if region is None :
32+ self .host = host
33+ else :
34+ self .set_data_residency (region = region )
3235
3336 self .client = python_http_client .Client (
3437 host = self .host ,
@@ -64,30 +67,29 @@ def send(self, message):
6467
6568 return self .client .mail .send .post (request_body = message )
6669
67- def set_host (self ,host ):
70+ def set_host (self , host ):
6871 self .host = host
6972 self .client = python_http_client .Client (
7073 host = self .host ,
7174 request_headers = self ._default_headers ,
7275 version = 3 )
7376
74- def set_data_residency (self ,region ):
77+ def set_data_residency (self , region ):
7578 """
76- * Client libraries contain setters for specifying region/edge.
77- * This allows support global and eu regions only. This set will likely expand in the future.
78- * Global should be the default
79- * Global region means the message should be sent through:
80- * HTTP: api.sendgrid.com
81- * EU region means the message should be sent through:
82- * HTTP: api.eu.sendgrid.com
79+ Client libraries contain setters for specifying region/edge.
80+ This supports global and eu regions only. This set will likely expand in the future.
81+ Global is the default residency (or region)
82+ Global region means the message will be sent through https://api.sendgrid.com
83+ EU region means the message will be sent through https://api.eu.sendgrid.com
8384 :param region:
8485 :return:
8586 """
8687 if region in region_host_dict .keys ():
8788 self .host = region_host_dict [region ]
88- self .client = python_http_client .Client (
89- host = self .host ,
90- request_headers = self ._default_headers ,
91- version = 3 )
89+ if self ._default_headers is not None :
90+ self .client = python_http_client .Client (
91+ host = self .host ,
92+ request_headers = self ._default_headers ,
93+ version = 3 )
9294 else :
9395 raise ValueError ("region can only be \" eu\" or \" global\" " )
0 commit comments