zope.app.wsgi adapters not registered by default

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

zope.app.wsgi adapters not registered by default

jmichiel
I'm upgrading a grok1.1 project to 1.4, and I came across this problem:
I have some views that allow XML export of some objects. The view's render method returns an on-the-fly generated tempfile.TemporaryFile object. That used to work before, but not after upgrading to 1.4: I got a rather obscure 'TypeError: The result should be None, a string, or adaptable to IResult.' error.

After some searching I found that zope.app.wsgi does define adapters for this, however, they don't seem to be registered by default. Adding 'zope.app.wsgi' to install_requires in setup.py solved the issue.

Was this deliberate, or an oversight?
If it is deliberate, there should be some mention of it in the docs.

I tried with a clean 1.4 project, and had the same problem:
create a new project and add

from tempfile import TemporaryFile

class Download(grok.View):
    def render(self):
        tempfile = TemporaryFile()
        tempfile.write('testing')
        return tempfile

browsing to '/test/download' will give you the error (provided the app was added as 'test' of course).
Reply | Threaded
Open this post in threaded view
|

Re: zope.app.wsgi adapters not registered by default

Christian Klinger
Hi Jeroen,

i guess you have to do something like this:
But i am not sure if it works...

   tempfile.write('testing')
   tempfile.seek(0)
   return tempfile.read()

Christian

>
> I'm upgrading a grok1.1 project to 1.4, and I came across this problem:
> I have some views that allow XML export of some objects. The view's render
> method returns an on-the-fly generated tempfile.TemporaryFile object. That
> used to work before, but not after upgrading to 1.4: I got a rather obscure
> 'TypeError: The result should be None, a string, or adaptable to IResult.'
> error.
>
> After some searching I found that zope.app.wsgi does define adapters for
> this, however, they don't seem to be registered by default. Adding
> 'zope.app.wsgi' to install_requires in setup.py solved the issue.
>
> Was this deliberate, or an oversight?
> If it is deliberate, there should be some mention of it in the docs.
>
> I tried with a clean 1.4 project, and had the same problem:
> create a new project and add
>
> from tempfile import TemporaryFile
>
> class Download(grok.View):
>      def render(self):
>          tempfile = TemporaryFile()
>          tempfile.write('testing')
>          return tempfile
>
> browsing to '/test/download' will give you the error (provided the app was
> added as 'test' of course).


_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|

Re: zope.app.wsgi adapters not registered by default

Martijn Faassen-2
In reply to this post by jmichiel
On 05/11/2011 01:48 PM, Jeroen Michiel wrote:

>
> I'm upgrading a grok1.1 project to 1.4, and I came across this problem:
> I have some views that allow XML export of some objects. The view's render
> method returns an on-the-fly generated tempfile.TemporaryFile object. That
> used to work before, but not after upgrading to 1.4: I got a rather obscure
> 'TypeError: The result should be None, a string, or adaptable to IResult.'
> error.
>
> After some searching I found that zope.app.wsgi does define adapters for
> this, however, they don't seem to be registered by default. Adding
> 'zope.app.wsgi' to install_requires in setup.py solved the issue.
>
> Was this deliberate, or an oversight?
> If it is deliberate, there should be some mention of it in the docs.

Doesn't sound deliberate. Could you add this to launchpad?

Regards,

Martijn

_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|

Re: zope.app.wsgi adapters not registered by default

jmichiel
Martijn Faassen-2 wrote
Doesn't sound deliberate. Could you add this to launchpad?

Regards,

Martijn
Thought as much.
Reported!
Reply | Threaded
Open this post in threaded view
|

Re: zope.app.wsgi adapters not registered by default

jmichiel
In reply to this post by Christian Klinger
Christian Klinger wrote
Hi Jeroen,

i guess you have to do something like this:
But i am not sure if it works...

   tempfile.write('testing')
   tempfile.seek(0)
   return tempfile.read()

Christian
Isn't this for working with zope.file File instances?
Reply | Threaded
Open this post in threaded view
|

Re: zope.app.wsgi adapters not registered by default

Jan-Wijbrand Kolman-3
In reply to this post by jmichiel
On 5/13/11 09:14 , Jeroen Michiel wrote:
> Martijn Faassen-2 wrote:
>> Doesn't sound deliberate. Could you add this to launchpad?
>
> Thought as much.
> Reported!

I looked into this. It is bit of an unfortunate situation. Let me try to
explain and propose a solution:

`zope.app.wsgi` defines `IResult` adapters for efficiently sending large
amounts of data back to the client.

Although in principle these adapters are not WSGI-specific (and IMHO
could've been implemented in zope.publisher where also the IResult
interfaces lives), there's one aspect in the adapter's implementation
that I think was the reason for putting these in the `zope.app.wsgi`
package after all: the implementation will use the "wsgi.file_wrapper"
from the WSGI environment when it is available.

In the Grok stack, it is grokcore.startup that directly depends on
`zope.app.wsgi`. A project built with grokproject will itself depend on
`grokcore.startup`, but no other package in the Grok stack depends on
`grokcore.startup` or `zope.app.wsgi` (except for several test
dependencies). It does somehow not make sense to me to have a project
built with `grokproject` to directly depend on `zope.app.wsgi` - this
package is only instrumental I guess.

For now I think a reasonable albeit not ideal solution would be to have
the grok package (which after all defines a "policy" or "profile" for
Grok-based web applications) depend on zope.app.wsgi and have grok's
`configure.zcml` include the configuration of `zope.app.wsgi`

I think I'll do that, unless of course someone has a much better idea :-)

regards, jw

_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|

Re: zope.app.wsgi adapters not registered by default

Jan-Wijbrand Kolman-3
On 5/18/11 11:25 , Jan-Wijbrand Kolman wrote:

> On 5/13/11 09:14 , Jeroen Michiel wrote:
>> Martijn Faassen-2 wrote:
>>> Doesn't sound deliberate. Could you add this to launchpad?
>>
>> Thought as much.
>> Reported!
>
> I looked into this. It is bit of an unfortunate situation. Let me try to
> explain and propose a solution:
>
> `zope.app.wsgi` defines `IResult` adapters for efficiently sending large
> amounts of data back to the client.
>
> Although in principle these adapters are not WSGI-specific (and IMHO
> could've been implemented in zope.publisher where also the IResult
> interfaces lives), there's one aspect in the adapter's implementation
> that I think was the reason for putting these in the `zope.app.wsgi`
> package after all: the implementation will use the "wsgi.file_wrapper"
> from the WSGI environment when it is available.
>
> In the Grok stack, it is grokcore.startup that directly depends on
> `zope.app.wsgi`. A project built with grokproject will itself depend on
> `grokcore.startup`, but no other package in the Grok stack depends on
> `grokcore.startup` or `zope.app.wsgi` (except for several test
> dependencies). It does somehow not make sense to me to have a project
> built with `grokproject` to directly depend on `zope.app.wsgi` - this
> package is only instrumental I guess.
>
> For now I think a reasonable albeit not ideal solution would be to have
> the grok package (which after all defines a "policy" or "profile" for
> Grok-based web applications) depend on zope.app.wsgi and have grok's
> `configure.zcml` include the configuration of `zope.app.wsgi`
>
> I think I'll do that, unless of course someone has a much better idea :-)

Done and released as grok-1.7.
regards, jw

_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev