Permalink
Browse files

Version 0.1.1, which adds some error checking

  • Loading branch information...
1 parent 1d89ba4 commit 0541d3a21b9a18aab45b2814bc6560f5a3867471 @Fluxx committed Mar 19, 2012
Showing with 39 additions and 6 deletions.
  1. +24 −2 README.rst
  2. +2 −2 setup.py
  3. +4 −0 tests/test_trappist.py
  4. +9 −2 trappist.py
View
@@ -1,6 +1,28 @@
Trappist
========
-**Currently a work in progress. Not ready for production yet**
+Trappist is a Python library which allows you to mount your Flask or other WSGI application inside of your Django application. It translates a call to a "Django view" to a call to a WSGI, and handles the translation of the Flask app response back to Django.
-Trappist is a Python library which allows you to mount your Flask application inside of your Django application. It translates a call to a "Django view" to a call to a Flask app, and handles the translation of the Flask app response back to Django.
+Installation
+============
+
+Trappist is hosted on Pypi, so a simple ``pip install trappist`` or ``easy_install trappist`` should do the trick.
+
+Usage
+=====
+
+To use Trappist, simply construct a new ``Trappist`` object to wrap your existing WSGI application, and call ``mounted_at('/path')`` to mount the app at that location. For example, here is a "blog" WSGI app mounted at '/blog' inside an existing Django application::
+
+ from django.conf.urls.defaults import patterns, include, url
+ from my_blob import app
+ from trappist import Trappist
+
+ urlpatterns = patterns('',
+ Trappist(app).mounted_at('/blog'),
+ (r'^articles/(?P<year>\d{4})/$', 'news.views.year_archive'),
+ (r'^comments/', include('django.contrib.comments.urls'))
+ )
+
+The root of the blog application would then be accessible at ``/blog``, relative to the Django application root.
+
+Note: The mountpoint passed to ``mounted_at`` must be a string with a leading forward slash (/). Any other form of mountpoint prefix is not supported.
View
@@ -11,10 +11,10 @@ def read(fname):
setup(
name = "trappist",
- version = "0.1.0",
+ version = "0.1.1",
author = "Jeff Pollard",
author_email = "jeff.pollard@gmail.com",
- description = ("Mount your Flask app inside your Django app."),
+ description = ("Mount your Flask or WSGI app in your Django app."),
license = "MIT",
keywords = "django flask http mount",
url = "https://github.com/Fluxx/trappist",
View
@@ -68,6 +68,10 @@ def change_app_to_mock_app(self):
def test_init_takes_app(self):
eq_(Trappist(self.mock_app).app, self.mock_app)
+ def test_mounted_at_with_improper_string_raises_valueerror(self):
+ assert_raises_regexp(ValueError, 'invalid prefix format',
+ Trappist(self.mock_app).mounted_at, 'foo')
+
def test_mounted_at_returns_django_regex_url_resolver(self):
assert_is_instance(self.mounted_at, RegexURLResolver)
View
@@ -11,8 +11,7 @@ def __init__(self, app):
self.app = app
def mounted_at(self, prefix):
- regex = r"^%s" % prefix.lstrip('/')
- pattern = patterns('', url(r'^', self))
+ regex, pattern = self.__regex_and_pattern_from(prefix)
self.app.config.update(APPLICATION_ROOT=prefix)
return url(regex, include(pattern), dict(mountpoint=prefix))
@@ -45,3 +44,11 @@ def __patch(self, request, mountpoint):
original_script_name = request.environ.get('SCRIPT_NAME', '')
request.environ['PATH_INFO'] = patched
request.environ['SCRIPT_NAME'] = original_script_name + mountpoint
+
+ def __regex_and_pattern_from(self, prefix):
+ if not prefix.startswith('/'):
+ raise ValueError('"%s" is an invalid prefix format' % prefix)
+
+ regex = r"^%s" % prefix.lstrip('/')
+ pattern = patterns('', url(r'^', self))
+ return (regex, pattern)

0 comments on commit 0541d3a

Please sign in to comment.