mtpgwlib.magic
index
/home/klokan/Projects/MarineTrans/opt/mtpgw/lib/mtpgwlib/magic.py

magic module
------------
Recognise type of file - based on magic sequence (first several bytes) and
scaning of content..
 
Supported types are: 'EMAIL', 'MTP', 'MTMLPolarisAttachment',
'MTMLPolarisRequisition', 'XLS'
 
If unsupported type is recognised DocumentUnsupported exception is thrown.
 
MTP - Marine Trans Purchasing
Copyright (2005) Klokan Petr Pridal

 
Functions
       
magic(content, filename)
Recognise content type according magic sequence (in the begining of
file). Returns one of: 'EMAIL', 'MTP', 'MTMLPolarisAttachment', 
'MTMLPolarisRequisition', 'XLS' or throw a DocumentUnsupported exception.
 
>>> magic('From adfafasf@klokan.cz','')
'EMAIL'
>>> magic('<?xml asdfasdf <MTP','')
'MTP'
>>> magic('<?xml asdfasdf <MTmL> ... <Requisition','')
'MTMLPolarisRequisition'
>>> magic('<?xml><MTML VersionNumber="2.0" PreparationTime=""> <Attachment..','')
'MTMLPolarisAttachment'
>>> magic('BIFF8asdfasdf','test.xls')
'XLS'
>>> magic('asdfasdfa','') # not supported document
Traceback (most recent call last):
    ...
DocumentUnsupported: Unsupported type of document