Permalink
Browse files

Adding documentation for wsgi pipeline to readme, allowing filter as …

…'main' for pipeline
  • Loading branch information...
1 parent eb5c906 commit 939b858393f23396bdbf82c1129df2074c935462 @davidjb davidjb committed Sep 6, 2012
Showing with 47 additions and 3 deletions.
  1. +29 −2 README.rst
  2. +17 −1 raptorizemw/middleware.py
  3. +1 −0 setup.py
View
@@ -39,6 +39,30 @@ line with the following::
app = raptorizemw.make_middleware(app)
return app
+Usage in a PasteDeploy pipeline
+-------------------------------
+
+You can also add raptors into your PasteDeploy pipeline like so::
+
+ [pipeline:main]
+ pipeline =
+ raptorize
+ my-app
+
+ [filter:raptorize]
+ use = egg:raptorizemw
+ enterOn = konami-code
+ delayTime = 3000
+ random_chance = 0.25
+ only_on_april_1st = True
+
+ [app:myapp]
+ ...
+
+Essentially, you're able to specify ``raportizemw`` as a filter within your
+WSGI pipeline, and configure options accordingly as per the `Configuration`_
+section below.
+
Configuration
-------------
@@ -55,8 +79,11 @@ a number of configuration keywords:
chance' to load the raptor. A value of 1.0 means the raptor will be injected
every time; a value of 0.0 means it will never be injected; a value of 0.5
will result in a 50% chance of raptors. Default is 1.0.
- - ``only_on_april_1st`` must be a ``bool`` value that will restrict raptors
- only to April Fool's day. Default is ``False``.
+ - ``only_on_april_1st`` should be a ``bool`` value that will restrict raptors
+ only to April Fool's day. The configuration will coerce Boolean-like strings
+ (such as ``t``, ``true``, ``y``, ``yes``, ``on`` and ``1``) into a suitable
+ format if provided in this manner (such as through a text-based pipeline
+ configuration). Default is ``False``.
For example::
@@ -7,6 +7,22 @@
import raptorizemw.resources
+truthy = frozenset(('t', 'true', 'y', 'yes', 'on', '1'))
+
+def asbool(s):
+ """ Return the boolean value ``True`` if the case-lowered value of string
+ input ``s`` is any of ``t``, ``true``, ``y``, ``on``, or ``1``, otherwise
+ return the boolean value ``False``. If ``s`` is the value ``None``,
+ return ``False``. If ``s`` is already one of the boolean values ``True``
+ or ``False``, return it."""
+ if s is None:
+ return False
+ if isinstance(s, bool):
+ return s
+ s = str(s).strip()
+ return s.lower() in truthy
+
+
class RaptorizeMiddleware(object):
""" WSGI middleware that throws a raptor on your page. """
@@ -26,7 +42,7 @@ def __init__(self, app, serve_resources=True, random_chance=1.0,
self.app = app
self.serve_resources = serve_resources
self.random_chance = float(random_chance)
- self.only_on_april_1st = bool(only_on_april_1st)
+ self.only_on_april_1st = asbool(only_on_april_1st)
self.enterOn = enterOn
self.delayTime = int(delayTime)
View
@@ -33,5 +33,6 @@
entry_points="""
[paste.filter_app_factory]
middleware = raptorizemw:make_middleware
+ main = raptorizemw:make_middleware
""",
)

0 comments on commit 939b858

Please sign in to comment.