예제 #1
0
파일: profile.py 프로젝트: cdent/py-ostatus
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
예제 #2
0
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)
예제 #3
0
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
예제 #4
0
파일: hcard.py 프로젝트: carbans/py-ostatus
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
예제 #5
0
def get_host_meta(host):
    """Ping a host for its host-meta file."""
    url = 'http://%s/.well-known/host-meta' % host
    return fetch(url)
예제 #6
0
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')
예제 #7
0
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')