Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysommer committed Oct 17, 2017
0 parents commit baf9069
Show file tree
Hide file tree
Showing 12 changed files with 537 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
.idea/
venv35/
*.pyc
__pycache__
test1.py
25 changes: 25 additions & 0 deletions .travis.yml
@@ -0,0 +1,25 @@
sudo: false
cache:
- pip
language: python
python:
- '3.5'
env:
- SANIC=0.6.0
install:
- pip install -U setuptools pep8 coverage docutils pygments sanic==$SANIC aiohttp
script:
- coverage erase
- nosetests --with-coverage --cover-package=spf
- python setup.py clean build install
after_success:
- pep8 spf.py
deploy:
provider: pypi
user: ashleysommer
distributions: sdist bdist_wheel
on:
tags: true
repo: ashleysommer/sanic-plugins-framework
password:
secure: cnwEYQjhEx0BOP1tdFBeFnKHUpDfZWLKkXf7N36+AOOEjBgK72D03DCsKcCt1iZJPv7KcUIK84vZzmTPBmdvGyxJNTBTJRyPpPXw1TkokxFVwVutIrMCPJB6Nchd0ZLY8tarTNdEnR3y24AWfqP6EyD0Z4mRHHX9jwnNqxQi2aMsh2tVYMPk8IlfMSyxBM6R0rlh2Ahx5GWahuvHgmJBBovp9EED9vBHOUUIREI9rU0O2SPN1hxFXH5g6QFze3iaNKsxeXO02RfWSoK3dGCa5AYnwWeraX4nTCRA6t8l7mFKdwzjpUdklFm102StQGo4h+EqXsBEGVFhrwb/SSdPcwG/pdJsfiHBLeoPhb5amI1US68OBLVYz9m4p3fH/PSB6PjMER6WYc3dxtVjfSc8+8PSKwLeN3N5ucjZJ9OtcIiRt+yiOoh+HYfTpSCEeZpG6G+TnAhUD/WDFBTt8aQxjw2wTHdyY+D9+B8a5VHm2PvNr7tEUFW/JfpFSBM02pFc0I01Gvxn67sXDzx+6ccrtVCSs/QP8AfsYLTHu3tAYHE52appYPMQ+EkIHiQB7tKfVLr1FtvQNbJcN4q7OCS7v+R0lE08KcZ3COGK66jpKg9gORjrk6Uw7drGrW3fs1vB8cLXOeQAxz9NYJuhSl5FYww+0oGJ3QjzcK/ABxMVtB8=
7 changes: 7 additions & 0 deletions LICENSE
@@ -0,0 +1,7 @@
Copyright (c) 2017 Cory Dolphin, Olin College

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 changes: 37 additions & 0 deletions README.rst
@@ -0,0 +1,37 @@
Sanic Plugins Framework
==========

|Build Status| |Latest Version| |Supported Python versions|
|License|

TODO: About

Installation
------------

Install the extension with using pip, or easy\_install.

.. code:: bash
$ pip install -U sanic-plugins-framework
Usage
-----

Contributing
------------

Questions, comments or improvements? Please create an issue on
`Github <https://github.com/ashleysommer/sanicpluginsframework>`__
Credits
-------


.. |Build Status| image:: https://api.travis-ci.org/ashleysommer/sanic-cors.svg?branch=master
:target: https://travis-ci.org/ashleysommer/sanic-cors
.. |Latest Version| image:: https://img.shields.io/pypi/v/Sanic-Cors.svg
:target: https://pypi.python.org/pypi/Sanic-Cors/
.. |Supported Python versions| image:: https://img.shields.io/pypi/pyversions/Sanic-Cors.svg
:target: https://img.shields.io/pypi/pyversions/Sanic-Cors.svg
.. |License| image:: http://img.shields.io/:license-mit-blue.svg
:target: https://pypi.python.org/pypi/Sanic-Plugins-Framework/
18 changes: 18 additions & 0 deletions example.py
@@ -0,0 +1,18 @@
from sanic import Sanic
from sanic.response import text

from spf.plugin import SanicPluginsFramework
from my_plugin import my_plugin
from logging import DEBUG

app = Sanic(__name__)
spf = SanicPluginsFramework(app)
my_plugin = spf.register_plugin(my_plugin)


@app.route('/')
def index(request):
return text("hello world")

if __name__ == "__main__":
app.run("127.0.0.1", port=8098, debug=True)
38 changes: 38 additions & 0 deletions my_plugin.py
@@ -0,0 +1,38 @@
from logging import DEBUG
from spf.plugin import SanicPlugin
from sanic.response import text

class MyPlugin(SanicPlugin):
pass

my_plugin = MyPlugin()

@my_plugin.middleware(priority=6, with_context=True)
def mw1(request, context):
context['test1'] = "test"
print("Hello world")


@my_plugin.middleware(priority=7, with_context=True)
def mw2(request, context):
assert 'test1' in context and context['test1'] == "test"
context['test2'] = "testb"
print("Hello world")


@my_plugin.middleware(priority=8, kind='response', relative='pre', with_context=True)
def mw3(request, response, context):
assert 'test1' in context and context['test1'] == "test"
assert 'test2' in context and context['test2'] == "testb"
print("Hello world")


@my_plugin.middleware(priority=2, with_context=True)
def mw4(request, context):
print(context)
my_plugin.log(DEBUG, "Hello Middleware")

@my_plugin.route('/test_plugin', with_context=False)
def t1(request):
c = my_plugin.context
return text('from plugin!')
1 change: 1 addition & 0 deletions requirements.txt
@@ -0,0 +1 @@
sanic>=0.6.0
2 changes: 2 additions & 0 deletions setup.cfg
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = true
50 changes: 50 additions & 0 deletions setup.py
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
"""
setup
~~~~
TODO: About
:copyright: (c) 2017 by Ashley Sommer.
:license: MIT, see LICENSE for more details.
"""

from setuptools import setup
from os.path import join, dirname

with open(join(dirname(__file__), 'spf/version.py'), 'r') as f:
exec(f.read())

with open(join(dirname(__file__), 'requirements.txt'), 'r') as f:
install_requires = f.read().split("\n")

setup(
name='Sanic-Cors',
version=__version__,
url='https://github.com/ashleysommer/sanicpluginsframework',
license='MIT',
author='Ashley Sommer',
author_email='ashleysommer@gmail.com',
description="TODO: desc",
long_description=open('README.rst').read(),
packages=['sanic_cors'],
zip_safe=False,
include_package_data=True,
platforms='any',
install_requires=install_requires,
tests_require=[
'nose'
],
test_suite='nose.collector',
classifiers=[
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
]
)
Empty file added spf/__init__.py
Empty file.

0 comments on commit baf9069

Please sign in to comment.