MCPcopy
hub / github.com/cherrypy/cherrypy / normalize_path

Function normalize_path

cherrypy/_helper.py:291–314  ·  view source on GitHub ↗

Resolve given path from relative into absolute form.

(path)

Source from the content-addressed store, hash-verified

289
290
291def normalize_path(path):
292 """Resolve given path from relative into absolute form."""
293 if './' not in path:
294 return path
295
296 # Normalize the URL by removing ./ and ../
297 atoms = []
298 for atom in path.split('/'):
299 if atom == '.':
300 pass
301 elif atom == '..':
302 # Don't pop from empty list
303 # (i.e. ignore redundant '..')
304 if atoms:
305 atoms.pop()
306 elif atom:
307 atoms.append(atom)
308
309 newpath = '/'.join(atoms)
310 # Preserve leading '/'
311 if path.startswith('/'):
312 newpath = '/' + newpath
313
314 return newpath
315
316
317####

Callers 1

urlFunction · 0.85

Calls 2

popMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…