1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 For references, see docstring in mediagoblin/webfinger/__init__.py
22 from urlparse
import urlparse
24 from mediagoblin
.tools
.response
import render_to_response
, render_404
26 def host_meta(request
):
31 placeholder
= 'MG_LRDD_PLACEHOLDER'
33 lrdd_title
= 'GNU MediaGoblin - User lookup'
35 lrdd_template
= request
.urlgen(
36 'mediagoblin.webfinger.xrd',
40 return render_to_response(
42 'mediagoblin/webfinger/host-meta.xml',
44 'lrdd_template': lrdd_template
,
45 'lrdd_title': lrdd_title
,
46 'placeholder': placeholder
})
48 MATCH_SCHEME_PATTERN
= re
.compile(r
'^acct:')
52 Find user data based on a webfinger URI
54 param_uri
= request
.GET
.get('uri')
57 return render_404(request
)
60 :py:module:`urlparse` does not recognize usernames in URIs of the
61 form ``acct:user@example.org`` or ``user@example.org``.
63 if not MATCH_SCHEME_PATTERN
.search(param_uri
):
64 # Assume the URI is in the form ``user@example.org``
65 uri
= 'acct://' + param_uri
67 # Assumes the URI looks like ``acct:user@example.org
68 uri
= MATCH_SCHEME_PATTERN
.sub(
71 parsed
= urlparse(uri
)
73 xrd_subject
= param_uri
75 # TODO: Verify that the user exists
76 # Q: Does webfinger support error handling in this case?
77 # Returning 404 seems intuitive, need to check.
80 # TODO: Fetch from database instead of using the MockUser
82 user
.username
= parsed
.username
86 'rel': 'http://microformats.org/profile/hcard',
87 'href': request
.urlgen(
88 'mediagoblin.user_pages.user_home',
92 'rel': 'http://schemas.google.com/g/2010#updates-from',
93 'href': request
.urlgen(
94 'mediagoblin.user_pages.atom_feed',
98 xrd_alias
= request
.urlgen(
99 'mediagoblin.user_pages.user_home',
103 return render_to_response(
105 'mediagoblin/webfinger/xrd.xml',
107 'subject': xrd_subject
,
109 'links': xrd_links
})
111 return render_404(request
)
113 class MockUser(object):
115 TEMPORARY user object