我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用django.utils.text.get_valid_filename()。
def get_valid_filename(s): """ like the regular get_valid_filename, but also slugifies away umlauts and stuff. """ s = get_valid_filename_django(s) filename, ext = os.path.splitext(s) filename = slugify(filename) ext = slugify(ext) if ext: return "%s.%s" % (filename, ext) else: return "%s" % (filename,)
def get_valid_name(self, name): """ Returns a filename, based on the provided filename, that's suitable for use in the target storage system. """ return get_valid_filename(name)
def parse_attachment(part): """ Get attachments of an email :param `Message` part: A `Message` :rtype: list :return: The list of attachments """ attachment = {} attachment['content_type'] = part.get_content_type() if attachment['content_type'].lower() in ['message/rfc822', 'message/delivery-status']: attachment['content'] = str(part) else: attachment['content'] = part.get_payload(decode=True) filename = part.get_filename() if not filename: filename = hashlib.sha1(attachment['content']).hexdigest() if attachment['content_type']: extension = mimetypes.guess_extension(attachment['content_type']) if extension: filename += extension attachment['filename'] = get_valid_filename(utils.decode_every_charset_in_the_world(filename)) return attachment
def get_download_filename(self): """ Return a valid filename to be downloaded as. """ title = self.contentnode.title filename = "{} ({}).{}".format(title, self.get_preset(), self.get_extension()) valid_filename = get_valid_filename(filename) return valid_filename
def _get_valid_name(self, name): dir_name, file_name = os.path.split(name) file_name = get_valid_filename(file_name) name = os.path.join(dir_name, file_name) return name