API Reference

zope.mimetype.interfaces

interfaces for mimetype package

interface ICharset[source]

Information about a charset

encoding

Encoding

The id of the encoding used for this charset.

name

Name

The charset name. This is what is used for the ‘charset’ parameter in content-type headers.

interface ICharsetCodec[source]

Marker interface for locating the codec for a given charset.

interface ICharsetGetter[source]

A utility that looks up a character set (charset).

__call__(name=None, data=None, content_type=None)

Look up a charset.

If a charset cannot be determined based on the input, this returns None.

interface ICodec[source]

Information about a codec.

name

Name

The name of the Python codec.

title

Title

The human-readable name of this codec.

writer(stream, errors='strict')

Construct a StramWriter object for this codec.

decode(input, errors='strict')

Decodes the input and returns a tuple (output, length consumed).

reader(stream, errors='strict')

Construct a StreamReader object for this codec.

encode(input, errors='strict')

Encodes the input and returns a tuple (output, length consumed).

interface ICodecPreferredCharset[source]

Marker interface for locating the preferred charset for a Codec.

interface ICodecSource[source]

Extends: zope.schema.interfaces.IIterableSource

Source for codecs.

interface ICodecTerm[source]

Extends: zope.schema.interfaces.ITitledTokenizedTerm

Extended term that describes a content type interface.

preferredCharset

Preferred Charset

Charset that should be used to represent the codec

interface IContentInfo[source]

Interface describing effective MIME type information.

When using MIME data from an object, an application should adapt the object to this interface to determine how it should be interpreted. This may be different from the information

getCodec()

Return an ICodec that should be used to decode/encode data.

This should return None if the object’s IContentType interface does not derive from IContentTypeEncoded.

If the content type is encoded and no encoding information is available in the effectiveParameters, this method may return None, or may provide a codec based on application policy.

If effectiveParameters indicates a specific charset, and no codec is registered to support that charset, ValueError will be raised.

contentType

Content type

The value of the Content-Type header, including both the MIME type and any parameters.

effectiveMimeType

Effective MIME type

MIME type that should be reported when downloading the document this IContentInfo object is for.

decode(s)

Return the decoding of s based on the effective encoding.

The effective encoding is determined by the return from the getCodec() method.

ValueError is raised if no codec can be found for the effective charset.

effectiveParameters

Effective parameters

Content-Type parameters that should be reported when downloading the document this IContentInfo object is for.

interface IContentType[source]

Marker interface for objects that represent content with a MIME type.

interface IContentTypeAware[source]

Interface for MIME content type information.

Objects that can provide content type information about the data they contain, such as file objects, should be adaptable to this interface.

mimeType

Mime Type

The mime type explicitly specified for the object that this MIME information describes, if any. May be None, or an ASCII MIME type string of the form major/minor.

parameters

Mime Type Parameters

The MIME type parameters (such as charset).

interface IContentTypeChangedEvent[source]

Extends: zope.interface.interfaces.IObjectEvent

The content type for an object has changed.

All changes of the IContentTypeInterface for an object are reported by this event, including the setting of an initial content type and the removal of the content type interface.

This event should only be used if the content type actually changes.

oldContentType

Content type interface before the change, if any, or None.

newContentType

Content type interface after the change, if any, or None.

interface IContentTypeEncoded[source]

Extends: zope.mimetype.interfaces.IContentType

Marker interface for content types that care about encoding.

This does not imply that encoding information is known for a specific object.

Content types that derive from IContentTypeEncoded support a content type parameter named ‘charset’, and that parameter is used to control encoding and decoding of the text.

