Beispiel #1
0
def get_valid_file_extension(request, mimetype):
    """
    Helper function to return the predefined file extension for a mimetype.
    Also used to check valid file types (return None if not supported)
    """
    vme = valid_mime_extensions(request)
    try:
        return vme[mimetype]
    except KeyError:
        return None
Beispiel #2
0
def getFileUploadValidExtensions(request):
    """
    Return an ordered list of valid file extensions for uploads as defined in
    the ini configuration of the application.
    """
    extensions = []
    validExtensions = valid_mime_extensions(request)
    for currentExtension in validExtensions:
        for knownExtension in mimetypes.guess_all_extensions(currentExtension):
            # Add each extension only once
            if knownExtension not in extensions:
                extensions.append(knownExtension)
    return sorted(extensions)