kopia lustrzana https://github.com/jcarbaugh/python-webfinger
Add default return objects to property methods
rodzic
d348184611
commit
880fd5f240
16
webfinger.py
16
webfinger.py
|
@ -50,15 +50,15 @@ class WebFingerResponse(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def aliases(self):
|
def aliases(self):
|
||||||
return self.jrd.get('aliases')
|
return self.jrd.get('aliases', [])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def properties(self):
|
def properties(self):
|
||||||
return self.jrd.get('properties')
|
return self.jrd.get('properties', {})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def links(self):
|
def links(self):
|
||||||
return self.jrd.get('links')
|
return self.jrd.get('links', [])
|
||||||
|
|
||||||
def rel(self, relation, attr='href'):
|
def rel(self, relation, attr='href'):
|
||||||
links = self.links
|
links = self.links
|
||||||
|
@ -76,7 +76,8 @@ class WebFingerClient(object):
|
||||||
|
|
||||||
def jrd(self, host, resource, rel, raw=False):
|
def jrd(self, host, resource, rel, raw=False):
|
||||||
""" Load resource at given URL and attempt to parse either XRD or JRD
|
""" Load resource at given URL and attempt to parse either XRD or JRD
|
||||||
based on HTTP response Content-Type header.
|
based on HTTP response Content-Type header. The rel parameter
|
||||||
|
may be a single value or a list.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
url = "https://%s/.well-known/webfinger" % host
|
url = "https://%s/.well-known/webfinger" % host
|
||||||
|
@ -91,19 +92,16 @@ class WebFingerClient(object):
|
||||||
params['rel'] = rel
|
params['rel'] = rel
|
||||||
|
|
||||||
resp = requests.get(url, params=params, headers=headers, timeout=self.timeout, verify=True)
|
resp = requests.get(url, params=params, headers=headers, timeout=self.timeout, verify=True)
|
||||||
|
|
||||||
logging.debug('fetching JRD from %s' % resp.url)
|
logging.debug('fetching JRD from %s' % resp.url)
|
||||||
|
|
||||||
content = resp.content
|
|
||||||
content_type = resp.headers.get('Content-Type', '').split(';', 1)[0].strip()
|
content_type = resp.headers.get('Content-Type', '').split(';', 1)[0].strip()
|
||||||
|
|
||||||
logging.debug('response content type: %s' % content_type)
|
logging.debug('response content type: %s' % content_type)
|
||||||
|
|
||||||
if content_type != WEBFINGER_TYPE and content_type not in LEGACY_WEBFINGER_TYPES:
|
if content_type != WEBFINGER_TYPE and content_type not in LEGACY_WEBFINGER_TYPES:
|
||||||
raise WebFingerException('Invalid response type from server')
|
raise WebFingerException('Invalid response type from server')
|
||||||
|
|
||||||
if raw:
|
if raw:
|
||||||
return content
|
return resp.content
|
||||||
|
|
||||||
return resp.json()
|
return resp.json()
|
||||||
|
|
||||||
|
@ -151,6 +149,8 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
wf = finger(args.acct, rel=args.rel)
|
wf = finger(args.acct, rel=args.rel)
|
||||||
|
|
||||||
|
print "--- %s ---" % wf.subject
|
||||||
|
|
||||||
if args.rel:
|
if args.rel:
|
||||||
|
|
||||||
link = wf.find_link(args.rel)
|
link = wf.find_link(args.rel)
|
||||||
|
|
Ładowanie…
Reference in New Issue