Previous topic

factory

Next topic

llsd_builder

This Page

helpers

class pyogp.lib.base.helpers.LLSDDeserializer

utility for deserializing LLSD data

The deserialization component is defined as a utility because the input data can be a string or a file. It might be possible to define this as an adapter on a string but a string is too generic for this. So that’s why it is a utility.

You can use it like this:

>>> s='<?xml version="1.0" ?><llsd><map><key>test</key><integer>1234</integer><key>foo</key><string>bar</string></map></llsd>'

We use queryUtility because this returns None instead of an exception when a utility is not registered. We use the content type we received as the name of the utility. Another option would of course be to subclas string to some LLSDString class and use an adapter. We then would need some factory for generating the LLSDString class from whatever came back from the HTTP call.

So here is how you use that utility: >>> deserializer = LLSDDeserializer() >>> llsd = deserializer.deserialize(s) >>> llsd {‘test’: 1234, ‘foo’: ‘bar’}

We can also test this with some non-LLSD string:

>>> llsd = deserializer.deserialize_string('mumpitz')   # this is not LLSD
...
DeserializationFailed: deserialization failed for 'mumpitz', reason: 'invalid token at index 0: 109'
>>> llsd = deserializer.deserialize_string('barfoo') 
...
DeserializationFailed: deserialization failed for 'barfoo', reason: 'binary notation not yet supported'
deserialize(data)
convenience class to handle a variety of inputs
deserialize_file(fp)
deserialize a file
deserialize_string(data)
deserialize a string
class pyogp.lib.base.helpers.ListLLSDSerializer(context)

adapter for serializing a list to LLSD

An example: >>> d=[‘ChatSessionRequest’, ‘CopyInventoryFromNotecard’] >>> serializer = ListLLSDSerializer(d) >>> serializer.serialize() ‘<?xml version=”1.0” ?><llsd><array><string>ChatSessionRequest</string><string>CopyInventoryFromNotecard</string></array></llsd>’ >>> serializer.content_type ‘application/llsd+xml’

content_type
return the content type of this serializer
serialize()
convert the payload to LLSD
class pyogp.lib.base.helpers.Helpers

contains useful helper functions

static bytes_to_ascii(data)
converts bytes to ascii format
static bytes_to_base64(data)
converts bytes to ascii format
static bytes_to_hex(data)
converts bytes to hex format
static hex_to_ascii(data)
converts bytes to ascii format
static int_to_bytes(data)
converts an int to a string of bytes
static log_event_queue_data(data, _object)
default logging function for event queue data events
static log_packet(packet, _object)
default logging function for packets
static null_packet_handler(packet, _object)
just a null event handler for watching aka fully parsing specific packets
static pack_quaternion_to_vector3(quaternion)
pack a normalized quaternion (tuple) into a vector3 (tuple)
static packed_u16_to_float(bytes, offset, lower, upper)
Extract float packed as u16 in a byte buffer
static packed_u8_to_float(bytes, offset, lower, upper)
Extract float packed as u8 in a byte buffer
class pyogp.lib.base.helpers.DictLLSDSerializer(context)

adapter for serializing a dictionary to LLSD

An example: >>> d={‘foo’:’bar’, ‘test’:1234} >>> serializer = DictLLSDSerializer(d) >>> serializer.serialize() ‘<?xml version=”1.0” ?><llsd><map><key>test</key><integer>1234</integer><key>foo</key><string>bar</string></map></llsd>’ >>> serializer.content_type ‘application/llsd+xml’

content_type
return the content type of this serializer
serialize()
convert the payload to LLSD
class pyogp.lib.base.helpers.Wait(duration)

a simple timer that blocks a calling routine for the specified number of seconds

done since we were writing timing loops in test scripts repeatedly returns True when it’s done

run()
stop()