declaraive de/serialization of python structures for pyramid
Project description
You will simply get a request method request.objective to ensure your request objective.
from pyramid import view_config
import objective
def includeme(config):
# include config somewhere
config.include("pyramid_objective")
config.add_route("foobar", "/foobar")
class FooObjective(objective.BunchMapping)
@objective.Item()
class body(objective.Mapping):
foo = objective.Item(objective.Unicode)
bar = objective.Item(objective.Number)
@view_config(route_name="foobar", request_method="POST")
def view(request):
validated = request.objective(FooObjective)
assert isinstance(validated.body['foo'], unicode)
assert isinstance(validated.body['bar'], (int, float))
The default objective subject is implemented like this:
class DefaultObjectiveSubject(dict):
"""Default adapter to build our objective subject."""
implements(IObjectiveSubject)
adapts(IRequest)
def __init__(self, request):
super(DefaultObjectiveSubject, self).__init__(
match=request.matchdict,
params=request.params
)
body = self._find_body(request)
if body:
self['body'] = body
@staticmethod
def _find_body(request):
# TODO maybe inspect content-type?
try:
body = request.json_body
return body
except ValueError:
if request.POST:
return request.POST
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyramid_objective-0.0.1.tar.gz
.
File metadata
- Download URL: pyramid_objective-0.0.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a397d45921a916f4533d5932929b58e5cfc8890afb3821da1c070b13993ca20f |
|
MD5 | 403cb81255923bc1f2061790f88302b9 |
|
BLAKE2b-256 | a1647c2707593b2b57770d3fc1ba86b4c3d82ea56a59dbfb695c82101d763566 |
File details
Details for the file pyramid_objective-0.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: pyramid_objective-0.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfbf7438ca22349448aa828294cb6db6da19de1d69514f3cb7731c866c6b2e4f |
|
MD5 | 7223dff72d5fec6101e94cb72573f07e |
|
BLAKE2b-256 | d0cd6b7d7b80c354cc78276ec2d9a9dc62eec72aad7a814d83b64789bc5c8442 |