The mailcap Module

The mailcap module in Example 6-7 contains code that deals with mailcap files, which contain information on how to handle different document formats (on Unix platforms).

Example 6-7. Using the mailcap Module to Get a Capability Dictionary

File: mailcap-example-1.py

import mailcap

caps = mailcap.getcaps()

for k, v in caps.items():
 print k, "=", v

image/* = [{'view': 'pilview'}]
application/postscript = [{'view': 'ghostview'}]

In Example 6-7, the system uses pilview for all kinds of images, and ghostscript viewer for PostScript documents. Example 6-8 shows how to find a viewer using mailcap.

Example 6-8. Using the mailcap Module to Find a Viewer

File: mailcap-example-2.py

import mailcap

caps = mailcap.getcaps()

command, info = mailcap.findmatch(
 caps, "image/jpeg", "view", "samples/sample.jpg"
 )

print command

pilview samples/sample.jpg

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols

Internationalization

Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules



Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net