# Path: federation/hostmeta/django/generators.py
# def rfc7033_webfinger_view(request, *args, **kwargs):
#     """
#     Django view to generate an RFC7033 webfinger.
#     """
#     resource = request.GET.get("resource")
#     if not resource:
#         return HttpResponseBadRequest("No resource found")
#     if not resource.startswith("acct:"):
#         return HttpResponseBadRequest("Invalid resource")
#     handle = resource.replace("acct:", "").lower()
#     logger.debug(f"{handle} requested with {request}")
#     profile_func = get_function_from_config("get_profile_function")
# 
#     try:
#         profile = profile_func(handle=handle, request=request)
#     except Exception as exc:
#         logger.warning("rfc7033_webfinger_view - Failed to get profile by handle %s: %s", handle, exc)
#         return HttpResponseNotFound()
# 
#     config = get_configuration()
#     webfinger = RFC7033Webfinger(
#         id=profile.id,
#         handle=profile.handle,
#         guid=profile.guid,
#         base_url=config.get('base_url'),
#         profile_path=get_path_from_url(profile.url),
#         hcard_path=config.get('hcard_path'),
#         atom_path=get_path_from_url(profile.atom_url),
#         search_path=config.get('search_path'),
#     )
# 
#     return JsonResponse(
#         webfinger.render(),
#         content_type="application/jrd+json",
#     )
# 
# Path: federation/hostmeta/django/generators.py
# def nodeinfo2_view(request, *args, **kwargs):
#     try:
#         nodeinfo2_func = get_function_from_config("nodeinfo2_function")
#     except AttributeError:
#         return HttpResponseBadRequest("Not configured")
#     nodeinfo2 = nodeinfo2_func()
# 
#     return JsonResponse(generate_nodeinfo2_document(**nodeinfo2))
# 
# def matrix_client_wellknown_view(request, *args, **kwargs):
#     try:
#         matrix_config_func = get_function_from_config("matrix_config_function")
#     except AttributeError:
#         return HttpResponseBadRequest("Not configured")
#     matrix_config = matrix_config_func()
# 
#     wellknown = MatrixClientWellKnown(
#         homeserver_base_url=matrix_config["homeserver_base_url"],
#         identity_server_base_url=matrix_config.get("identity_server_base_url"),
#         other_keys=matrix_config.get("client_wellknown_other_keys"),
#     )
#     return JsonResponse(wellknown.render())
# 
# def matrix_server_wellknown_view(request, *args, **kwargs):
#     try:
#         matrix_config_func = get_function_from_config("matrix_config_function")
#     except AttributeError:
#         return HttpResponseBadRequest("Not configured")
#     matrix_config = matrix_config_func()
# 
#     wellknown = MatrixServerWellKnown(
#         homeserver_domain_with_port=matrix_config["homeserver_domain_with_port"],
#     )
#     return JsonResponse(wellknown.render())


from django.conf.urls import url
from federation.hostmeta.django import rfc7033_webfinger_view
from federation.hostmeta.django.generators import (
    nodeinfo2_view, matrix_client_wellknown_view, matrix_server_wellknown_view,
)
# noinspection PyPackageRequirements


urlpatterns = [
    url(r'^.well-known/matrix/client$', matrix_client_wellknown_view, name="matrix-client-wellknown"),
    url(r'^.well-known/matrix/server$', matrix_server_wellknown_view, name="matrix-server-wellknown"),
    url(r'^.well-known/webfinger$', rfc7033_webfinger_view, name="rfc7033-webfinger"),
    url(r'^.well-known/x-nodeinfo2$', nodeinfo2_view, name="nodeinfo2"),

# Path: federation/hostmeta/django/generators.py
# def rfc7033_webfinger_view(request, *args, **kwargs):
#     """
#     Django view to generate an RFC7033 webfinger.
#     """
#     resource = request.GET.get("resource")
#     if not resource:
#         return HttpResponseBadRequest("No resource found")
#     if not resource.startswith("acct:"):
#         return HttpResponseBadRequest("Invalid resource")
#     handle = resource.replace("acct:", "").lower()
#     logger.debug(f"{handle} requested with {request}")
#     profile_func = get_function_from_config("get_profile_function")
# 
#     try:
#         profile = profile_func(handle=handle, request=request)
#     except Exception as exc:
#         logger.warning("rfc7033_webfinger_view - Failed to get profile by handle %s: %s", handle, exc)
#         return HttpResponseNotFound()
# 
#     config = get_configuration()
#     webfinger = RFC7033Webfinger(
#         id=profile.id,
#         handle=profile.handle,
#         guid=profile.guid,
#         base_url=config.get('base_url'),
#         profile_path=get_path_from_url(profile.url),
#         hcard_path=config.get('hcard_path'),
#         atom_path=get_path_from_url(profile.atom_url),
#         search_path=config.get('search_path'),
#     )
# 
#     return JsonResponse(
#         webfinger.render(),
#         content_type="application/jrd+json",
#     )
# 
# Path: federation/hostmeta/django/generators.py
# def nodeinfo2_view(request, *args, **kwargs):
#     try:
#         nodeinfo2_func = get_function_from_config("nodeinfo2_function")
#     except AttributeError:
#         return HttpResponseBadRequest("Not configured")
#     nodeinfo2 = nodeinfo2_func()
# 
#     return JsonResponse(generate_nodeinfo2_document(**nodeinfo2))
# 
# def matrix_client_wellknown_view(request, *args, **kwargs):
#     try:
#         matrix_config_func = get_function_from_config("matrix_config_function")
#     except AttributeError:
#         return HttpResponseBadRequest("Not configured")
#     matrix_config = matrix_config_func()
# 
#     wellknown = MatrixClientWellKnown(
#         homeserver_base_url=matrix_config["homeserver_base_url"],
#         identity_server_base_url=matrix_config.get("identity_server_base_url"),
#         other_keys=matrix_config.get("client_wellknown_other_keys"),
#     )
#     return JsonResponse(wellknown.render())
# 
# def matrix_server_wellknown_view(request, *args, **kwargs):
#     try:
#         matrix_config_func = get_function_from_config("matrix_config_function")
#     except AttributeError:
#         return HttpResponseBadRequest("Not configured")
#     matrix_config = matrix_config_func()
# 
#     wellknown = MatrixServerWellKnown(
#         homeserver_domain_with_port=matrix_config["homeserver_domain_with_port"],
#     )
#     return JsonResponse(wellknown.render())


# Path: federation/hostmeta/django/urls.py
from django.conf.urls import url
from federation.hostmeta.django import rfc7033_webfinger_view
from federation.hostmeta.django.generators import (
    nodeinfo2_view, matrix_client_wellknown_view, matrix_server_wellknown_view,
)

# noinspection PyPackageRequirements


urlpatterns = [
    url(r'^.well-known/matrix/client$', matrix_client_wellknown_view, name="matrix-client-wellknown"),
    url(r'^.well-known/matrix/server$', matrix_server_wellknown_view, name="matrix-server-wellknown"),
    url(r'^.well-known/webfinger$', rfc7033_webfinger_view, name="rfc7033-webfinger"),
    url(r'^.well-known/x-nodeinfo2$', nodeinfo2_view, name="nodeinfo2"),

]