File: coral_cdn_filter.py

package info (click to toggle)
planet-venus 0~bzr95-2%2Blenny1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,616 kB
  • ctags: 1,981
  • sloc: python: 14,776; xml: 821; makefile: 36; sed: 3
file content (18 lines) | stat: -rw-r--r-- 610 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""
Remap all images to take advantage of the Coral Content Distribution
Network <http://www.coralcdn.org/>.
"""

import re, sys, urlparse, xml.dom.minidom

entry = xml.dom.minidom.parse(sys.stdin).documentElement

for node in entry.getElementsByTagName('img'):
    if node.hasAttribute('src'):
        component = list(urlparse.urlparse(node.getAttribute('src')))
        if component[0] == 'http':
            component[1] = re.sub(r':(\d+)$', r'.\1', component[1])
            component[1] += '.nyud.net:8080'
            node.setAttribute('src', urlparse.urlunparse(component))

print entry.toxml('utf-8')