Exemple #1
0
 def getAllowedExtensionList(self, request_dict={}):
   """List types which can be generated from given type
   Type can be given as:
     - filename extension
     - document type ('text', 'spreadsheet', 'presentation' or 'drawing')
   e.g
   self.getAllowedMimetypeList(dict(document_type="text"))
   return extension_list
   """
   mimetype = request_dict.get('mimetype')
   extension = request_dict.get('extension')
   document_type = request_dict.get('document_type')
   if mimetype:
     allowed_extension_list = []
     for ext in guess_all_extensions(mimetype):
       ext = ext.replace('.', '')
       extension_list = mimemapper.getAllowedExtensionList(extension=ext,
                                                document_type=document_type)
       for extension in extension_list:
         if extension not in allowed_extension_list:
           allowed_extension_list.append(extension)
     return allowed_extension_list
   elif extension:
     extension = extension.replace('.', '')
     return mimemapper.getAllowedExtensionList(extension=extension,
                                                document_type=document_type)
   elif document_type:
     return mimemapper.getAllowedExtensionList(document_type=document_type)
   else:
     return [('', '')]
Exemple #2
0
 def getAllowedExtensionList(self, request_dict={}):
     """List types which can be generated from given type
 Type can be given as:
   - filename extension
   - document type ('text', 'spreadsheet', 'presentation' or 'drawing')
 e.g
 self.getAllowedMimetypeList(dict(document_type="text"))
 return extension_list
 """
     mimetype = request_dict.get('mimetype')
     extension = request_dict.get('extension')
     document_type = request_dict.get('document_type')
     if mimetype:
         allowed_extension_list = []
         for ext in guess_all_extensions(mimetype):
             ext = ext.replace('.', '')
             extension_list = mimemapper.getAllowedExtensionList(
                 extension=ext, document_type=document_type)
             for extension in extension_list:
                 if extension not in allowed_extension_list:
                     allowed_extension_list.append(extension)
         return allowed_extension_list
     elif extension:
         extension = extension.replace('.', '')
         return mimemapper.getAllowedExtensionList(
             extension=extension, document_type=document_type)
     elif document_type:
         return mimemapper.getAllowedExtensionList(
             document_type=document_type)
     else:
         return [('', '')]
Exemple #3
0
  def getAllowedExtensionList(self, request_dict={}):
    """BBB: extension should not be used, use MIMEType with getAllowedConversionFormatList

    List extension which can be generated from given type
    Type can be given as:
      - content type
      - filename extension
      - document type
    """
    mimetype = request_dict.get('mimetype')
    extension = request_dict.get('extension')
    document_type = request_dict.get('document_type')
    if not mimetype:
      if extension:
        mimetype, _ = BBB_guess_type("a." + extension)
      elif document_type:
        # BBB no other choice than to ask ooo.mimemapper
        return mimemapper.getAllowedExtensionList(document_type=document_type)
    if mimetype:
      allowed_extension_set = set()
      for content_type, title in self.getAllowedConversionFormatList(mimetype):
        ext = BBB_guess_extension(content_type, title)
        if ext:
          allowed_extension_set.add((ext.lstrip('.'), title))
      return list(allowed_extension_set) or [('', '')]
    else:
      return [('', '')]
Exemple #4
0
  def getAllowedConversionFormatList(source_mimetype):
    """Returns a list content_type and their titles which are supported
    by enabled handlers.

    [('application/vnd.oasis.opendocument.text', 'ODF Text Document'),
     ('application/pdf', 'PDF - Portable Document Format'),
     ...
    ]
    """
    # XXX please never guess extension from mimetype
    output_set = set()
    if "/" in source_mimetype:
      parsed_mimetype_type = parseContentType(source_mimetype).gettype()
      # here `guess_all_extensions` never handles mimetype parameters
      #   (even for `text/plain;charset=UTF-8` which is standard)
      extension_list = mimetypes.guess_all_extensions(parsed_mimetype_type)  # XXX never guess
    else:
      extension_list = [source_mimetype]

    for ext in extension_list:
      for ext, title in mimemapper.getAllowedExtensionList(extension=ext.replace(".", "")):
        if ext in ("fodt", ".fodt"):  # BBB
          output_set.add(("application/vnd.oasis.opendocument.text-flat-xml", title))
          continue
        if ext:
          mimetype, _ = mimetypes.guess_type("a." + ext)  # XXX never guess
          if mimetype:
            output_set.add((mimetype, title))
    return list(output_set)
Exemple #5
0
    def getAllowedConversionFormatList(source_mimetype):
        """Returns a list content_type and their titles which are supported
    by enabled handlers.

    [('application/vnd.oasis.opendocument.text', 'ODF Text Document'),
     ('application/pdf', 'PDF - Portable Document Format'),
     ...
    ]
    """
        # XXX please never guess extension from mimetype
        output_set = set()
        if "/" in source_mimetype:
            parsed_mimetype_type = parseContentType(source_mimetype).gettype()
            # here `guess_all_extensions` never handles mimetype parameters
            #   (even for `text/plain;charset=UTF-8` which is standard)
            extension_list = mimetypes.guess_all_extensions(
                parsed_mimetype_type)  # XXX never guess
        else:
            extension_list = [source_mimetype]

        for ext in extension_list:
            for ext, title in mimemapper.getAllowedExtensionList(
                    extension=ext.replace(".", "")):
                if ext in ("fodt", ".fodt"):  # BBB
                    output_set.add(
                        ("application/vnd.oasis.opendocument.text-flat-xml",
                         title))
                    continue
                if ext:
                    mimetype, _ = mimetypes.guess_type("a." +
                                                       ext)  # XXX never guess
                    if mimetype:
                        output_set.add((mimetype, title))
        return list(output_set)
Exemple #6
0
    def getAllowedExtensionList(self, request_dict={}):
        """BBB: extension should not be used, use MIMEType with getAllowedConversionFormatList

    List extension which can be generated from given type
    Type can be given as:
      - content type
      - filename extension
      - document type
    """
        mimetype = request_dict.get('mimetype')
        extension = request_dict.get('extension')
        document_type = request_dict.get('document_type')
        if not mimetype:
            if extension:
                mimetype, _ = BBB_guess_type("a." + extension)
            elif document_type:
                # BBB no other choice than to ask ooo.mimemapper
                return mimemapper.getAllowedExtensionList(
                    document_type=document_type)
        if mimetype:
            allowed_extension_set = set()
            for content_type, title in self.getAllowedConversionFormatList(
                    mimetype):
                ext = BBB_guess_extension(content_type, title)
                if ext:
                    allowed_extension_set.add((ext.lstrip('.'), title))
            return list(allowed_extension_set) or [('', '')]
        else:
            return [('', '')]