def profile(identifier): """ Given a webfinger address, find the profile page, and fetch that. """ links = finger(identifier) profile_data = None for link in links: if link['rel'] == PROFILE: profile_data = fetch(link['href']) break if not profile_data: raise ProfileError('no links found to get profile') else: return profile_data
def status(identifier): """ Get the latest update from a webfinger address. """ links = finger(identifier) feed = None for link in links: if link['rel'] == UPDATES_FROM: feed = fetch(link['href']) break if not feed: raise StatusError('no links found to get status') else: entries = parse_feed(feed) if entries: return entries[0] else: raise StatusError('no data for %s' % identifier)
def hcard(identifier): """ Find the first hcard in a URI and parse it to usefulness. """ links = finger(identifier) hcard_uri = None for link in links: if link['rel'] == HCARD: data = fetch(link['href']) break if not data: raise HcardError('no links to get data') body = (minidom.parseString(data).documentElement.getElementsByTagName( 'body')[0]) vcard = _traverse_for_class(body, 'vcard', None) data = _traverse_for_data(vcard, HCARD_ELEMENTS) return data
def hcard(identifier): """ Find the first hcard in a URI and parse it to usefulness. """ links = finger(identifier) hcard_uri = None for link in links: if link['rel'] == HCARD: data = fetch(link['href']) break if not data: raise HcardError('no links to get data') body = (minidom.parseString(data).documentElement .getElementsByTagName('body')[0]) vcard = _traverse_for_class(body, 'vcard', None) data = _traverse_for_data(vcard, HCARD_ELEMENTS) return data
def get_host_meta(host): """Ping a host for its host-meta file.""" url = 'http://%s/.well-known/host-meta' % host return fetch(url)
def _finger(uri): """Actual implementation of finger, now that we know where to look""" content = fetch(uri, headers={'Accept': 'application/xrd+xml'}) doc = minidom.parseString(content).documentElement return doc.getElementsByTagName('Link')
def _finger(uri): """Actual implementation of finger, now that we know where to look""" content = fetch(uri) doc = minidom.parseString(content).documentElement return doc.getElementsByTagName('Link')