Christian Scholz
2008-07-20 08:22:14 UTC
Hi!
Yesterday I changed trunk of pyogp.lib.base to streamline the use of the
ISerialization interface. The basic pattern for serialization is now:
from interfaces import ISerialization
data = {'some':'dict'}
serializer = ISerialization(data)
payload = serializer.serialize()
content_type = serializer.content_type
So what a ISerialization adapter does is serializing it's content with
serialize() and returning the content type of the payload returned. The
default implementation uses LLSD and thus returns application/llsd+xml
The same can be used now for serializing credentials. data in this case
is a PlainPasswordCredential instance (or something which implement
IPlainPasswordCredential)
Deserialization is a bit different because we don't start with an object
which has some interface, we only have a string most of the times.
Because of this I used a names utility (you can give utility names and
register different ones which have the same Interface but different names).
Here is how to use it:
from zope.component import getUtility
from interfaces import IDeserialization
s = getDataFromSomeWhere()
content_type = obtainContentTypeOfData()
# both of the above usually come as a result of an http call
deserializer = getUtility(IDeserialization, name = content_type)
data = deserializer.deserialize_string(s)
The result is probably some dictionary (you need to know what the result
should look like) which you then can process further.
doctests for all this can be found in caps.py at the bottom where I put
the serializer/deserializer for cap data (I factored this out as it was
hardcoded to LLSD here). You can find the plainpasswordserializer in
credentials.py like before, now also with doctest. There is no
deserializer for credentials right now as the client lib does not need
it. It needs to get added on the agentdomain side, though.
I also wrote a doctest for caps in tests/caps.txt.
You can run them by calling bin/test in your buildout directory but you
first need to start bin/testserver in a different shell.
In order to only run the doctests you can say
bin/test testDocTests
which only runs that file.
-- Christian
Yesterday I changed trunk of pyogp.lib.base to streamline the use of the
ISerialization interface. The basic pattern for serialization is now:
from interfaces import ISerialization
data = {'some':'dict'}
serializer = ISerialization(data)
payload = serializer.serialize()
content_type = serializer.content_type
So what a ISerialization adapter does is serializing it's content with
serialize() and returning the content type of the payload returned. The
default implementation uses LLSD and thus returns application/llsd+xml
The same can be used now for serializing credentials. data in this case
is a PlainPasswordCredential instance (or something which implement
IPlainPasswordCredential)
Deserialization is a bit different because we don't start with an object
which has some interface, we only have a string most of the times.
Because of this I used a names utility (you can give utility names and
register different ones which have the same Interface but different names).
Here is how to use it:
from zope.component import getUtility
from interfaces import IDeserialization
s = getDataFromSomeWhere()
content_type = obtainContentTypeOfData()
# both of the above usually come as a result of an http call
deserializer = getUtility(IDeserialization, name = content_type)
data = deserializer.deserialize_string(s)
The result is probably some dictionary (you need to know what the result
should look like) which you then can process further.
doctests for all this can be found in caps.py at the bottom where I put
the serializer/deserializer for cap data (I factored this out as it was
hardcoded to LLSD here). You can find the plainpasswordserializer in
credentials.py like before, now also with doctest. There is no
deserializer for credentials right now as the client lib does not need
it. It needs to get added on the agentdomain side, though.
I also wrote a doctest for caps in tests/caps.txt.
You can run them by calling bin/test in your buildout directory but you
first need to start bin/testserver in a different shell.
In order to only run the doctests you can say
bin/test testDocTests
which only runs that file.
-- Christian
--
Christian Scholz video blog: http://comlounge.tv
COM.lounge blog: http://mrtopf.de/blog
Luetticher Strasse 10 Skype: HerrTopf
52064 Aachen Homepage: http://comlounge.net
Tel: +49 241 400 730 0 E-Mail ***@comlounge.net
Fax: +49 241 979 00 850 IRC: MrTopf, Tao_T
neue Show: TOPFt?glich (http://mrtopf.de/blog/category/topf-taglich/)
Christian Scholz video blog: http://comlounge.tv
COM.lounge blog: http://mrtopf.de/blog
Luetticher Strasse 10 Skype: HerrTopf
52064 Aachen Homepage: http://comlounge.net
Tel: +49 241 400 730 0 E-Mail ***@comlounge.net
Fax: +49 241 979 00 850 IRC: MrTopf, Tao_T
neue Show: TOPFt?glich (http://mrtopf.de/blog/category/topf-taglich/)