[mod_python] servlet form against publishe rR: Mod_python Digest, Vol 18, Issue 13

Daniel Popowich dpopowich at comcast.net
Wed Sep 8 10:26:40 EDT 2004


Manera, Villiam writes:
> >Daniel Popowich wrote:
> 
> >I still don't quite understand why you would need it.  Let's say a
> >request comes in like this:
> 
> >   http://myserver/myservlet?foo=
> 
> >In the current system, if I set query_vars like this:
> 
> >   query_vars = ['foo']
> 
> >then you get exactly what you need: empty values are stripped by
> >FieldStorage, but Servlet, not seeing the key, will set the instance
> >variable foo to its default, an empty string.
> 
> >Daniel Popowich
> 
> Yes, this is right and powerful for new programs, I will develop.
> 
> I'm thinking a way to move the 1000 programs that have been  written already from  publisher to servlet, probably I'm the only in the world with this need.
> 
> I've written something like servlet.__load_vars but instead to setattr(self, name, val) I put them in session[name] = val and the programs will search there.
> 
> In order to set query_vars I should enter inside the 1000  programs to discover the variables to set.
> 
> If I had the option to set for these kind of programs req.form = util.FieldStorage(req, keep_blank_values=1) in self.form.list I would find all this variables without looking inside the programs.
> 
> So I now understand that it is a special need concerning the past instead of the future, and  I may solve it in a other way,  so don't care anymore about it
> 
> Villiam

I see your problem.  While I don't think I want to add this to the
mainstream distribution, it's actually quite simple (so, perhaps I
should just shut up and do it!).  You can apply the patch attached
below.  It adds a keep_blank_values attribute with a default of 0 to
Servlet, so unless you change something in a subclass, servlets will
behave exactly as they do now.  To get the behaviour you want, set
keep_blank_values to 1 in a subclass, eg:

   MyServlet(HTMLPage):
      keep_blank_values = 1
      ...
      

Daniel Popowich
-----------------------------------------------
http://home.comcast.net/~d.popowich/mpservlets/


servlet.patch for version 1.1.5:

-------------- next part --------------
*** servlet.py~	Fri Aug  6 11:33:28 2004
--- servlet.py	Wed Sep  8 09:14:05 2004
***************
*** 199,204 ****
--- 199,205 ----
      content_type = None
      auth_realm = 'Unspecified'
      reusable = True
+     keep_blank_values = 0
      use_session = False
      session = None
      session_timeout = 60 * 30 # 30 minutes
***************
*** 585,591 ****
      
          self.__out = []
  
!         self.form = util.FieldStorage(self.req)
          self.__load_vars()
  
          if self.use_session:
--- 586,592 ----
      
          self.__out = []
  
!         self.form = util.FieldStorage(self.req, self.keep_blank_values)
          self.__load_vars()
  
          if self.use_session:


More information about the Mod_python mailing list