[mod_python] StringField patch for 3.3.10

Graham Dumpleton graham.dumpleton at gmail.com
Thu May 24 18:18:56 EDT 2007


We can look at your changes, but the documentation does say about the
Field class:

"""This class is used internally by FieldStorage and is not meant to
be instantiated by the user."""

In other words it is an implementation detail and you perhaps
shouldn't be expecting it to be able to be pickled and unpickled, the
later equating to instantiation by the user.

You would perhaps be better off using the public API to translate the
form/fields into a neutral format and then doing the pickle on that.

BTW, I presume you meant 3.3.1 rather than 3.3.10.

Graham

On 25/05/07, Luca Montecchiani <l.montecchiani at teamsystem.com> wrote:
> Hi all,
>
> after a while I figure out all the problems withe the new
> StringField objects and I've cooked a patch that works for me.
> The patch try to fix the following problems:
>
> 1- StringField not pickable anymore with modpython 3.3.10
> 2- StringField eval() problem with modpython 3.3.10
> 3- avoid to put the entire file content on Field __repr__ method
>
> please let me know if this could be an acceptable way to address
> all this compatibility problems.
>
> thanks in advance,
> luca
>
> --
> 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 .
> ------------------------------------------------------------------------------------------
>
> --- util.py.orig        Wed Nov 22 12:15:54 2006
> +++ util.py     Thu May 24 23:06:42 2007
> @@ -83,7 +83,12 @@
>
>      def __repr__(self):
>          """Return printable representation."""
> -        return "Field(%s, %s)" % (`self.name`, `self.value`)
> +        if self.file:
> +            # avoid to put the entire file content in the
> +            # returned string !
> +            return "Field(%s, %s)" % (`self.name`, `self.filename`)
> +        else:
> +            return "Field(%s, %s)" % (`self.name`, `self.value`)
>
>      def __getattr__(self, name):
>          if name != 'value':
> @@ -126,8 +131,8 @@
>          return self.file
>
>      def __repr__(self):
> -        """Return printable representation (to pass unit tests)."""
> -        return "Field(%s, %s)" % (`self.name`, `self.value`)
> +        # this is necessary if you want to eval a StringField
> +        return self.value
>
>  class FieldList(list):
>
> @@ -330,15 +335,18 @@
>              if disp_options.has_key("filename"):
>                  field = Field(name)
>                  field.filename = disp_options["filename"]
> +                # file and headers attributes are only
> +                # for Field objects because they will make
> +                # a StringField unpickable
> +                field.file = file
> +                field.headers = headers
>              else:
>                  field = StringField(file.read())
>                  field.name = name
> -            field.file = file
>              field.type = ctype
>              field.type_options = type_options
>              field.disposition = disp
>              field.disposition_options = disp_options
> -            field.headers = headers
>              self.list.append(field)
>
>      def add_field(self, key, value):
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
>



More information about the Mod_python mailing list