~percona-dev/percona-server/release-5.1.59-13.0

« back to all changes in this revision

Viewing changes to python-for-subunit2junitxml/testtools/content_type.py

  • Committer: Stewart Smith
  • Date: 2011-10-06 06:45:16 UTC
  • Revision ID: stewart@flamingspork.com-20111006064516-rrjg17x7wwn9vr6w
add subunit support to mtr

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2009-2010 testtools developers. See LICENSE for details.
 
2
 
 
3
"""ContentType - a MIME Content Type."""
 
4
 
 
5
 
 
6
class ContentType(object):
 
7
    """A content type from http://www.iana.org/assignments/media-types/
 
8
 
 
9
    :ivar type: The primary type, e.g. "text" or "application"
 
10
    :ivar subtype: The subtype, e.g. "plain" or "octet-stream"
 
11
    :ivar parameters: A dict of additional parameters specific to the
 
12
        content type.
 
13
    """
 
14
 
 
15
    def __init__(self, primary_type, sub_type, parameters=None):
 
16
        """Create a ContentType."""
 
17
        if None in (primary_type, sub_type):
 
18
            raise ValueError("None not permitted in %r, %r" % (
 
19
                primary_type, sub_type))
 
20
        self.type = primary_type
 
21
        self.subtype = sub_type
 
22
        self.parameters = parameters or {}
 
23
 
 
24
    def __eq__(self, other):
 
25
        if type(other) != ContentType:
 
26
            return False
 
27
        return self.__dict__ == other.__dict__
 
28
 
 
29
    def __repr__(self):
 
30
        return "%s/%s params=%s" % (self.type, self.subtype, self.parameters)
 
31
 
 
32
 
 
33
UTF8_TEXT = ContentType('text', 'plain', {'charset': 'utf8'})