For example, interfaces for text/* content types all derive from this base interface.

interface IContentTypeInterface[source]

Interface that describes a logical mime type.

Interfaces that provide this interfaces are content-type interfaces.

Most MIME types are described by the IANA MIME-type registry (http://www.iana.org/assignments/media-types/).

interface IContentTypeSource[source]

Extends: zope.schema.interfaces.ISource, zope.schema.interfaces.IIterableSource

Source for content types.

interface IContentTypeTerm[source]

Extends: zope.schema.interfaces.ITitledTokenizedTerm

Extended term that describes a content type interface.

mimeTypes

MIME types

List of MIME types represented by this interface; the first should be considered the preferred MIME type.

extensions

Extensions

Filename extensions commonly associated with this type of file.

interface IMimeTypeGetter[source]

A utility that looks up a MIME type string.

__call__(name=None, data=None, content_type=None)

Look up a MIME type.

If a MIME type cannot be determined based on the input, this returns None.

Parameters:data (bytes) – If given, the bytes data to get a MIME type for. This may be examined for clues about the type.
mimeTypeConstraint(value)[source]

Return True iff value is a syntactically legal MIME type.

tokenConstraint(value)[source]

Return True iff value is a syntactically legal RFC 2045 token.

zope.mimetype.codec

zope.mimetype.contentinfo

Default IContentInfo implementation.

class ContentInfo(context)[source]

Bases: object

Basic IContentInfo that provides information from an IContentTypeAware.

zope.mimetype.event

Implementation of and support for the IContentTypeChangedEvent.

changeContentType(object, newContentType)[source]

Set the content type interface for the object.

If this represents a change, an IContentTypeChangedEvent will be fired.

zope.mimetype.i18n

I18N support for the zope.mime package.

This defines a MessageFactory for the I18N domain for the zope.mimetype package. This is normally used with this import:

from i18n import MessageFactory as _

The factory is then used normally. Two examples:

text = _('some internationalized text')
text = _('helpful-descriptive-message-id', 'default text')

zope.mimetype.mtypes

Mime-Types management

zope.mimetype.source

Sources for IContentTypeInterface providers and codecs.

class CodecSource[source]

Bases: zope.mimetype.source.UtilitySource

Source of ICodec providers.

class CodecTerms(source, request)[source]

Bases: zope.mimetype.source.Terms

Utility to provide terms for codecs.

class ContentTypeSource[source]

Bases: zope.mimetype.source.UtilitySource

Source of IContentTypeInterface providers.

class ContentTypeTerms(source, request)[source]

Bases: zope.mimetype.source.Terms

Utility to provide terms for content type interfaces.

class Terms(source, request)[source]

Bases: object

Utility to provide terms for content type interfaces.

class UtilitySource[source]

Bases: object

Source of utilities providing a specific interface.

zope.mimetype.typegetter

charsetGetter(name=None, data=None, content_type=None)[source]

Default implementation of zope.mimetype.interfaces.ICharsetGetter.

mimeTypeGetter(name=None, data=None, content_type=None)[source]

A minimal extractor that never attempts to guess.

mimeTypeGuesser(name=None, data=None, content_type=None)[source]

An extractor that tries to guess the content type based on the name and data if the input contains no content type information.

smartMimeTypeGuesser(name=None, data=None, content_type=None)[source]

An extractor that checks the content for a variety of constructs to try and refine the results of the mimeTypeGuesser(). This is able to do things like check for XHTML that’s labelled as HTML in upload data.

zope.mimetype.utils

Utility helpers

decode(s, charset_name)[source]

given a string and a IANA character set name, decode string to unicode

zope.mimetype.widget

Widget that provides translation and sorting for an IIterableSource.

This widget translates the term titles and presents those in sorted order.

Properly, this should call on a language-specific collation routine, but we don’t currently have those. Also, it would need to deal with a partially-translated list of titles when translations are only available for some of the titles.

The implementation ignores these issues for now.

class TranslatableSourceDropdownWidget(field, source, request)[source]

Bases: zope.mimetype.widget.TranslatableSourceSelectWidget

class TranslatableSourceSelectWidget(field, source, request)[source]

Bases: zope.formlib.source.SourceSelectWidget

renderItemsWithValues(values)[source]

Render the list of possible values, with those found in values being marked as selected.

textForValue(term)[source]

Extract a string from the term.

The term must be a vocabulary tokenized term.

This can be overridden to support more complex term objects. The token is returned here since it’s the only thing known to be a string, or str()able.

zope.mimetype.zcml

interface ICharsetDirective[source]

Defines a charset in a codec.

Example:

<charset name="iso8859-1" preferred="True" />
<charset name="latin1" />
preferred

Preferred

Is this is the preferred charset for the encoding.

name

Name

The name of the Python codec.

interface ICodecDirective[source]

Defines a codec.

Example:

<zope:codec name="iso8859-1" title="Western (ISO-8859-1)">
   ...
</zope:codec>
title

Title

The human-readable name for this codec.

name

Name

The name of the Python codec.

interface IMimeTypesDirective[source]

Request loading of a MIME type definition table.

Example:

<zope:mimeDefinitions file='types.csv'/>
module

Module

Module which contains the interfaces referenced from the CSV file.

file

File

Path of the CSV file to load registrations from.