Logo Search packages:      
Sourcecode: zope-cps-portaltransforms version File versions  Download package

def PortalTransforms::MimeTypesRegistry::MimeTypesRegistry::classify (   self,
  data,
  mimetype = None,
  filename = None 
)

Classify works as follows:
1) you tell me the rfc-2046 name and I give you an imimetype
   object
2) the filename includes an extension from which we can guess
   the mimetype
3) we can optionally introspect the data
4) default to self.defaultMimetype if no data was provided
   else to application/octet-stream if no filename was provided,
   else to None

Return an imimetype object

Definition at line 187 of file MimeTypesRegistry.py.

00187                                                           :
        """Classify works as follows:
        1) you tell me the rfc-2046 name and I give you an imimetype
           object
        2) the filename includes an extension from which we can guess
           the mimetype
        3) we can optionally introspect the data
        4) default to self.defaultMimetype if no data was provided
           else to application/octet-stream if no filename was provided,
           else to None

        Return an imimetype object
        """
        mt = None
        if mimetype:
            mt = self.lookup(mimetype)
            if mt:
                mt = mt[0]
        elif filename:
            mt = self.lookupExtension(filename)
        if data and not mt:
            for c in self._classifiers():
                if c.classify(data):
                    mt = c
                    break
            if not mt:
                mstr = magic.guessMime(data)
                if mstr:
                    mt = self.lookup(mstr)
                    if mt:
                        mt = mt[0]
        if not mt:
            if not data:
                mt = self.lookup(self.defaultMimetype)[0]
            elif filename:
                mt = self.lookup('application/octet-stream')[0]
            else:
                mt = None
        if mt:
            # Remove acquisition wrappers
            mt = aq_base(mt)
            # Copy by pickle, to remove connection references
            mt = loads(dumps(mt))
        return mt

    def __call__(self, data, **kwargs):


Generated by  Doxygen 1.6.0   Back to index