Re: Calling a WSGI application from an action

2008-06-03 Thread Alberto Valverde

Alex Marandon wrote:
 2008/5/30 Ian Bicking [EMAIL PROTECTED]:
   
 ()

 However, there is a problem that the POST body can be eaten up.  WebOb
 specifically tries to reconstruct it, but not for file uploads (simply
 because I didn't get around to it, because it's harder to construct than
 a simple POST form).  And maybe what you are encountering is this same
 issue.
 

 Hi Ian, thanks a lot for answering my message.

 One thing I don't understand, is why the POST body gets
 deconstructed in the first place. I don't have a deep understanding
 of WSGI yet, but I thought one of its advantages was to allow
 developers to build arbitrary chains of middlewares and applications
 that are not aware of each others. So how come Pylons is modifying
 the POST body in such a way that it can't be used by subsequent WSGI
 component in the chain?
   

I had a similar problem when mounting Trac inside a Pylons application
as a controller. Apparently, at some stage environ['wsgi.input'] was
consumed hence POST requests were seen blank by Trac once they reached it.

I solved it using this piece of middleware [1] stacked closest to the
server [2] to cache input in a regular temporary file so it can be
'rewound' before passing the request to Trac [3].

Hope it helps,
Alberto

[1]
http://beta.toscawidgets.org/trac/twWebSite/browser/twwebsite/lib/inputsaver.py
[2]
http://beta.toscawidgets.org/trac/twWebSite/browser/twwebsite/config/middleware.py#L99
[3]
http://beta.toscawidgets.org/trac/twWebSite/browser/twwebsite/controllers/tracdelegate.py#L16

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



paste.registry as a standalone EGG

2008-06-03 Thread Alberto Valverde

Hi,

Are there any plans to pull paste.registry out of the Paste distribution
into a separate one?

I've recently removed Paste's dependency from ToscaWidgets in favor of
smaller WebOb and ended up copying the registry.py module almost verbatim
which is certainly sub-optimal. I believe the registry is useful enough
outside of paste and fits with the general trend of breaking Paste up into
smaller pieces.

As far as I can tell, paste.registry only needs Paste for the threadlocal
(is 2.3 support still needed?) and an import from eval_exception inside
get_request_id which could be conditional.

