wafsamba: use additional xml catalog file (bug #9512)
[Samba/gebeck_regimport.git] / lib / testtools / testtools / content_type.py
blobc4914088cd73136dbe7fd57c1155d5cd2c5276cb
1 # Copyright (c) 2009-2012 testtools developers. See LICENSE for details.
3 """ContentType - a MIME Content Type."""
6 class ContentType(object):
7 """A content type from http://www.iana.org/assignments/media-types/
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 """
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 {}
24 def __eq__(self, other):
25 if type(other) != ContentType:
26 return False
27 return self.__dict__ == other.__dict__
29 def __repr__(self):
30 if self.parameters:
31 params = '; '
32 params += ', '.join(
33 sorted('%s="%s"' % (k, v) for k, v in self.parameters.items()))
34 else:
35 params = ''
36 return "%s/%s%s" % (self.type, self.subtype, params)
39 JSON = ContentType('application', 'json')
41 UTF8_TEXT = ContentType('text', 'plain', {'charset': 'utf8'})