kopia lustrzana https://github.com/jcarbaugh/python-webfinger
leave scheme up to the user
rodzic
60713e1def
commit
0cfbc04cf9
17
webfinger.py
17
webfinger.py
|
@ -107,8 +107,8 @@ class WebFingerClient(object):
|
||||||
content = resp.content
|
content = resp.content
|
||||||
return content if raw else rd.loads(content, resp.headers.get('Content-Type'))
|
return content if raw else rd.loads(content, resp.headers.get('Content-Type'))
|
||||||
|
|
||||||
def finger(self, username, resource=None, rel=None):
|
def finger(self, subject, resource=None, rel=None):
|
||||||
""" Perform a WebFinger query based on the given username.
|
""" Perform a WebFinger query based on the given subject.
|
||||||
The `rel` parameter, if specified, will be passed to the provider,
|
The `rel` parameter, if specified, will be passed to the provider,
|
||||||
but be aware that providers are not required to implement the
|
but be aware that providers are not required to implement the
|
||||||
rel filter.
|
rel filter.
|
||||||
|
@ -137,24 +137,23 @@ class WebFingerClient(object):
|
||||||
template = hm.find_link(WEBFINGER_TYPES, attr='template')
|
template = hm.find_link(WEBFINGER_TYPES, attr='template')
|
||||||
secure = template.startswith('https://')
|
secure = template.startswith('https://')
|
||||||
|
|
||||||
url = template.replace('{uri}',
|
url = template.replace('{uri}', urllib.quote_plus(subject))
|
||||||
urllib.quote_plus('acct:%s@%s' % (username, self._host)))
|
|
||||||
|
|
||||||
lrdd = self.rd(url)
|
lrdd = self.rd(url)
|
||||||
return WebFingerResponse(lrdd, secure)
|
return WebFingerResponse(lrdd, secure)
|
||||||
|
|
||||||
|
|
||||||
def finger(identifier, resource=None, rel=None, timeout=None, official=False):
|
def finger(subject, resource=None, rel=None, timeout=None, official=False):
|
||||||
""" Shortcut method for invoking WebFingerClient.
|
""" Shortcut method for invoking WebFingerClient.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if ":" in identifier:
|
if ":" not in subject:
|
||||||
(scheme, identifier) = identifier.split(':', 1)
|
raise WebFingerException("scheme is required in subject URI")
|
||||||
|
|
||||||
(username, host) = identifier.split('@')
|
(identifier, host) = subject.split('@')
|
||||||
|
|
||||||
client = WebFingerClient(host, timeout=timeout, official=official)
|
client = WebFingerClient(host, timeout=timeout, official=official)
|
||||||
return client.finger(username, resource=resource, rel=rel)
|
return client.finger(subject, resource=resource, rel=rel)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Ładowanie…
Reference in New Issue