[Zope-dev] Storing modules in the ZODB

Joseph Barillari jbarilla@princeton.edu
Sun, 29 Jul 2001 20:20:28 -0400


--M9NhX3UHpAaciwkO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hello,

I'm having trouble storing to the ZODB.=20

The code in question reads a string argument and selects a module from
the current directory that matches the string argument, importing it
into the current class:

class Division(Persistence.Persistent):
    "A collection of rounds."
    def __init__(self, name, type, flags =3D []):
        self.name =3D name
        self.typename =3D type
        self.rules =3D __import__(type)
        self.rounds =3D []
        self.teams =3D {}
        self.judges =3D []
        self.flags =3D flags

(rest of class snipped in the interests of brevity)

Here's the result of a call using the arguments ('Test', 'APDA') in
Python 1.5.2 and Zope 2.4.0

Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "t3s.py", line 909, in add_division
    get_transaction().commit()
  File "/usr/lib/python1.5/ZODB/Transaction.py", line 300, in commit
    j.commit(o,self)
  File "/usr/lib/python1.5/ZODB/Connection.py", line 375, in commit
    dump(state)
cPickle.UnpickleableError: Cannot pickle <type 'module'> objects

(add_division is a function that creates the division and stores it to
a global database; essentially, a wrapper.)

I tried the native cPickle module in Python 2.1.1 (to ensure that I
had a clean version). Same problem -- it chokes on module objects.

The purpose of this code is to enable the user to select from several
different sets of 'rules' ('APDA' is currently the only one written),
which are implemented as Python modules. At run-time, when a
'division' is created, the ruleset is imported into the object
instance as self

Do you have any suggestions as to how I might implement this?

Thanks,

Joe

--M9NhX3UHpAaciwkO
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7ZKhLIV4b0vah+jcRAo91AJ9UIo6gNXq9aj+R89y4PrV0/4kE3wCbBKc+
IwFELw1F7VtHBOuFhQowsSQ=
=qT43
-----END PGP SIGNATURE-----

--M9NhX3UHpAaciwkO--