Skip to content

Commit ae6c615

Browse files
committed
Add stub files and start porting tests
1 parent 2c6b0a6 commit ae6c615

File tree

2 files changed

+769
-0
lines changed

2 files changed

+769
-0
lines changed

lib/pyld/iri_resolver.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
def resolve(relative_iri: str, base_iri: str | None = None) -> str:
2+
# TODO: implement
3+
return ''
4+
5+
def remove_dot_segments(path: str) -> str:
6+
"""
7+
Removes dot segments from a URL path.
8+
9+
:param path: the path to remove dot segments from.
10+
11+
:return: a path with normalized dot segments.
12+
"""
13+
14+
# RFC 3986 5.2.4 (reworked)
15+
16+
# empty path shortcut
17+
if len(path) == 0:
18+
return ''
19+
20+
input = path.split('/')
21+
output = []
22+
23+
while len(input) > 0:
24+
next = input.pop(0)
25+
done = len(input) == 0
26+
27+
if next == '.':
28+
if done:
29+
# ensure output has trailing /
30+
output.append('')
31+
continue
32+
33+
if next == '..':
34+
if len(output) > 0:
35+
output.pop()
36+
if done:
37+
# ensure output has trailing /
38+
output.append('')
39+
continue
40+
41+
output.append(next)
42+
43+
# ensure output has leading /
44+
# merge path segments from section 5.2.3
45+
# note that if the path includes no segments, the entire path is removed
46+
if len(output) > 0 and path.startswith('/') and output[0] != '':
47+
output.insert(0, '')
48+
if len(output) == 1 and output[0] == '':
49+
return '/'
50+
51+
return '/'.join(output)

0 commit comments

Comments
 (0)