From ad53da5dcedc0825d2b1e8380763b22aadd070d0 Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh Date: Mon, 30 Jul 2012 17:47:25 -0400 Subject: [PATCH] Change package name to webfinger. Closes #4. --- README.rst | 12 ++++++------ setup.py | 10 +++++----- pywebfinger.py => webfinger.py | 14 ++++++++++---- 3 files changed, 21 insertions(+), 15 deletions(-) rename pywebfinger.py => webfinger.py (96%) diff --git a/README.rst b/README.rst index 3730ce5..9e0c07b 100644 --- a/README.rst +++ b/README.rst @@ -1,14 +1,14 @@ -================ -python-webfinger -================ +========= +webfinger +========= Usage ===== Example:: - from pywebfinger import finger - + from webfinger import finger + wf = finger('user@host.com') print wf.profile print wf.hcard @@ -23,7 +23,7 @@ The following relation types are supported: * portable_contacts: http://portablecontacts.net/spec/1.0 * profile: http://webfinger.net/rel/profile-page * xfn: http://gmpg.org/xfn/11 - + Other relation types can be accessed directly from the XRD document.:: print wf.find_link('http://example.com/example/spec', attr='href') diff --git a/setup.py b/setup.py index 1518f11..bef97c5 100644 --- a/setup.py +++ b/setup.py @@ -1,16 +1,16 @@ from distutils.core import setup -from pywebfinger import __version__ +from webfinger import __version__ long_description = open('README.rst').read() -setup(name="python-webfinger", +setup(name="webfinger", version=str(__version__), - py_modules=["pywebfinger"], + py_modules=["webfinger"], description="Simple Python implementation of webfinger client protocol", author="Jeremy Carbaugh", - author_email = "jcarbaugh@gmail.com", + author_email="jcarbaugh@gmail.com", license='BSD', - url="http://github.com/jcarbaugh/python-webfinger/", + url="http://github.com/jcarbaugh/webfinger/", long_description=long_description, install_requires=["python-xrd"], platforms=["any"], diff --git a/pywebfinger.py b/webfinger.py similarity index 96% rename from pywebfinger.py rename to webfinger.py index 787918c..06daf95 100644 --- a/pywebfinger.py +++ b/webfinger.py @@ -1,6 +1,7 @@ -import urllib, urllib2 +import urllib +import urllib2 -__version__ = '0.1' +__version__ = '0.2' RELS = { 'activity_streams': 'http://activitystrea.ms/spec/1.0', @@ -25,9 +26,11 @@ UNOFFICIAL_ENDPOINTS = { 'twitter.com': 'twitter-webfinger.appspot.com', } + class WebFingerException(Exception): pass + class WebFingerResponse(object): def __init__(self, xrd, insecure): @@ -39,13 +42,14 @@ class WebFingerResponse(object): return self._xrd.find_link(RELS[name], attr='href') return getattr(self._xrd, name) + class WebFingerClient(object): def __init__(self, host, timeout=None, official=False): self._host = host self._official = official self._opener = urllib2.build_opener(urllib2.HTTPRedirectHandler()) - self._opener.addheaders = [('User-agent', 'python-webfinger')] + self._opener.addheaders = [('User-agent', 'github.com/jcarbaugh/webfinger')] self._timeout = timeout @@ -62,7 +66,7 @@ class WebFingerClient(object): conn = self._opener.open(url, timeout=self._timeout) response = conn.read() conn.close() - + return response if raw else XRD.parse(response) def hostmeta(self, protocol): @@ -95,6 +99,7 @@ class WebFingerClient(object): data = self.xrd(xrd_url) return WebFingerResponse(data, insecure) + def finger(identifier, timeout=None, official=False): if identifier.startswith('acct:'): (acct, identifier) = identifier.split(':', 1) @@ -102,6 +107,7 @@ def finger(identifier, timeout=None, official=False): client = WebFingerClient(host, timeout=timeout, official=official) return client.finger(username) + if __name__ == '__main__': # example usage