How to use the cornice.util function in cornice

To help you get started, we’ve selected a few cornice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Cornices / cornice / tests / test_util.py View on Github external
def test_extract_form_urlencoded_data_is_deprecated(self):
        with mock.patch('cornice.util.warnings') as mocked:
            util.extract_form_urlencoded_data(mock.MagicMock())
            self.assertTrue(mocked.warn.called)
github Cornices / cornice / tests / test_util.py View on Github external
def test_extract_json_data_is_deprecated(self):
        with mock.patch('cornice.util.warnings') as mocked:
            util.extract_json_data(mock.MagicMock())
            self.assertTrue(mocked.warn.called)
github Cornices / cornice / tests / test_util.py View on Github external
def test_current_service_returns_the_service_for_existing_patterns(self):
        request = mock.MagicMock()
        request.matched_route.pattern = '/buckets'
        request.registry.cornice_services = {'/buckets': mock.sentinel.service}

        self.assertEqual(util.current_service(request), mock.sentinel.service)
github fedora-infra / bodhi / bodhi / server / services / errors.py View on Github external
import mako.lookup
import pyramid.httpexceptions
import pyramid.response

from bodhi.server.config import config
from bodhi.server.util import get_absolute_path


log = logging.getLogger('bodhi')


# First, just re-use cornice's default json handler for our own.  It is fine.
json_handler = cornice.util.json_error

# TODO -- make this do the right thing.  Not a big deal for now.
jsonp_handler = cornice.util.json_error


def camel2space(camel):
    """
    Convert CamelCaseText to Space Separated Text.

    Args:
        camel (str): Camel cased text you wish to convert to space separated text.
    Returns:
        str: A space separated version of the given camel cased text.
    """
    regexp = r'([A-Z][a-z0-9]+|[a-z0-9]+|[A-Z0-9]+)'
    return ' '.join(re.findall(regexp, camel))


def status2summary(status):
github fedora-infra / bodhi / bodhi / server / services / errors.py View on Github external
import cornice.util
import mako.exceptions
import mako.lookup
import pyramid.httpexceptions
import pyramid.response

from bodhi.server.config import config
from bodhi.server.util import get_absolute_path


log = logging.getLogger('bodhi')


# First, just re-use cornice's default json handler for our own.  It is fine.
json_handler = cornice.util.json_error

# TODO -- make this do the right thing.  Not a big deal for now.
jsonp_handler = cornice.util.json_error


def camel2space(camel):
    """
    Convert CamelCaseText to Space Separated Text.

    Args:
        camel (str): Camel cased text you wish to convert to space separated text.
    Returns:
        str: A space separated version of the given camel cased text.
    """
    regexp = r'([A-Z][a-z0-9]+|[a-z0-9]+|[A-Z0-9]+)'
    return ' '.join(re.findall(regexp, camel))
github Cornices / cornice / cornice / __init__.py View on Github external
"""Include the Cornice definitions
    """
    # attributes required to maintain services
    config.registry.cornice_services = {}

    settings = config.get_settings()

    # localization request subscriber must be set before first call
    # for request.localizer (in wrap_request)
    if settings.get('available_languages'):
        setup_localization(config)

    config.add_directive('add_cornice_service', register_service_views)
    config.add_directive('add_cornice_resource', register_resource_views)
    config.add_subscriber(wrap_request, NewRequest)
    config.add_renderer('simplejson', util.json_renderer)
    config.add_view_predicate('content_type', ContentTypePredicate)
    config.add_request_method(current_service, reify=True)

    if asbool(settings.get('handle_exceptions', True)):
        config.add_view(handle_exceptions, context=Exception,
                        permission=NO_PERMISSION_REQUIRED)
        config.add_view(handle_exceptions, context=HTTPNotFound,
                        permission=NO_PERMISSION_REQUIRED)
        config.add_view(handle_exceptions, context=HTTPForbidden,
                        permission=NO_PERMISSION_REQUIRED)