MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / filename

Method filename

21-async/mojifinder/bottle.py:2371–2387  ·  view source on GitHub ↗

Name of the file on the client file system, but normalized to ensure file system compatibility. An empty filename is returned as 'empty'. Only ASCII letters, digits, dashes, underscores and dots are allowed in the final filename. Accents are removed, if possible

(self)

Source from the content-addressed store, hash-verified

2369
2370 @cached_property
2371 def filename(self):
2372 ''' Name of the file on the client file system, but normalized to ensure
2373 file system compatibility. An empty filename is returned as 'empty'.
2374
2375 Only ASCII letters, digits, dashes, underscores and dots are
2376 allowed in the final filename. Accents are removed, if possible.
2377 Whitespace is replaced by a single dash. Leading or tailing dots
2378 or dashes are removed. The filename is limited to 255 characters.
2379 '''
2380 fname = self.raw_filename
2381 if not isinstance(fname, unicode):
2382 fname = fname.decode('utf8', 'ignore')
2383 fname = normalize('NFKD', fname).encode('ASCII', 'ignore').decode('ASCII')
2384 fname = os.path.basename(fname.replace('\\', os.path.sep))
2385 fname = re.sub(r'[^a-zA-Z0-9-_.\s]', '', fname).strip()
2386 fname = re.sub(r'[-\s]+', '-', fname).strip('.-')
2387 return fname[:255] or 'empty'
2388
2389 def _copy_file(self, fp, chunk_size=2**16):
2390 read, write, offset = self.file.read, fp.write, self.file.tell()

Callers

nothing calls this directly

Calls 3

normalizeFunction · 0.85
decodeMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected