Initial commit

This commit is contained in:
Dan Tracy 2015-06-08 16:28:30 -04:00
commit f73a5e07ce
18 changed files with 427 additions and 0 deletions

85
.gitignore vendored Normal file
View file

@ -0,0 +1,85 @@
# Python #
##########
*.EGG
*.EGG-INFO
*.egg
*.egg-info
*.mo
*.pyc
*.pyd
*.pyo
*.tmp*
develop-eggs
downloads
eggs
fake-eggs
parts
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.deb
*.dmg
*.gz
*.iso
*.rar
*.tar
*.tgz
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
Icon?
Thumbs.db
ehthumbs.db
# Editor generated files #
##########################
*.bak
*.swm
*.swn
*.swo
*.swp
*~
.ropeproject
*.sublime-*
# Chef #
########
/trace_stats
cookbooks/*/metadata.json
# Tag files #
#############
TAGS
# Generated by make targets #
#############################
/.coverage
/.nose-stopwatch-times
/.req
/RELEASE-VERSION
/build
/chef_script
/dist/
/docs/doctrees
/docs/html
/docs/_build
/env/
/htmlcov
/pip-log.txt
/reports/
/.tests.pylintrc
/.tox
nosetests.xml
/.tox/

22
.travis.yml Normal file
View file

@ -0,0 +1,22 @@
language: python
python:
- 2.7
- 3.2
- 3.3
- 3.4
- pypy
install:
- pip install -r test-requirements.txt
script: nosetests
after_success:
- codecov
deploy:
distributions: sdist bdist_wheel
provider: pypi
on:
python: 2.7
tags: true
all_branches: true
user: sprockets
password:
secure: "ox6qm9oUyQGwuO5f651DNv8q8Mr1I7FrfnIuTU58y0Y+X8/g+1MWYvdc5q7Wevmnmu0dCJ3TIqYTJlHNR8lxJADzVXwzGxplr7ui68ZLI8oIcKT3Q/arqgP/IjF83p7zLmh7dYKpBcygh4OTp1F7X3f2pMIJsj4zUy9cTwxQhRIwbBn2XvtOdlgwwClPJJaL34vLDpiB1eBnOVQVI6JSXX5KJEeydIBaZS46yoe/ZLxTJsPFRdPRWcXYtYQVdEqZgPdMEWKpE+bg3YlYki5JvSI1goEzllyiheaOfeHUbzfakADqNafnbwJg9KJ+Qkpec/20TwDu+bUsLD5QzU8IrU5ycsrp78iJ7JL3LX9T6yFqdQSRcq9WEnQazRuMG+iT7EiW8+KiMPBTeNXilnQvVRaX6lV5twzIHdgIA6gzmtrzSiQxlGEGvvldJJXCzaoYfGK7LIxzYaXWdB3d5umW+3NQY710CPGHDLkIcQECrIxKot6IREyULhI/CO7josoAWzMBEwV8NWRtHQgDeo1W92NR4VBiiOY6R+TgVIhUiU53vqgRPc0DxrwX+fnro2Pj/Bys0VvyOqHWz/L0Mu5Hddu0ZxZRMTMaksxNBRRrXotjGLZvMaJVmMn8o3sKw8otjvhRPgEcCHOWDBqH7WRoXuPbk/r9L1gy7vj7EVUsmO8="

25
LICENSE Normal file
View file

@ -0,0 +1,25 @@
Copyright (c) 2015 AWeber Communications
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Sprockets nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

3
MANIFEST.in Normal file
View file

@ -0,0 +1,3 @@
include LICENSE
include README.rst
include test-requirements.txt

93
README.rst Normal file
View file

@ -0,0 +1,93 @@
sprockets.mixins.media_type
===========================
A mixin that performs Content-Type negotiation and request/response (de)serialization.
|Version| |Downloads| |Status| |Coverage| |License|
Installation
------------
``sprockets.mixins.media_type`` is available on the
`Python Package Index <https://pypi.python.org/pypi/sprockets.mixins.media_type>`_
and can be installed via ``pip`` or ``easy_install``:
.. code:: bash
pip install sprockets.mixins.media_type
Documentation
-------------
https://sprocketsmixinsmedia_type.readthedocs.org
Example
-------
The following example demonstrates how to use the Mix-in to handle media
type validation and serialization.
.. code:: python
from tornado import web, gen
from sprockets.mixins import media_type
class MyRequestHandler(media_type.MediaTypeMixin, web.RequestHandler):
@gen.coroutine
def post(self, **kwargs):
# Validate the Content-Type header using the Mix-in
if not self.is_valid_content_type():
self.set_status(415, 'Unsupported content type')
self.finish()
return
# Deserialize your request payload
data = self.decode_request()
# Ensure that you get some data out of it!
if not data:
self.set_status(400)
self.finish()
return
# Manipulate your data and do business stuff with it
data.pop('the_key')
self.set_status(200)
# Automatically serialize your data using the HTTP Accept headers
self.write(data)
@gen.coroutine
def get(self, some_id):
# Validate the Accept headers using the Mix-in
if not self.is_valid_accept_header():
self.set_status(406, 'Invalid Accept header')
self.finish()
return
# Maybe do some lookups from the database or get some data from somewhere
data = {'some_id': some_id}
self.set_status(200)
# Automatically serialize your data using the HTTP Accept headers
self.write(data)
Version History
---------------
Available at https://sprocketsmixinsmedia_type.readthedocs.org/en/latest/history.html
.. |Version| image:: https://img.shields.io/pypi/v/sprockets.mixins.media_type.svg?
:target: http://badge.fury.io/py/sprockets.mixins.media_type
.. |Status| image:: https://img.shields.io/travis/sprockets/sprockets.mixins.media_type.svg?
:target: https://travis-ci.org/sprockets/sprockets.mixins.media_type
.. |Coverage| image:: https://img.shields.io/codecov/c/github/sprockets/sprockets.mixins.media_type.svg?
:target: https://codecov.io/github/sprockets/sprockets.mixins.media_type?branch=master
.. |Downloads| image:: https://img.shields.io/pypi/dm/sprockets.mixins.media_type.svg?
:target: https://pypi.python.org/pypi/sprockets.mixins.media_type
.. |License| image:: https://img.shields.io/pypi/l/sprockets.mixins.media_type.svg?
:target: https://sprockets.mixins.media_type.readthedocs.org

2
docs/api.rst Normal file
View file

@ -0,0 +1,2 @@
.. automodule:: sprockets.mixins.media_type
:members:

18
docs/conf.py Normal file
View file

@ -0,0 +1,18 @@
from sprockets.mixins.media_type import __version__
needs_sphinx = '1.0'
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx']
source_suffix = '.rst'
master_doc = 'index'
project = 'sprockets.mixins.media_type'
copyright = '2015, AWeber Communications'
release = __version__
version = '.'.join(release.split('.')[0:1])
intersphinx_mapping = {
'python': ('https://docs.python.org/', None),
'requests': ('https://requests.readthedocs.org/en/latest/', None),
'sprockets': ('https://sprockets.readthedocs.org/en/latest/', None),
}

54
docs/examples.rst Normal file
View file

@ -0,0 +1,54 @@
Examples
========
The following example demonstrates how to use the Mix-in to handle media
type validation and serialization.
.. code:: python
from tornado import web, gen
from sprockets.mixins import media_type
class MyRequestHandler(media_type.MediaTypeMixin, web.RequestHandler):
@gen.coroutine
def post(self, **kwargs):
# Validate the Content-Type header using the Mix-in
if not self.is_valid_content_type():
self.set_status(415, 'Unsupported content type')
self.finish()
return
# Deserialize your request payload
data = self.decode_request()
# Ensure that you get some data out of it!
if not data:
self.set_status(400)
self.finish()
return
# Manipulate your data and do business stuff with it
data.pop('the_key')
self.set_status(200)
# Automatically serialize your data using the HTTP Accept headers
self.write(data)
@gen.coroutine
def get(self, some_id):
# Validate the Accept headers using the Mix-in
if not self.is_valid_accept_header():
self.set_status(406, 'Invalid Accept header')
self.finish()
return
# Maybe do some lookups from the database or get some data from somewhere
data = {'some_id': some_id}
self.set_status(200)
# Automatically serialize your data using the HTTP Accept headers
self.write(data)

7
docs/history.rst Normal file
View file

@ -0,0 +1,7 @@
Version History
===============
Next Release
------------
* Initial version

61
docs/index.rst Normal file
View file

@ -0,0 +1,61 @@
sprockets.mixins.media_type
===========================
A mixin that performs Content-Type negotiation and request/response (de)serialization.
|Version| |Downloads| |Status| |Coverage| |License|
Installation
------------
``sprockets.mixins.media_type`` is available on the
`Python Package Index <https://pypi.python.org/pypi/sprockets.mixins.media_type>`_
and can be installed via ``pip`` or ``easy_install``:
.. code:: bash
pip install sprockets.mixins.media_type
API Documentation
-----------------
.. toctree::
:maxdepth: 2
api
examples
Version History
---------------
See :doc:`history`
Issues
------
Please report any issues to the Github project at `https://github.com/sprockets/sprockets.mixins.media_type/issues <https://github.com/sprockets/sprockets.mixins.media_type/issues>`_
Source
------
``sprockets.mixins.media_type`` source is available on Github at `https://github.com/sprockets/sprockets.mixins.media_type <https://github.com/sprockets/sprockets.mixins.media_type>`_
License
-------
``sprockets.mixins.media_type`` is released under the `3-Clause BSD license <https://github.com/sprockets/sprockets.mixins.media_type/blob/master/LICENSE>`_.
Indices and tables
------------------
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. |Version| image:: https://img.shields.io/pypi/v/sprockets.mixins.media_type.svg?
:target: http://badge.fury.io/py/sprockets.mixins.media_type
.. |Status| image:: https://img.shields.io/travis/sprockets/sprockets.mixins.media_type.svg?
:target: https://travis-ci.org/sprockets/sprockets.mixins.media_type
.. |Coverage| image:: https://img.shields.io/codecov/c/github/sprockets/sprockets.mixins.media_type.svg?
:target: https://codecov.io/github/sprockets/sprockets.mixins.media_type?branch=master
.. |Downloads| image:: https://img.shields.io/pypi/dm/sprockets.mixins.media_type.svg?
:target: https://pypi.python.org/pypi/sprockets.mixins.media_type
.. |License| image:: https://img.shields.io/pypi/l/sprockets.mixins.media_type.svg?
:target: https://sprockets.mixins.media_type.readthedocs.org

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
tornado
msgpack-python

2
setup.cfg Normal file
View file

@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1

38
setup.py Normal file
View file

@ -0,0 +1,38 @@
import setuptools
setuptools.setup(
name='sprockets.mixins.media_type',
version='0.0.0',
description='A mixin for reporting handling content-type/accept headers',
long_description=open('test-requirements.txt', 'r').read(),
url='https://github.com/sprockets/sprockets.mixins.media_type',
author='AWeber Communications',
author_email='api@aweber.com',
license='BSD',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules'
],
packages=['sprockets',
'sprockets.mixins',
'sprockets.mixins.media_type'],
package_data={'': ['LICENSE', 'README.md']},
include_package_data=True,
install_requires=['tornado'],
namespace_packages=['sprockets',
'sprockets.mixins'],
zip_safe=False)

1
sprockets/__init__.py Normal file
View file

@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

View file

@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

View file

@ -0,0 +1,8 @@
"""
Sprockets.Mixins.Media_type
===========================
"""
version_info = (0, 0, 0)
__version__ = '.'.join(str(v) for v in version_info)

5
test-requirements.txt Normal file
View file

@ -0,0 +1,5 @@
coverage>=3.7,<4
codecov
nose>=1.3,<2
mock
-r requirements.txt

0
tests.py Normal file
View file