human
Solve the following python programming problem given the following code:
@newrelic.agent.function_trace()
def process_document_path(func, reverse_name='wiki.document'):
assistant
#Here is the Python program you requested.

    """Decorator to process document_path into locale and slug, with
    auto-redirect if necessary.
    This function takes generic args and kwargs so it can presume as little
    as possible on the view method signature.
    """
    @wraps(func)
    def process(request, document_path=None, *args, **kwargs):
        if kwargs.get('bypass_process_document_path', False):
            del kwargs['bypass_process_document_path']
            return func(request, document_path, *args, **kwargs)
        (document_slug, document_locale) = (None, None)
        if document_path:
            (document_locale, document_slug, needs_redirect) = locale_and_slug_from_path(document_path, request)
            slug_length = len(document_slug)
            if (slug_length and (document_slug[(slug_length - 1)] == '/')):
                needs_redirect = True
                document_slug = document_slug.rstrip('/')
            if (not document_slug):
                raise Http404
            if (request.GET.get('raw', False) is not False):
                needs_redirect = False
            if needs_redirect:
                url = reverse('wiki.document', locale=document_locale, args=[document_slug])
                url = urlparams(url, query_dict=request.GET)
                return HttpResponsePermanentRedirect(url)
        kwargs['document_slug'] = document_slug
        kwargs['document_locale'] = document_locale
        return func(request, *args, **kwargs)
    return process