FYI,
urls = ("/([\w\.-_]{3,100})", "Resize")
allows for *.jpeg, *.tiff, *.gif.gz, *.jpg.bz2, ...
Use `mimetypes` (given the filename) or `PIL` (given the file) to determine
the extension, type, etc.
>>> import mimetypes
>>> mimetypes.guess_type('image.jpg')
('image/jpeg', None)
>>> mimetypes.guess_type('image.png.bz2')
('image/png', 'bzip2')
On Thu, Jan 14, 2010 at 12:55 AM, Branko Vukelic <[email protected]>wrote:
> Hi, Herman,
>
> I found your idea very cool, so I started working on something
> similar. I used the following URL pattern to match file names:
>
> '/(\w+.\w{3})'
>
> Of course, it's not a very comprehensive regex, but as a proof of
> concept, it's good enough. The filename gets handled properly, so I
> can:
>
> class resizer:
> def GET(self, filename):
> return filename
>
> Hope that helps. Also, if you're really stuck, and don't have much
> time, I'd recommend using a debugger like WinPDB to go through your
> code and figure out what web.py thinks about those URLs.
>
> On Thu, Jan 14, 2010 at 7:11 AM, Herman <[email protected]> wrote:
> > Hi Angelo,
> >
> > I tried that, but it does not seem to work.
> >
> > Hit the following URL:
> http://dev.hermanradtke.com:8881/imagedoesnotexist.jpg
> >
> > Or make any URL pointing to that domain with a .jpg|.gif|.png|.zip
> > extension. It just serves back up a page with my url as showing and a
> > content type that matches the extension.
> >
> > On Jan 13, 5:03 pm, Angelo Gladding <[email protected]> wrote:
> >> Not sure what your problem is. What do you mean by "fake file"?
> >>
> >> Maybe this will help you get started. The PIL API I'm using is
> fictitious.
> >> Replace with correct API.
> >>
> >> resources = (
> >> '/(\d{1,4})x(\d{1,4})/(.*)', 'Resize'
> >> )
> >>
> >> class Resize:
> >> def GET(self, width, height, image):
> >> new_image = PIL.image(image)
> >> new_image.resize(width=width, height=height)
> >> web.header('Content-Type', new_image.type) # image/jpeg
> >> return new_image.data
> >>
> >>
> >>
> >> On Wed, Jan 13, 2010 at 8:45 AM, Herman <[email protected]> wrote:
> >> > My intention was to use PIL to size images just in time. So I get a
> >> > URL like "http://example.com/50x20/foo.jpg". I want process this
> >> > request and send back a jpg file. It works fine now if I don't use
> >> > a .jpg extension, but that is not allowed by requirements.
> >>
> >> > On Jan 13, 6:22 am, jlist9 <[email protected]> wrote:
> >> > > I suppose you can check in GET() to see if the file exists,
> >> > > and if not, return a 404?
> >>
> >> > > On Tue, Jan 12, 2010 at 10:30 PM, Herman <[email protected]>
> wrote:
> >> > > > I want to proxy image files through webpy. I have a very simple
> >> > > > index.py that I am testing with, but webpy is automagically
> serving up
> >> > > > fake image files before I can process them.
> >>
> >> > > > index.py:
> >> > > > import web
> >>
> >> > > > urls = ("/.*", "hello")
> >> > > > app = web.application(urls, globals())
> >>
> >> > > > class hello:
> >> > > > def GET(self):
> >> > > > return 'Hello, world!'
> >>
> >> > > > if __name__ == "__main__":
> >> > > > app.run()
> >>
> >> > > > Output from webserver:
> >> > > > $ ./index.py 192.168.1.3:8881
> >> > > >http://192.168.1.3:8881/
> >> > > > 192.168.1.5:50327 - - [12/Jan/2010 22:21:00] "HTTP/1.1 GET
> /foo.jpg" -
> >> > > > 200 OK
> >>
> >> > > > My web output:
> >> > > >http://192.168.1.3:8881/foo.jpg
> >>
> >> > > > How can I prevent webpy from serving up this fake file?
> >>
> >> > > > --
> >> > > > You received this message because you are subscribed to the Google
> >> > Groups "web.py" group.
> >> > > > To post to this group, send email to [email protected].
> >> > > > To unsubscribe from this group, send email to
> >> > [email protected]<webpy%[email protected]><
> webpy%[email protected]<webpy%[email protected]>
> >.
> >> > > > For more options, visit this group athttp://
> >> > groups.google.com/group/webpy?hl=en.
> >>
> >> > --
> >> > You received this message because you are subscribed to the Google
> Groups
> >> > "web.py" group.
> >> > To post to this group, send email to [email protected].
> >> > To unsubscribe from this group, send email to
> >> > [email protected]<webpy%[email protected]><
> webpy%[email protected]<webpy%[email protected]>
> >.
> >> > For more options, visit this group at
> >> >http://groups.google.com/group/webpy?hl=en.
> >>
> >> --
> >> Angelo Gladding
> >> [email protected]http://angelo.gladding.name/
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "web.py" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> [email protected] <webpy%[email protected]>.
> > For more options, visit this group at
> http://groups.google.com/group/webpy?hl=en.
> >
> >
> >
> >
>
>
>
> --
> Branko Vukelić
>
> http://foxbunny.tumblr.com/
> http://www.flickr.com/photos/16889...@n04/
> http://www.twitter.com/foxbunny
>
> --
> You received this message because you are subscribed to the Google Groups
> "web.py" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected] <webpy%[email protected]>.
> For more options, visit this group at
> http://groups.google.com/group/webpy?hl=en.
>
>
>
>
--
Angelo Gladding
[email protected]
http://angelo.gladding.name/
-- You received this message because you are subscribed to the Google Groups "web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
