MCPcopy Index your code
hub / github.com/algorithmiaio/algorithmia-python / getParentAndBase

Function getParentAndBase

Algorithmia/util.py:8–29  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

6
7
8def getParentAndBase(path):
9 match = PREFIX.match(path)
10 if match is None:
11 if path.endswith('/'):
12 stripped_path = path[:-1]
13 else:
14 stripped_path = path
15 base = FNAME_MATCH.search(stripped_path)
16 if base is None:
17 raise ValueError('Invalid path')
18 parent = FNAME_MATCH.sub('', stripped_path)
19 return parent, base.group(1)
20 else:
21 prefix, leading_slash, uri = match.groups()
22 parts = uri.split('/')
23 parent_path = '/'.join(parts[:-1])
24
25 if leading_slash is not None:
26 parent_path = '{prefix}/{uri}'.format(prefix=prefix, uri='/'.join(parts[:-1]))
27 else:
28 parent_path = '{prefix}{uri}'.format(prefix=prefix, uri='/'.join(parts[:-1]))
29 return parent_path, parts[-1]
30
31
32def pathJoin(parent, base):

Callers 5

getNameMethod · 0.90
getNameMethod · 0.90
getNameMethod · 0.90
createMethod · 0.90
test_getParentAndBaseMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_getParentAndBaseMethod · 0.72