If I get a pointer into a way to best remove these deps. I'll gladly do
the grunt work of creating a new distribution, graft the registry back
into the paste namespace (with a setuptools' namespace packages) and
contribute it back.

Regards,
Alberto


-- 
 the humbleness of a warrior is not the humbleness of a beggar.  The
warrior lowers his head to no one, but at the same time, he doesn't
permit anyone to lower his head to him.  The beggar, on the other hand,
falls to his knees at the drop of a hat and scrapes the floor for anyone
he deems to be higher; but at the same time, he demands that someone
lower than him scrape the floor for him ... I know only the humbleness of
a warrior, and that will never permit me to be anyone's master.

Carlos Castaneda, Tales of Power




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: paste.registry as a standalone EGG

2008-06-03 Thread Ian Bicking

Alberto Valverde wrote:
 Hi,
 
 Are there any plans to pull paste.registry out of the Paste distribution
 into a separate one?

There aren't, mostly because the registry has always made me a little 
uncomfortable.  Usually when separating things out, I like to review the 
code and have a certain sense that the code is as simple and 
understandable as it can be.  I don't feel like paste.registry is at 
that point, though of course I would like it to be.  I'm not exactly 
sure what would make it simpler.

-- 
Ian Bicking : [EMAIL PROTECTED] : http://blog.ianbicking.org

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Calling a WSGI application from an action

2008-06-03 Thread Alex Marandon

2008/6/2 Ian Bicking [EMAIL PROTECTED]:
 You need code that takes req.POST and turns it into the serialized body,
 so that the WSGI app you are calling can reconstruct that body.

 I understand that Pylons parses the body of the POST request and turns
 into a Python data structure. In particular, any uploaded file gets
 turned into a cgi.FieldStorage. What I need to do is convert it back
 to its serialized version. Am I correct so far?

 Then where should I set the serialized version so that it can be used
 by oher WSGI apps? It seems that request.POST can't be assigned a new
 value.

 You'd put a new file-like object into wsgi.input, like:

 from cStringIO import StringIO
 environ['wsgi.input'] = StringIO(serialized_body)

Great, I managed to make it working. I'll try to get my head around
webob and add it there.
Thanks a lot.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



AW: How to pass image?

2008-06-03 Thread Andrew Smart

 -Ursprüngliche Nachricht-
 Von: pylons-discuss@googlegroups.com 
 [mailto:[EMAIL PROTECTED] Im Auftrag von deezee
 Gesendet: Dienstag, 3. Juni 2008 23:05
 An: pylons-discuss
 Betreff: How to pass image?
 
 
 Hello everybody!
 I'm pretty new in Pylons world - today i downloaded and 
 installed software. So, some stupid question:
 
 How to send (simplest way) image from PIL to template  
 (browser) without saving file?
 I'm playing around helloworld sample, but i want to see 
 picture instead of text. I can generate one by PIL, and send 
 by c.image, but till now i just have PIL.Image.. 
 marker, no image itself.
 In PHP it's quite simple, don't believe something newer is 
 more complicated..

Inside of the controller action:
1. you generate a image with PIL
2. you convert the stuff to string with a certain format (I do this with
reportlab charts like: binaryStuff = drawToString(d, 'png'))
3. you set the content header to the corresponding format
(response.headers['Content-type'] = 'image/png')
4. you return the string (return binaryStuff)

This controller action is only for serving the image requests! In you HTML
(maybe generated by MAKO) you have to have a img - tag which points to the
controller action.

For example:
- action index  - serves HTML, and returns HTML with img
src=/picture1
- action picture1 - serves PNG pictures

A very rough draft, but hopefully points you to the right direction.

Andrew


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: How to pass image?

2008-06-03 Thread jerry

class ImageController(BaseController):
def view(self):
image_content = binary data of your (generated) image /
app = DataApp(image_content, content_type='image/jpeg')
app.content_disposition(filename='%s.jpg' % image_name)
return app(request.environ, self.start_response)

Jerry

On Jun 3, 5:05 pm, deezee [EMAIL PROTECTED] wrote:
 Hello everybody!
 I'm pretty new in Pylons world - today i downloaded and installed
 software. So, some stupid question:

 How to send (simplest way) image from PIL to template  (browser)
 without saving file?
 I'm playing around helloworld sample, but i want to see picture
 instead of text. I can generate one by PIL, and send by c.image, but
 till now i just have PIL.Image.. marker, no image itself.
 In PHP it's quite simple, don't believe something newer is more
 complicated..

 Ł
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: How to pass image?

2008-06-03 Thread jerry

from paste.fileapp import DataApp

Jerry

On Jun 3, 8:38 pm, jerry [EMAIL PROTECTED] wrote:
 class ImageController(BaseController):
 def view(self):
 image_content = binary data of your (generated) image /
 app = DataApp(image_content, content_type='image/jpeg')
 app.content_disposition(filename='%s.jpg' % image_name)
 return app(request.environ, self.start_response)

 Jerry

 On Jun 3, 5:05 pm, deezee [EMAIL PROTECTED] wrote: Hello everybody!
  I'm pretty new in Pylons world - today i downloaded and installed
  software. So, some stupid question:

  How to send (simplest way) image from PIL to template  (browser)
  without saving file?
  I'm playing around helloworld sample, but i want to see picture
  instead of text. I can generate one by PIL, and send by c.image, but
  till now i just have PIL.Image.. marker, no image itself.
  In PHP it's quite simple, don't believe something newer is more
  complicated..

  Ł
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---