MCPcopy Create free account
hub / github.com/docker/docker-py / normalize

Method normalize

docker/utils/build.py:233–257  ·  view source on GitHub ↗
(cls, p)

Source from the content-addressed store, hash-verified

231
232 @classmethod
233 def normalize(cls, p):
234
235 # Remove trailing spaces
236 p = p.strip()
237
238 # Leading and trailing slashes are not relevant. Yes,
239 # "foo.py/" must exclude the "foo.py" regular file. "."
240 # components are not relevant either, even if the whole
241 # pattern is only ".", as the Docker reference states: "For
242 # historical reasons, the pattern . is ignored."
243 # ".." component must be cleared with the potential previous
244 # component, regardless of whether it exists: "A preprocessing
245 # step [...] eliminates . and .. elements using Go's
246 # filepath.".
247 i = 0
248 split = split_path(p)
249 while i < len(split):
250 if split[i] == '..':
251 del split[i]
252 if i > 0:
253 del split[i - 1]
254 i -= 1
255 else:
256 i += 1
257 return split
258
259 def match(self, filepath):
260 return fnmatch(normalize_slashes(filepath), self.cleaned_pattern)

Callers 1

__init__Method · 0.95

Calls 1

split_pathFunction · 0.85

Tested by

no test coverage detected