<commit_before># -*- coding: utf-8 -*-

import re
import logging
from flask import request, url_for

from website import settings

# Keep me: Makes rubeus importable from website.util
from . import rubeus  # noqa

logger = logging.getLogger(__name__)


guid_url_node_pattern = re.compile('^/project/[a-zA-Z0-9]{5,}/node(?=/[a-zA-Z0-9]{5,})')
guid_url_project_pattern = re.compile('^/project(?=/[a-zA-Z0-9]{5,})')
guid_url_profile_pattern = re.compile('^/profile(?=/[a-zA-Z0-9]{5,})')


def _get_guid_url_for(url):
    """URL Post-processor transforms specific `/project/<pid>` or `/project/<pid>/node/<nid>`
    urls into guid urls. Ex: `<nid>/wiki/home`.
    """
    guid_url = guid_url_node_pattern.sub('', url, count=1)
    guid_url = guid_url_project_pattern.sub('', guid_url, count=1)
    guid_url = guid_url_profile_pattern.sub('', guid_url, count=1)
    return guid_url


def api_url_for(view_name, _absolute=False, *args, **kwargs):
    """Reverse URL lookup for API routes (those that use the JSONRenderer).
    Takes the same arguments as Flask's url_for, with the addition of
    `_absolute`, which will make an absolute URL with the correct HTTP scheme
    based on whether the app is in debug mode.
    """
    if _absolute:
        # Pop off kwargs to ensure that keyword arguments are only passed
        # once
        _external = kwargs.pop('_external', True)
        scheme = 'http' if settings.DEBUG_MODE else 'https'
        _scheme = kwargs.pop('_scheme', scheme)
    else:
        _external = kwargs.pop('_external', False)
        _scheme = kwargs.pop('_scheme', None)
    return url_for('JSONRenderer__{0}'.format(view_name),
        _external=_external, _scheme=_scheme,
        *args, **kwargs)


def web_url_for(view_name, _absolute=False, _guid=False, *args, **kwargs):
    """Reverse URL lookup for web routes (those that use the OsfWebRenderer).
    Takes the same arguments as Flask's url_for, with the addition of
    `_absolute`, which will make an absolute URL with the correct HTTP scheme
    based on whether the app is in debug mode.
    """
    if _absolute:
        _external = kwargs.pop('_external', True)
        scheme = 'http' if settings.DEBUG_MODE else 'https'
        _scheme = kwargs.pop('_scheme', scheme)
    else:
        _external = kwargs.pop('_external', False)
        _scheme = kwargs.pop('_scheme', None)<commit_msg>add xml renderer to api_url_for<commit_after># -*- coding: utf-8 -*-

import re
import logging
from flask import request, url_for

from website import settings

# Keep me: Makes rubeus importable from website.util
from . import rubeus  # noqa

logger = logging.getLogger(__name__)


guid_url_node_pattern = re.compile('^/project/[a-zA-Z0-9]{5,}/node(?=/[a-zA-Z0-9]{5,})')
guid_url_project_pattern = re.compile('^/project(?=/[a-zA-Z0-9]{5,})')
guid_url_profile_pattern = re.compile('^/profile(?=/[a-zA-Z0-9]{5,})')


def _get_guid_url_for(url):
    """URL Post-processor transforms specific `/project/<pid>` or `/project/<pid>/node/<nid>`
    urls into guid urls. Ex: `<nid>/wiki/home`.
    """
    guid_url = guid_url_node_pattern.sub('', url, count=1)
    guid_url = guid_url_project_pattern.sub('', guid_url, count=1)
    guid_url = guid_url_profile_pattern.sub('', guid_url, count=1)
    return guid_url


def api_url_for(view_name, _absolute=False, _xml=False, *args, **kwargs):
    """Reverse URL lookup for API routes (that use the JSONRenderer or XMLRenderer).
    Takes the same arguments as Flask's url_for, with the addition of
    `_absolute`, which will make an absolute URL with the correct HTTP scheme
    based on whether the app is in debug mode.
    """
    if _absolute:
        # Pop off kwargs to ensure that keyword arguments are only passed
        # once
        _external = kwargs.pop('_external', True)
        scheme = 'http' if settings.DEBUG_MODE else 'https'
        _scheme = kwargs.pop('_scheme', scheme)
    else:
        _external = kwargs.pop('_external', False)
        _scheme = kwargs.pop('_scheme', None)

    renderer = 'XMLRenderer' if _xml else 'JSONRenderer'

    return url_for('{0}__{1}'.format(renderer, view_name),
        _external=_external, _scheme=_scheme,
        *args, **kwargs)


def web_url_for(view_name, _absolute=False, _guid=False, *args, **kwargs):
    """Reverse URL lookup for web routes (those that use the OsfWebRenderer).
    Takes the same arguments as Flask's url_for, with the addition of
    `_absolute`, which will make an absolute URL with the correct HTTP scheme
    based on whether the app is in debug mode.
    """
    if _absolute:
        _external = kwargs.pop('_external', True)
        scheme = 'http' if settings.DEBUG_MODE else 'https'
        _scheme = kwargs.pop('_scheme', scheme)
    else:
        _external = kwargs.pop('_external', False)
        _scheme = kwargs.pop('_scheme', None)
{'fraction_non_alphanumeric': 0.12631578947368421, 'fraction_numerical': 0.007223942208462332, 'mean_word_length': 3.5673892554194158, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2194411', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1545, 'n_words': 454}