#!/usr/bin/env python # encoding: utf-8 import urllib import re from xml.etree import ElementTree from xml.parsers.expat import ExpatError import htmlentitydefs _UNESCAPE = re.compile(ur'&\w+?;', re.UNICODE) def unescape(s): if s is None: return "" def fixup(m): ent = m.group(0)[1:-1] print ent return unichr(htmlentitydefs.name2codepoint[ent]) try: return _UNESCAPE.sub(fixup,s.decode("utf-8")).encode("utf-8") except: print s.decode("utf-8") def parse_content(c): try: data = ElementTree.fromstring(c)[0] rv = {} for k,v in zip(data[::2], data[1::2]): rv[k.text] = unescape(v.text) return rv except ExpatError: print " Syntax Error" return None def fetch_snippets(name): base_url = "http://svn.textmate.org/trunk/Bundles/" + name + ".tmbundle/" snippet_idx = base_url + "Snippets/" idx_list = urllib.urlopen(snippet_idx).read() rv = [] for link in re.findall("