Package pyamf :: Package util

[hide private]
[frames] | no frames]

# Package util

source code

AMF Utilities.

Since: 0.1.0

Submodules | [hide private]

- pyamf.util.imports: Tools for doing dynamic imports.

Classes | [hide private]

| StringIOProxy
| DataTypeMixIn

Functions | [hide private]

find_xml_lib() Run through a predefined order looking through the various `ElementTree` implementations so that any type can be encoded but PyAMF will return elements as the first implementation found. | source code

`str`

hexdump(data) Get hexadecimal representation of `StringIO` data. | source code

`str`

get_timestamp(d) Returns a UTC timestamp for a `datetime.datetime` object. | source code

`datetime.datetime`

get_datetime(secs) Return a UTC date from a timestamp. | source code

get_properties(obj) | source code

get_attrs(obj) Gets a `dict` of the attrs of an object in a predefined resolution order. | source code

set_attrs(obj, attrs) A generic function which applies a collection of attributes `attrs` to object `obj`. | source code

get_class_alias(klass) Returns a alias class suitable for klass. | source code

`bool`

is_class_sealed(klass) Returns a `boolean` whether or not the supplied class can accept dynamic properties. | source code

`dict`

get_class_meta(klass) Returns a `dict` containing meta data based on the supplied class, useful for class aliasing. | source code

is_ET_element(obj) Determines if the supplied `obj` param is a valid ElementTree element. | source code

`bool`

is_float_broken() Older versions of Python (<=2.5) and the Windows platform are renowned for mixing up 'special' floats. | source code

isNaN(val) | source code

isPosInf(val) | source code

isNegInf(val) | source code

read_double_workaround(self) | source code

write_double_workaround(self, d) Override the DataTypeMixIn.write_double method to fix problems with doubles by using the third-party `fpconst` library. | source code

x(self, d) Writes an 8 byte float to the stream. | source code

Variables | [hide private]

| xml_types = `None` XML types.
| int_types = ``(`<type 'int'>`,` <type 'long'>`)`` Numeric types.
| str_types = ``(`<type 'str'>`,` <type 'unicode'>`)`` String types.
| PosInf = `inf`
| NegInf = `-inf`
| NaN = `nan`
| negative_timestamp_broken = `False` On some Python versions retrieving a negative timestamp, like `datetime.datetime.utcfromtimestamp(-31536000.0)` is broken.

Imports: struct, calendar, datetime, types, inspect, pyamf, StringIO, set, ET, BufferedByteStream, IndexedCollection, IndexedMap, imports

Function Details | [hide private]

### find_xml_lib()

source code

Run through a predefined order looking through the various `ElementTree` implementations so that any type can be encoded but PyAMF will return elements as the first implementation found.

We work through the C implementations first - then the pure Python versions. The downside to this is that a possible of three libraries will be loaded into memory that are not used but the libs are small (relatively) and the flexibility that this gives seems to outweigh the cost. Time will tell.

Since: 0.4

### hexdump(data)

source code

Get hexadecimal representation of `StringIO` data.

Parameters:
  - `data` ()
Returns: `str`
  Hexadecimal string.

### get_timestamp(d)

source code

Returns a UTC timestamp for a `datetime.datetime` object.

Parameters:
  - `d` (`datetime.datetime`) - The date object.
Returns: `str`
  UTC timestamp.

Note: Inspiration taken from the Intertwingly blog.

### get_datetime(secs)

source code

Return a UTC date from a timestamp.

Parameters:
  - `secs` (`long`) - Seconds since 1970.
Returns: `datetime.datetime`
  UTC timestamp.

### get_properties(obj)

source code

Since: 0.5

### get_attrs(obj)

source code

Gets a `dict` of the attrs of an object in a predefined resolution order.

Raises:
  - `AttributeError` - A duplicate attribute was already found in this collection, are you mixing different key types?

### set_attrs(obj, attrs)

source code

A generic function which applies a collection of attributes `attrs` to object `obj`.

Parameters:
  - `obj` - An instance implementing the `__setattr__` function
  - `attrs` (Usually a dict) - A collection implementing the `iteritems` function

### get_class_alias(klass)

source code

Returns a alias class suitable for klass. Defaults to pyamf.ClassAlias

### is_class_sealed(klass)

source code

Returns a `boolean` whether or not the supplied class can accept dynamic properties.

Returns: `bool`

Since: 0.5

### get_class_meta(klass)

source code

Returns a `dict` containing meta data based on the supplied class, useful for class aliasing.

Returns: `dict`

Since: 0.5

### is_float_broken()

source code

Older versions of Python (<=2.5) and the Windows platform are renowned for mixing up 'special' floats. This function determines whether this is the case.

Returns: `bool`

Since: 0.4

### isNaN(val)

source code

Since: 0.5

### isPosInf(val)

source code

Since: 0.5

### isNegInf(val)

source code

Since: 0.5

### x(self, d)

source code

Writes an 8 byte float to the stream.

Parameters:
  - `d` (`float`) - 8 byte float
Raises:
  - `TypeError` - Unexpected type for float `d`.