-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #335 from delijati/imperative
adding abillity to define services imperative
- Loading branch information
Showing
11 changed files
with
535 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pyramid.config import Configurator | ||
|
||
|
||
def main(global_config, **settings): | ||
config = Configurator(settings=settings) | ||
# adds cornice | ||
config.include("cornice") | ||
# adds application-specific views | ||
config.include("cornice.tests.ext.dummy.views.includeme") | ||
return config.make_wsgi_app() | ||
|
||
|
||
if __name__ == '__main__': | ||
main({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from collections import defaultdict | ||
from cornice import Service | ||
from cornice import resource | ||
|
||
_USERS = defaultdict(dict) | ||
|
||
|
||
class ThingImp(object): | ||
|
||
def __init__(self, request, context=None): | ||
self.request = request | ||
self.context = context | ||
|
||
def collection_get(self): | ||
"""returns yay""" | ||
return 'yay' | ||
|
||
|
||
def get_info(request): | ||
"returns the user data" | ||
username = request.matchdict['username'] | ||
return _USERS[username] | ||
|
||
|
||
def includeme(config): | ||
# FIXME this should also work in includeme | ||
user_info = Service(name='users', path='/{username}/info') | ||
user_info.add_view('get', get_info) | ||
config.add_cornice_service(user_info) | ||
|
||
resource.add_view(ThingImp.collection_get, permission='read') | ||
thing_resource = resource.add_resource( | ||
ThingImp, collection_path='/thing', path='/thing/{id}', | ||
name='thing_service') | ||
config.add_cornice_resource(thing_resource) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.