Increased version to 1.0-post
[0publish/0publish-limyreth.git] / mimetypes.py
blob9ced462d6120a61dc01e966b2b482cf74552cabc
1 from xml.dom import minidom
2 from zeroinstall.injector import namespaces
4 def add_types(data):
5 doc = minidom.parseString(data)
7 changed = False
8 for archive in doc.documentElement.getElementsByTagNameNS(namespaces.XMLNS_IFACE, 'archive'):
9 href = archive.getAttribute('href')
10 type = archive.getAttribute('type')
12 if not type:
13 if href.endswith('.tar.bz2'):
14 type = "application/x-bzip-compressed-tar"
15 elif href.endswith('.tgz') or href.endswith('.tar.gz'):
16 type = "application/x-compressed-tar"
17 else:
18 raise Exception("Can't guess type for " + href)
19 archive.setAttribute('type', type)
20 changed = True
22 if changed:
23 return doc.toxml()
24 else:
25 return data