You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ni...@apache.org on 2021/06/01 17:49:48 UTC
[atlas] 01/05: ATLAS-4318 : fix python client api url concatenation
(#130)
This is an automated email from the ASF dual-hosted git repository.
nixon pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/atlas.git
commit bf688aa126d0c8cda09912badd95e879420b0258
Author: Claudio Benfatto <cl...@gmail.com>
AuthorDate: Tue Jun 1 16:52:22 2021 +0200
ATLAS-4318 : fix python client api url concatenation (#130)
(cherry picked from commit 4f74de1498ef9f191f2b6d21d963d6de6ca0c5f9)
---
intg/src/main/python/apache_atlas/utils.py | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/intg/src/main/python/apache_atlas/utils.py b/intg/src/main/python/apache_atlas/utils.py
index 8500293..01d0762 100644
--- a/intg/src/main/python/apache_atlas/utils.py
+++ b/intg/src/main/python/apache_atlas/utils.py
@@ -17,6 +17,7 @@
# limitations under the License.
import enum
import time
+from functools import reduce
BASE_URI = "api/atlas/"
APPLICATION_JSON = 'application/json'
@@ -118,16 +119,28 @@ class API:
self.consumes = consumes
self.produces = produces
+ def multipart_urljoin(self, base_path, *path_elems):
+ """Join a base path and multiple context path elements. Handle single
+ leading and trailing `/` characters transparently.
+
+ Args:
+ base_path (string): the base path or url (ie. `http://atlas/v2/`)
+ *path_elems (string): multiple relative path elements (ie. `/my/relative`, `/path`)
+
+ Returns:
+ string: the result of joining the base_path with the additional path elements
+ """
+ def urljoin_pair(left, right):
+ return "/".join([left.rstrip('/'), right.strip('/')])
+
+ return reduce(urljoin_pair, path_elems, base_path)
+
def format_path(self, params):
return API(self.path.format(**params), self.method, self.expected_status, self.consumes, self.produces)
def format_path_with_params(self, *params):
- path = self.path
-
- for par in params:
- path += "/" + par
-
- return API(path, self.method, self.expected_status, self.consumes, self.produces)
+ request_path = self.multipart_urljoin(self.path, *params)
+ return API(request_path, self.method, self.expected_status, self.consumes, self.produces)
class HTTPMethod(enum.Enum):