mò
d{£>c           @   s   d  Z  d d d !Z d d d !Z d d d !Z d k Z d k Z d k Z h  Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d S(   sĈ  
$RCSfile: ProductProperties.py,v $

This module includes all of those properties that really belong to the
ExternalFile Product as a whole, rather than to any particular
_instance_ of ExternalFile.

These properties are loaded in from ASCII configuration files at
Zope startup time.  See the comments in the top of 'mime.types'
and 'display.types' for more information.

Author: <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
Release: 1.2

s	   $Name:  $i   iŝ˙˙˙s   $Date: 2003/04/21 00:56:27 $s   $Revision: 1.3 $i
   Nc         C   s>   t  i |   } | p	 d GHn | o t  i i |  n d S(   s[   

    Initialize the mimetype list with addl mimetypes
    from the file 'mime.types'

    s%   Empty or non-existent mime.types fileN(   t	   mimetypest   read_mime_typest   filepatht   typemapt	   types_mapt   update(   R   R   (    (    tM   /home2/kennisonb/webapps/zope/Zope/Products/ExternalFile/ProductProperties.pyt   initMimeTypeList   s     	c         C   sŝ   y t  |   } Wn t j
 o d GHd Sn Xh  } x¸ | i   } | p Pn | i   } x; t	 t
 |   D]' } | | d d j o | | 3Pqo qo W| p q8 n t
 |  d j o d G| d GHn | d | d } } | t | <q8 W| i   d S(   s   

    Initialize the custom DisplayType list from the file
    'display.types' Using an algorithm adapted from Python builtin
    mimetypes.py

    s    Error reading display.types fileNi   i    t   #i   s)   Extra characters in display.types ignored(   t   openR   t   ft   IOErrort   mapt   readlinet   linet   splitt   wordst   ranget   lent   it   mimetypet   displaytypet   display_type_mapt   close(   R   R   R   R
   R   R   R   R   (    (    R   t   initDisplayTypeList)   s2     	    	 c           C   s   d S(   s}   
    The mimetype to assign by default if we can't figure it
    out by looking at the suffix (or if there is no suffix)
    s   application/octet-streamN(    (    (    (    R   t   getDefaultMimeTypeH   s     c          C   st   t  i i   } | i   | d }  xJ t t |  d d d  D], } |  | | j o | | =q@ | | }  q@ W| S(   s$   Return list of available mime types.i˙˙˙˙i   N(	   R    R   t   valuest   typelistt   sortt   lastR   R   R   (   R   R   R   (    (    R   t   getMimeTypeListO   s     

  c         C   sD   d \ } } |  o t i |   \ } } n | p t   } n | S(   sò   

    Given a file, return the appropriate mime type.  If the mime type
    cannot be guessed from the suffix (or there is no suffix), return
    the default mimetype.  If the file is None, automatically return
    the default mimetype.

    t    N(   R   R   (   R   t   encodingR   R    t
   guess_typeR   (   R   R   R    (    (    R   t   getMimeTypeFromFile]   s     c         C   sm   t  i |  d  } | pP |  i d d  \ } } | d j o
 d } qi | d j o
 d } qi d } n | S(   së  

    Derive the DisplayType of file from its mimetype.  DisplayType is
    an invented concept that is used _solely_ to decide how to edit
    and view ExternalFiles in the ZMI.  There are three types:

    'ascii'  Editable TTW, viewed in a readonly textarea
    'image'  Not editable TTW, viewed via image tag eg <img src="foo.jpg"/>
    'binary' Not editable TTW, viewed via hyperlink eg <a href="foo.doc"/>

    Generally, the DisplayType is derived by parsing the type from the
    mimetype.  That is,

    'image/jpeg'     -> 'image'
    'text/plain'     -> 'ascii'
    'application/zip -> 'binary'

    In certain circumstances, this is not appropriate.  For example,
    'application/xml' should be 'ascii' rather than 'binary.'
    
    t   /i   t   imaget   textt   asciit   binaryN(   R   t   getR   t   NoneR   R   t   typet   subtype(   R   R+   R   R*   (    (    R   t   getDisplayTypeFromMimeTypem   s     


(   t   __doc__t
   __cvstag__t   __date__t   __version__R    t   os.patht   ost   sysR   R   R   R   R   R"   R,   (   R/   R    R   R"   R   R.   R   R   R3   R,   R   R0   R2   (    (    R   t   ?   s   					