def parse_diaspora_webfinger(document):
webfinger = {<EOL>"<STR_LIT>": None,<EOL>}<EOL>try:<EOL><INDENT>doc = json.loads(document)<EOL>for link in doc["<STR_LIT>"]:<EOL><INDENT>if link["<STR_LIT>"] == "<STR_LIT>":<EOL><INDENT>webfinger["<STR_LIT>"] = link["<STR_LIT>"]<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.warning("<STR_LIT>")<EOL>raise ValueError<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>try:<EOL><INDENT>xrd = XRD.parse_xrd(document)<EOL>webfinger["<STR_LIT>"] = xrd.find_link(rels="<STR_LIT>").href<EOL><DEDENT>except xml.parsers.expat.ExpatError:<EOL><INDENT>logger.warning("<STR_LIT>")<EOL>pass<EOL><DEDENT><DEDENT>return webfinger<EOL>
Parse Diaspora webfinger which is either in JSON format (new) or XRD (old).

https://diaspora.github.io/diaspora_federation/discovery/webfinger.html