kopia lustrzana https://github.com/jcarbaugh/python-webfinger
Change package name to webfinger. Closes #4.
rodzic
c57f388b20
commit
ad53da5dce
12
README.rst
12
README.rst
|
@ -1,14 +1,14 @@
|
||||||
================
|
=========
|
||||||
python-webfinger
|
webfinger
|
||||||
================
|
=========
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
from pywebfinger import finger
|
from webfinger import finger
|
||||||
|
|
||||||
wf = finger('user@host.com')
|
wf = finger('user@host.com')
|
||||||
print wf.profile
|
print wf.profile
|
||||||
print wf.hcard
|
print wf.hcard
|
||||||
|
@ -23,7 +23,7 @@ The following relation types are supported:
|
||||||
* portable_contacts: http://portablecontacts.net/spec/1.0
|
* portable_contacts: http://portablecontacts.net/spec/1.0
|
||||||
* profile: http://webfinger.net/rel/profile-page
|
* profile: http://webfinger.net/rel/profile-page
|
||||||
* xfn: http://gmpg.org/xfn/11
|
* xfn: http://gmpg.org/xfn/11
|
||||||
|
|
||||||
Other relation types can be accessed directly from the XRD document.::
|
Other relation types can be accessed directly from the XRD document.::
|
||||||
|
|
||||||
print wf.find_link('http://example.com/example/spec', attr='href')
|
print wf.find_link('http://example.com/example/spec', attr='href')
|
||||||
|
|
10
setup.py
10
setup.py
|
@ -1,16 +1,16 @@
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
from pywebfinger import __version__
|
from webfinger import __version__
|
||||||
|
|
||||||
long_description = open('README.rst').read()
|
long_description = open('README.rst').read()
|
||||||
|
|
||||||
setup(name="python-webfinger",
|
setup(name="webfinger",
|
||||||
version=str(__version__),
|
version=str(__version__),
|
||||||
py_modules=["pywebfinger"],
|
py_modules=["webfinger"],
|
||||||
description="Simple Python implementation of webfinger client protocol",
|
description="Simple Python implementation of webfinger client protocol",
|
||||||
author="Jeremy Carbaugh",
|
author="Jeremy Carbaugh",
|
||||||
author_email = "jcarbaugh@gmail.com",
|
author_email="jcarbaugh@gmail.com",
|
||||||
license='BSD',
|
license='BSD',
|
||||||
url="http://github.com/jcarbaugh/python-webfinger/",
|
url="http://github.com/jcarbaugh/webfinger/",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
install_requires=["python-xrd"],
|
install_requires=["python-xrd"],
|
||||||
platforms=["any"],
|
platforms=["any"],
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import urllib, urllib2
|
import urllib
|
||||||
|
import urllib2
|
||||||
|
|
||||||
__version__ = '0.1'
|
__version__ = '0.2'
|
||||||
|
|
||||||
RELS = {
|
RELS = {
|
||||||
'activity_streams': 'http://activitystrea.ms/spec/1.0',
|
'activity_streams': 'http://activitystrea.ms/spec/1.0',
|
||||||
|
@ -25,9 +26,11 @@ UNOFFICIAL_ENDPOINTS = {
|
||||||
'twitter.com': 'twitter-webfinger.appspot.com',
|
'twitter.com': 'twitter-webfinger.appspot.com',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class WebFingerException(Exception):
|
class WebFingerException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class WebFingerResponse(object):
|
class WebFingerResponse(object):
|
||||||
|
|
||||||
def __init__(self, xrd, insecure):
|
def __init__(self, xrd, insecure):
|
||||||
|
@ -39,13 +42,14 @@ class WebFingerResponse(object):
|
||||||
return self._xrd.find_link(RELS[name], attr='href')
|
return self._xrd.find_link(RELS[name], attr='href')
|
||||||
return getattr(self._xrd, name)
|
return getattr(self._xrd, name)
|
||||||
|
|
||||||
|
|
||||||
class WebFingerClient(object):
|
class WebFingerClient(object):
|
||||||
|
|
||||||
def __init__(self, host, timeout=None, official=False):
|
def __init__(self, host, timeout=None, official=False):
|
||||||
self._host = host
|
self._host = host
|
||||||
self._official = official
|
self._official = official
|
||||||
self._opener = urllib2.build_opener(urllib2.HTTPRedirectHandler())
|
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
|
self._timeout = timeout
|
||||||
|
|
||||||
|
@ -62,7 +66,7 @@ class WebFingerClient(object):
|
||||||
conn = self._opener.open(url, timeout=self._timeout)
|
conn = self._opener.open(url, timeout=self._timeout)
|
||||||
response = conn.read()
|
response = conn.read()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
return response if raw else XRD.parse(response)
|
return response if raw else XRD.parse(response)
|
||||||
|
|
||||||
def hostmeta(self, protocol):
|
def hostmeta(self, protocol):
|
||||||
|
@ -95,6 +99,7 @@ class WebFingerClient(object):
|
||||||
data = self.xrd(xrd_url)
|
data = self.xrd(xrd_url)
|
||||||
return WebFingerResponse(data, insecure)
|
return WebFingerResponse(data, insecure)
|
||||||
|
|
||||||
|
|
||||||
def finger(identifier, timeout=None, official=False):
|
def finger(identifier, timeout=None, official=False):
|
||||||
if identifier.startswith('acct:'):
|
if identifier.startswith('acct:'):
|
||||||
(acct, identifier) = identifier.split(':', 1)
|
(acct, identifier) = identifier.split(':', 1)
|
||||||
|
@ -102,6 +107,7 @@ def finger(identifier, timeout=None, official=False):
|
||||||
client = WebFingerClient(host, timeout=timeout, official=official)
|
client = WebFingerClient(host, timeout=timeout, official=official)
|
||||||
return client.finger(username)
|
return client.finger(username)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
# example usage
|
# example usage
|
Ładowanie…
Reference in New Issue