using yaml_constructors attribute of the Loader class
Manlio Perillo <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi.
In a framework I'm writing I have a custom YAML Loader, with several
custom constructors.
Now, I would like to allow applications to define their own
constructors, and have them be used by my framework.
Using setuptools entry points, the code is something like this:
from pkg_resources import iter_entry_points
from yaml.loader import Loader
class MyLoader(Loader):
def factory(cls)
yaml_constructors = cls.yaml_constructors
for ep in iter_entry_points('my.entrypoint'):
yl = ep.load()
yaml_constructors.update(yl.yaml_constructors)
d = dict(yaml_constructors=yaml_constructors)
return type('MyLoader', (cls,), d)
Applications just need to create a custom loader class, derived from
yaml.loader.Loader, and register their own constructors.
Is it "safe" (that is, is the API stable) to access the
yaml_constructors attribute of the Loader class?
Thanks Manlio Perillo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkvV6qIACgkQscQJ24LbaUQuVwCeLKAkdAieiGX1Toi7Hhrz4Eid
EE4AnA8isbYnip6u19kFATm0EYBsfYFf
=coop
-----END PGP SIGNATURE-----
------------------------------------------------------------------------------