Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into replace-nose-pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Aug 12, 2020
2 parents d35ca6c + 43aab02 commit fcb0456
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ man
.channel
dist/
.venv/
.idea/
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
os: linux
dist: focal
language: python
python: 3.6
sudo: false
env:
- TOX_ENV=flake8
- TOX_ENV=docs
Expand All @@ -13,7 +14,7 @@ after_success:
- pip install coveralls
- coveralls

matrix:
jobs:
include:
- python: 3.5
env:
Expand All @@ -22,15 +23,12 @@ matrix:
env:
- TOX_ENV=py36
- python: 3.7
dist: xenial
env:
- TOX_ENV=py37
- python: 3.7
dist: xenial
env:
- TOX_ENV=py37-raw
- python: 3.8
dist: xenial
env:
- TOX_ENV=py38

Expand Down
24 changes: 23 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,34 @@
CHANGELOG
#########

4.1.0 (unreleased)
5.0.3 (unreleased)
==================

- Nothing changed yet.


5.0.2 (2020-08-12)
==================

- Rename default renderer from ``cornice`` to ``cornicejson`` (#543)


5.0.1 (2020-05-25)
==================

- Add setuptoools ``python_requires`` check


5.0.0 (2020-05-19)
==================

**Breaking Changes**

- Drop Python 2 support
- The default JSON renderer does not use ``simplejson.dumps()`` by default anymore, so the requirement has been dropped.

Please refer to `upgrading docs <https://cornice.readthedocs.io/en/stable/upgrading.html>`_ for detailed migration instructions.


4.0.1 (2019-12-02)
==================
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ Cornice:
* Vincent Fretin <vincent.fretin@gmail.com>
* Ymage <o2heltem@gmail.com>
* Volodymyr Maksymiv <vmaksymiv@quintagroup.com>
* Walter Danilo Galante <walterdangalante@gmail.com>
* Sergey Safonov <spoof@spoofa.info>
2 changes: 1 addition & 1 deletion cornice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def includeme(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('cornice', CorniceRenderer())
config.add_renderer('cornicejson', CorniceRenderer())
config.add_view_predicate('content_type', ContentTypePredicate)
config.add_request_method(current_service, reify=True)

Expand Down
87 changes: 80 additions & 7 deletions cornice/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Service(object):
:param renderer:
The renderer that should be used by this service. Default value is
'cornice'.
'cornicejson'.
:param description:
The description of what the webservice does. This is primarily intended
Expand Down Expand Up @@ -149,7 +149,7 @@ class Service(object):
:meth:`~put`, :meth:`~options` and :meth:`~delete` are decorators that can
be used to decorate views.
"""
renderer = 'cornice'
renderer = 'cornicejson'
default_validators = DEFAULT_VALIDATORS
default_filters = DEFAULT_FILTERS

Expand Down Expand Up @@ -204,11 +204,6 @@ def __init__(self, name, path=None, description=None, cors_policy=None,
# add this service to the list of available services
SERVICES.append(self)

# register aliases for the decorators
for verb in ('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'):
setattr(self, verb.lower(),
functools.partial(self.decorator, verb))

# this callback will be called when config.scan (from pyramid) will
# be triggered.
def callback(context, name, ob):
Expand Down Expand Up @@ -337,6 +332,84 @@ def wrapper(view):
return view
return wrapper

def get(self, **kwargs):
"""Add the ability to define get using python's decorators
syntax.
For instance, it is possible to do this with this method::
service = Service("blah", "/blah")
@service.get(accept="application/json")
def my_view(request):
pass
"""
return self.decorator("GET", **kwargs)

def post(self, **kwargs):
"""Add the ability to define post using python's decorators
syntax.
For instance, it is possible to do this with this method::
service = Service("blah", "/blah")
@service.post(accept="application/json")
def my_view(request):
pass
"""
return self.decorator("POST", **kwargs)

def put(self, **kwargs):
"""Add the ability to define put using python's decorators
syntax.
For instance, it is possible to do this with this method::
service = Service("blah", "/blah")
@service.put(accept="application/json")
def my_view(request):
pass
"""
return self.decorator("PUT", **kwargs)

def delete(self, **kwargs):
"""Add the ability to define delete using python's decorators
syntax.
For instance, it is possible to do this with this method::
service = Service("blah", "/blah")
@service.delete(accept="application/json")
def my_view(request):
pass
"""
return self.decorator("DELETE", **kwargs)

def options(self, **kwargs):
"""Add the ability to define options using python's decorators
syntax.
For instance, it is possible to do this with this method::
service = Service("blah", "/blah")
@service.options(accept="application/json")
def my_view(request):
pass
"""
return self.decorator("OPTIONS", **kwargs)

def patch(self, **kwargs):
"""Add the ability to define patch using python's decorators
syntax.
For instance, it is possible to do this with this method::
service = Service("blah", "/blah")
@service.patch(accept="application/json")
def my_view(request):
pass
"""
return self.decorator("PATCH", **kwargs)

def filter_argumentlist(self, method, argname, filter_callables=False):
"""
Helper method to ``get_acceptable`` and ``get_contenttypes``. DRY.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ it is easy to use and you can get started in a matter of minutes.
Show me some code!
==================

A **full** Cornice WGSI application looks like this (this example is taken from
A **full** Cornice WSGI application looks like this (this example is taken from
the `demoapp project <https://github.com/Cornices/examples>`_)::

from collections import defaultdict
Expand Down
10 changes: 10 additions & 0 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ To use Cornice, install it::

$ pip install cornice

You'll also need **waitress** (see https://pypi.python.org/pypi/waitress)::

$ pip install waitress

To start from scratch, you can use a `Cookiecutter <https://cookiecutter.readthedocs.io>`_ project template::

$ pip install cookiecutter
$ cookiecutter gh:Cornices/cookiecutter-cornice
...

Once your application is generated, go there and call *develop* against it::

$ cd myapp
$ python setup.py develop
...

The template creates a working Cornice application.

.. note::
Expand Down
29 changes: 29 additions & 0 deletions docs/source/upgrading.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
Upgrading
#########

4.X to 5.X
==========

Upgrade your codebase to Python 3.

In order to keep using ``simplejson`` with this release, add it explicitly as your project dependencies, and set it explicitly as the default renderer:

.. code-block:: python
import simplejson
from cornice.render import CorniceRenderer
class SimpleJSONRenderer(CorniceRenderer):
def __init__(self, **kwargs):
kwargs["serializer"] = simplejson.dumps
config.add_renderer(None, SimpleJSONRenderer())
See https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/renderers.html


3.X to 4.X
==========

``request.validated`` is now always a ``colander.MappingSchema`` instance (``dict``) when using ``colander_*_validator()`` functions.

In order to use a different type (eg. ``SequenceSchema``), use ``colander_validator()`` and read it from ``request.validated['body']``.


2.X to 3.X
==========

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package_data = {}

setup(name='cornice',
version='4.1.0.dev0',
version='5.0.3.dev0',
description='Define Web Services in Pyramid.',
long_description=README + '\n\n' + CHANGES,
license='MPLv2.0',
Expand All @@ -30,6 +30,7 @@
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", ],
python_requires='>=3.5',
entry_points=entry_points,
author='Mozilla Services',
author_email='services-dev@mozilla.org',
Expand Down
21 changes: 21 additions & 0 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,27 @@ def patch_favorite_color(request):
method, view, _ = service.definitions[4]
self.assertEqual("PATCH", method)

@service.put()
def put_favorite_color(request):
return ""

method, view, _ = service.definitions[5]
self.assertEqual("PUT", method)

@service.delete()
def delete_favorite_color(request):
return ""

method, view, _ = service.definitions[6]
self.assertEqual("DELETE", method)

@service.options()
def favorite_color_options(request):
return ""

method, view, _ = service.definitions[7]
self.assertEqual("OPTIONS", method)

def test_get_acceptable(self):
# defining a service with different "accept" headers, we should be able
# to retrieve this information easily
Expand Down

0 comments on commit fcb0456

Please sign in to comment.