[mod_python] [help]please give an input filter example ?

camge is83070 at cis.nctu.edu.tw
Thu Sep 18 21:32:47 EST 2003


----- Original Message ----- 
From: "David Fraser" <davidf at sjsoft.com>
To: "camge" <is83070 at cis.nctu.edu.tw>
Cc: <mod_python at modpython.org>
Sent: Thursday, September 18, 2003 7:05 PM
Subject: Re: [mod_python] [help]please give an input filter example ?


> camge wrote:
>
> >----- Original Message ----- 
> >From: "David Fraser" <davidf at sjsoft.com>
> >To: "camge" <is83070 at cis.nctu.edu.tw>
> >Sent: Thursday, September 18, 2003 6:12 PM
> >Subject: Re: [mod_python] [help]please give an input filter example ?
> >
> >
> >
> >
> >>>camge wrote:
> >>>
> >>>Hi ,
> >>>
> >>>   I have written an output filter, and it works fine.
> >>>But I dont know how to write an input filter, there are not any
examples.
> >>>I have tried to write an simple input filter according to an output
> >>>
> >>>
> >filter.
> >
> >
> >>>But it always makes IE hang there.
> >>>If any one can give me an example about input filter?
> >>>Thanks a lot!
> >>>
> >>>My environment:
> >>> Apache/2.0.44 (Win32)
> >>> mod_ssl/2.0.44
> >>> OpenSSL/0.9.7
> >>> mod_python/3.0.3
> >>> Python/2.2.2
> >>>
> >>>Best regards,
> >>>camge
> >>>
> >>>
> >>>
> >>Why don't you send your example input filter that makes IE hang?
> >>
> >>Thanks
> >>David
> >>
> >>
> >>
> >>
> >
> >Below is my simple input filter inputFilter.py:
> >-------------------------------------------------------------
> >def inputfilter(filter):
> >    f=open('filter.log','ab')#for debug
> >    data='start'
> >    while data!=None:
> >        try:
> >            data = filter.read()
> >            if data:
> >                filter.write(data)
> >                f.write(str(data))
> >        except Exception,e:
> >                f.write(str(e))
> >                data=None
> >     if data==None:
> >        filter.close()
> >     f.close()
> >----------------------------------------
> >httpd.conf:
> >----------------------------------------
> ><Location /test/>
> >     PythonInputFilter inputFilter MyInputFilter
> >     SetInputFilter MyInputFilter
> ></Location>
> >
> >
> >
> >
> Excuse me rearranging your post, bottom posting makes discussion easier...
>
> I think the problem here is that you're doing filter.read() which will
> read until an end of file, which will never happen on an input filter.
> You probably need a more intelligent way of working out when to stop
> reading, e.g. for HTTP, you could read a line at a time.
> What are you wanting to use the input filter for?
>
> David
>
>
>
Thanks for your fast response!
I have tried filter.readline(), but it still reads nothing.
I need input filter to convert character set of form data submitted by cell
phone browser.
For example, convert utf-8 to big5 or gb.
If I can do it in input filter, then I dont need to modify all of my pages.







More information about the Mod_python mailing list