Coverage for /usr/local/lib/python3.11/site-packages/tgclients/config.py: 99%
54 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-02 16:49 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-02 16:49 +0000
1# SPDX-FileCopyrightText: 2022 Georg-August-Universität Göttingen
2#
3# SPDX-License-Identifier: CC0-1.0
5"""Variable config options with defaults to be used with the TextGrid clients library."""
6import logging
7from typing import Optional
9logger = logging.getLogger(__name__)
11DEFAULT_TIMEOUT: float = 120.00
13PROD_SERVER: str = 'https://textgridlab.org'
14DEV_SERVER: str = 'https://dev.textgridlab.org'
15TEST_SERVER: str = 'https://test.textgridlab.org'
18class TextgridConfig:
19 """Provide standard configuration / URLs for TextGrid services.
20 Default is to connect to the TextGrid
21 production server (https://textgridlab.org).
22 Pass the constants tgclients.config.DEV_SERVER or
23 tgclients.config.TEST_SERVER to the constructor to change to
24 develop or test server or provide an URL for your own instance.
25 """
27 def __init__(self, host: Optional[str] = 'https://textgridlab.org') -> None:
28 """TextGrid Service Endpoint Configuration.
30 Overwrite the host string to connect to other servers, e.g.:
31 * Test-Server: https://test.textgridlab.org
32 (use constant tgclients.config.TEST_SERVER)
33 * Development-Server: https://dev.textgridlab.org
34 (use constant tgclients.config.DEV_SERVER)
36 Args:
37 host (Optional[str]):TextGrid server. Defaults to 'https://textgridlab.org'.
38 """
39 if not isinstance(host, str) or host == '':
40 logger.info(
41 'host param was None or emtpy, default to: %s', PROD_SERVER)
42 host = PROD_SERVER
43 if host.endswith('/'):
44 logger.info('trailing slash in hostname detected and removed')
45 host = host[:-1]
46 self._host = host
47 self._http_timeout = DEFAULT_TIMEOUT
49 @property
50 def host(self) -> str:
51 """the host URL
53 Returns:
54 str: the configured host URL
55 """
56 return self._host
58 @property
59 def auth_wsdl(self) -> str:
60 """the tgauth wsdl location
62 Returns:
63 str: the tgauth wsdl location
64 """
65 return self._host + '/1.0/tgauth/wsdl/tgextra.wsdl'
67 @property
68 def auth_address(self) -> str:
69 """the tgauth service location
71 Returns:
72 str: the tgauth service location
73 """
74 return self._host + '/1.0/tgauth/tgextra.php'
76 @property
77 def extra_crud_wsdl(self) -> str:
78 """the tgextra wsdl location
80 Returns:
81 str: the tgextra wsdl location
82 """
83 return self._host + '/1.0/tgauth/wsdl/tgextra-crud.wsdl'
85 @property
86 def extra_crud_address(self) -> str:
87 """the tgextra service location
89 Returns:
90 str: the tgextra service location
91 """
92 return self._host + '/1.0/tgauth/tgextra-crud.php'
94 @property
95 def search(self) -> str:
96 """the nonpublic tgsearch service location
98 Returns:
99 str: the nonpublic tgsearch service location
100 """
101 return self._host + '/1.0/tgsearch'
103 @property
104 def search_public(self) -> str:
105 """the public tgsearch service location
107 Returns:
108 str: the public tgsearch service location
109 """
110 return self._host + '/1.0/tgsearch-public'
112 @property
113 def crud(self) -> str:
114 """the nonpublic tgcrud REST service location
116 Returns:
117 str: the nonpublic tgcrud REST service location
118 """
119 return self._host + '/1.0/tgcrud/rest'
121 @property
122 def crud_public(self) -> str:
123 """the public tgcrud REST service location
125 Returns:
126 str: the public tgcrud REST service location
127 """
128 return self._host + '/1.0/tgcrud-public/rest'
130 @property
131 def aggregator(self) -> str:
132 """the aggregator service location
134 Returns:
135 str: the aggregator service location
136 """
137 return self._host + '/1.0/aggregator'
139 @property
140 def http_timeout(self) -> float:
141 """HTTP timeout to be used when accessing TextGrid services
143 Returns:
144 float: http timeout in seconds
145 """
146 return self._http_timeout
148 @http_timeout.setter
149 def http_timeout(self, value: float) -> None:
150 """Set HTTP timeout to be used when accessing TextGrid services
152 Args:
153 value (float): the timeout
154 """
155 self._http_timeout = value