Django WSGI bug with twill?

5 views
Skip to first unread message

akaihola

unread,
Dec 3, 2007, 4:41:27 PM12/3/07
to Django developers
I'm desperately trying to get twill to work together with Django using
twill's WSGI intercepting.

The problem is, I always get the content of the page concatenated
twice together. I've debugged and narrowed down the problem so it must
be either in twill.wsgi_intercept.wsgi_fake_socket.makefile() or
django.core.handlers.wsgi.WSGIHandler.__call__(). I just don't
understand WSGI well enough to tell which one is misbehaving.

My comments to Andrey Khavryuchenko's blog entry document my debugging
process:

http://www.kds.com.ua/wp/2007/06/04/testing-django-with-twill-and-nosetests/

akaihola

unread,
Dec 3, 2007, 4:53:11 PM12/3/07
to Django developers
Here is a simple test case. Place twilltest.py and urls.py in a
directory and run "PYTHONPATH=. python twilltest.py". Make sure Django
and twill exist in your PYTHONPATH.

--- twilltest.py -------------------------

#!/usr/bin/python

from django.conf import settings
settings.configure(ROOT_URLCONF='urls')

from django.core.servers.basehttp import AdminMediaHandler
from django.core.handlers.wsgi import WSGIHandler
app = AdminMediaHandler(WSGIHandler())

from twill import add_wsgi_intercept
add_wsgi_intercept('127.0.0.1', 8000, lambda: app)

from twill.commands import *
go('http://127.0.0.1:8000/test/')
show()


--- urls.py --------------------

from django.conf.urls.defaults import patterns
from django.http import HttpResponse

urlpatterns = patterns('',
(r'^test/', lambda request: HttpResponse('TEST')),)


--- output on my machine with twill 0.9b1 and both Python 2.4 and 2.5:

closing...
==> at http://127.0.0.1:8000/test/
TESTTEST

akaihola

unread,
Dec 3, 2007, 5:09:20 PM12/3/07
to Django developers
(twill 0.9b1 is of course as close as saying "easy_install twill" if
you have setuptools installed)

akaihola

unread,
Dec 3, 2007, 5:34:58 PM12/3/07
to Django developers
I tried old versions of twill, and it seemed to work correctly in
0.8.4, but version 0.8.5 introduced this duplicating behavior. I can
see that the application result reading mechanism was heavily modified
at that point.

Here are relevant snippets of the source for your convenience.

twill 0.8.4: wsgi_intercept.wsgi_fake_socket.makefile()
http://dpaste.com/hold/26661/

twill 0.8.5: wsgi_intercept.wsgi_fake_socket.makefile()
http://dpaste.com/hold/26662/

diff between the two:
http://dpaste.com/hold/26663/

akaihola

unread,
Dec 4, 2007, 3:57:40 PM12/4/07
to Django developers
Titus Brown, the author of twill, fixed this issue in the latest
snapshot. It's available from http://darcs.idyll.org/~t/projects/twill-latest.tar.gz

Kumar McMillan

unread,
Dec 4, 2007, 3:26:35 PM12/4/07
to django-d...@googlegroups.com
On Dec 3, 2007 4:34 PM, akaihola <akai...@gmail.com> wrote:
>
> I tried old versions of twill, and it seemed to work correctly in
> 0.8.4, but version 0.8.5 introduced this duplicating behavior. I can
> see that the application result reading mechanism was heavily modified
> at that point.

Hello.
Is the right side of your diff (the + signs) the 0.8.5 version? If
so, it looks like the standalone version of wsgi_intercept (which I am
maintaining now independent of twill) contains the 0.8.5 code. Can
you try installing the latest wsgi_intercept to see if the error still
happens there?

You can run `easy_install wsgi_intercept` but then you will probably
have to obfuscate the twill local path or else remove the local
wsgi_intercept somehow. More info on some things you *might* have
to change in your code to use the standalone version is here:

http://code.google.com/p/wsgi-intercept/

-Kumar

Reply all
Reply to author
Forward
0 new messages