def _getHandler(self, instance):
     """
     _getHandler(self, instance) => get the handler object
     """
     handler = AttachmentHandler.getAttachmentHandler(
         self.getContentType(instance, ),
         self, instance,
         )
     return handler
    def _old_testFileIndexing(self, file, handler, output_encoding):
        """
        testFileIndexing(self, file, handler, output_encoding) => dict
        the dict keys are :
          - content_type: MIME type
          - content_length: length
          - filename: filename (!)
          - raw_content: file.read()
          - index: indexable value
          - preview: html preview
          - encoding: same as output_encoding
        handler id and output encoding must be provided.
        """
        import AttachmentHandler
        filename = file.filename
        content = file.read()
        content_type = string.lower(file.headers['Content-Type'])
        ret = {
            "content_type": content_type,
            "content_length": len(content),
            "filename": filename,
            "raw_content": content,
            "handler": "(unknown)",
            "handler_mime": "(unknown)",
            "index": "(unavailable)",
            "index_sample": "(unavailable)",
            "preview": "(unavailable)",
            "encoding": output_encoding,
            }
        handlers = AttachmentHandler.__HANDLERS__
        hnd = handler
        name = None
        mime = None

        if hnd:
            # Specific handler : get it
            for klass, handler in handlers:
                name = klass
                if name == hnd:
                    break
        else:
            # Try to guess the handler according to content-type
            handler = AttachmentHandler.getAttachmentHandler(
                content_type, None, self,
                )
            name = handler.__class__.__name__
            mime = handler.content_types

        # Ok, we've found the right handler
        ret["handler_mime"] = mime
        ret["handler"] = name
        try:
            # use the converter
            index = handler.convertStringToIndex(content, content_type, self)

            # Provide a more useable presentation
            index_sample = index[:INDEX_SAMPLE_LENGTH]
            index = "%d words." % (
                len(string.split(index)),
                )

        except:
            s = StringIO.StringIO()
            traceback.print_exc(file = s, )
            s.seek(0)
            index = s.read()
            index_sample = ""

        try:
            preview = handler.convertStringToPreview(content, content_type, self)
            preview = preview.encode(output_encoding, "replace")

        except:
            s = StringIO.StringIO()
            traceback.print_exc(file = s, )
            s.seek(0)
            preview = s.read()

        ret['index'] = index
        ret['index_sample'] = index_sample
        ret['preview'] = preview

        return ret