Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3ae1ee3

Browse files
committed
Add Node creation with a URL string
1 parente22e31d commit3ae1ee3

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

‎typesense/configuration.py‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
from .exceptionsimportConfigError
22
from .loggerimportlogger
3-
3+
fromurllib.parseimporturlparse
44

55
classNode(object):
6+
def__init__(self,url):
7+
parsed=urlparse(url);
8+
ifnotparsed.hostname:
9+
raiseConfigError('Node URL does not contain the host name.')
10+
ifnotparsed.port:
11+
raiseConfigError('Node URL does not contain the port.')
12+
ifnotparsed.scheme:
13+
raiseConfigError('Node URL does not contain the protocol.')
14+
self.__init__(parsed.hostname,parsed.port,parsed.path,parsed.scheme)
15+
616
def__init__(self,host,port,path,protocol):
717
self.host=host
818
self.port=port
@@ -21,19 +31,21 @@ def __init__(self, config_dict):
2131
Configuration.show_deprecation_warnings(config_dict)
2232
Configuration.validate_config_dict(config_dict)
2333

24-
node_dicts=config_dict.get('nodes', [])
25-
2634
self.nodes= []
27-
fornode_dictinnode_dicts:
28-
self.nodes.append(
29-
Node(node_dict['host'],node_dict['port'],node_dict.get('path',''),node_dict['protocol'])
30-
)
35+
fornode_configinconfig_dict.get('nodes', []):
36+
ifisinstance(node_config,str):
37+
node=Node(node_config)
38+
else:
39+
node=Node(node_config['host'],node_config['port'],node_config.get('path',''),node_config['protocol'])
40+
self.nodes.append(node)
3141

3242
nearest_node=config_dict.get('nearest_node',None)
33-
ifnearest_node:
34-
self.nearest_node=Node(nearest_node['host'],nearest_node['port'],nearest_node.get('path',''),nearest_node['protocol'])
35-
else:
43+
ifnotnearest_node:
3644
self.nearest_node=None
45+
elseifisinstance(nearest_node,str):
46+
self.nearest_node=Node(nearest_node)
47+
else:
48+
self.nearest_node=Node(nearest_node['host'],nearest_node['port'],nearest_node.get('path',''),nearest_node['protocol'])
3749

3850
self.api_key=config_dict.get('api_key','')
3951
self.connection_timeout_seconds=config_dict.get('connection_timeout_seconds',3.0)
@@ -53,16 +65,18 @@ def validate_config_dict(config_dict):
5365

5466
fornodeinnodes:
5567
ifnotConfiguration.validate_node_fields(node):
56-
raiseConfigError('`node` entry must be a dictionary with the following required keys: '
68+
raiseConfigError('`node` entry must be aURL string or adictionary with the following required keys: '
5769
'host, port, protocol')
5870

5971
nearest_node=config_dict.get('nearest_node',None)
6072
ifnearest_nodeandnotConfiguration.validate_node_fields(nearest_node):
61-
raiseConfigError('`nearest_node` entry must be a dictionary with the following required keys: '
73+
raiseConfigError('`nearest_node` entry must be aURL string or adictionary with the following required keys: '
6274
'host, port, protocol')
6375

6476
@staticmethod
6577
defvalidate_node_fields(node):
78+
ifisinstance(node,str):
79+
returntrue
6680
expected_fields= {'host','port','protocol'}
6781
returnexpected_fields.issubset(node)
6882

@@ -76,4 +90,3 @@ def show_deprecation_warnings(config_dict):
7690

7791
ifconfig_dict.get('read_replica_nodes'):
7892
logger.warn('Deprecation warning: read_replica_nodes is now consolidated to nodes, starting with Typesense Server v0.12')
79-

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp