[mod_python] StringField patch for 3.3.10

Luca Montecchiani l.montecchiani at teamsystem.com
Fri May 25 03:33:44 EDT 2007

Mike Looijmans wrote:
> The suggested changes will break a lot more than they will fix. The 
> strange implementation of the
> __repr__ functions have been done that way to remain compatible with the 
> existing code. 

read my reply to Graham, 3.3.1 is not compatible with 3.2.10 IMHO

> The StringField can be made picklable by adding a __getstate__ and, if 
> needed, a __setstate__
> function, which will not break existing code. Probably, something like 
> this will do (untested code):
> ...
>     def __getstate__(self):
>         return {'name': self.name, 'value': self.value}
> ...

I try it and I can tell you that works.

> That is a change that we could commit into the SVN archive i guess.

Two other problems remain open:

- StringField eval() problem with modpython 3.3.10

This could be solved using the Graham's suggestion
it's up to you if this is a big compatibility issue

- avoid to put the entire file content on Field __repr__ method

This could be solved using the Graham's suggestion
but I really don't like the idea of filling up a string with
a 4x time the size of an uploaded binary file ;-)
BTW this is in 3.2.10 too.

> A Field instance (uploaded file with no size limit) should never be 
> pickled - it contains a handle
> to a file that will be deleted when the current request handler ends.

Yes I know and my pickle function check for data type, and only
StringField,str and other basic type was allowed to be pickled.

Looking at 3.3.1 util.py :

     329             # make a Field
     330             if disp_options.has_key("filename"):
     331                 field = Field(name)
     332                 field.filename = disp_options["filename"]
     333             else:
     334                 field = StringField(file.read())
     335                 field.name = name
     336             field.file = file

Why always assign the "file" member ? The docs says it works on demand
and for StringField could be omitted preserving resource :

     329             # make a Field
     330             if disp_options.has_key("filename"):
     331                 field = Field(name)
     332                 field.filename = disp_options["filename"]
     333                 field.file = file
     334             else:
     335                 field = StringField(file.read())
     336                 field.name = name

> Graham's suggestion to translate the fields into something neutral, i 
> suggest using a dictonary, is
> simple enough, so I strongly advise taking that route.

I'm going that way and I will happy if this thread will
improve mopython internals.

thanks again,

Luca Montecchiani
Software Di Base
TeamSystem S.p.a.
Informativa ai sensi del D. Lgs. 196-30/06/2003.
Il contenuto di questa e.mail e degli eventuali allegati, deve essere nella disponibilità
del solo destinatario.  Se ricevete per errore questa e-mail siete pregati di informarci
(rispedendola al mittente) e di provvedere alla sua rimozione.
Possono essere presenti informazioni riservate e non corrette (parzialmente o totalmente).
Le e-mail in partenza e in arrivo possono essere oggetto di monitoraggio
da parte di Teamsystem spa.  Del contenuto è responsabile il mittente della presente.
Chiunque venga in possesso non autorizzato di questa e-mail è vincolato
dalla Legge a non leggerne il contenuto, a non copiarla, a non diffonderla e a non usarla.
Informiamo che per l' esercizio dei diritti di cui all'art. 7 del d.lgs.196/2003 ci si può
rivolgere al Titolare del trattamento Teamsystem S.r.l. via Gagarin 205 61100 PESARO
per posta o fax, indicando sulla busta o sul foglio la dicitura "Inerente alla Privacy",
o inviando una e-mail all' indirizzo privacy at teamsystem.com .

More information about the Mod_python mailing list