MCPcopy Create free account
hub / github.com/datapane/datapane / filename

Method filename

python-client/src/datapane/_vendor/bottle.py:2750–2767  ·  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

2748
2749 @cached_property
2750 def filename(self):
2751 """ Name of the file on the client file system, but normalized to ensure
2752 file system compatibility. An empty filename is returned as 'empty'.
2753
2754 Only ASCII letters, digits, dashes, underscores and dots are
2755 allowed in the final filename. Accents are removed, if possible.
2756 Whitespace is replaced by a single dash. Leading or tailing dots
2757 or dashes are removed. The filename is limited to 255 characters.
2758 """
2759 fname = self.raw_filename
2760 if not isinstance(fname, unicode):
2761 fname = fname.decode('utf8', 'ignore')
2762 fname = normalize('NFKD', fname)
2763 fname = fname.encode('ASCII', 'ignore').decode('ASCII')
2764 fname = os.path.basename(fname.replace('\\', os.path.sep))
2765 fname = re.sub(r'[^a-zA-Z0-9-_.\s]', '', fname).strip()
2766 fname = re.sub(r'[-\s]+', '-', fname).strip('.-')
2767 return fname[:255] or 'empty'
2768
2769 def _copy_file(self, fp, chunk_size=2 ** 16):
2770 read, write, offset = self.file.read, fp.write, self.file.tell()

Callers

nothing calls this directly

Calls 2

decodeMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected