icat.helper — A collection of internal helper routines

Note

This module is intended for the internal use in python-icat. Most users will not need to use it directly or even care about it.

class icat.helper.Version(version)

Bases: Version

A variant of packaging.version.Version.

This version class features a special handling of the ‘-SNAPSHOT’ suffix being used for ICAT prereleases. It furthermore adds comparison with strings.

>>> version = Version('4.11.1')
>>> version == '4.11.1'
True
>>> version < '4.9.3'
False
>>> version = Version('5.0.0-SNAPSHOT')
>>> version
<Version('5.0.0a1')>
>>> version > '4.11.1'
True
>>> version < '5.0.0'
True
>>> version == '5.0.0a1'
True

New in version 1.0.0.

icat.helper.simpleqp_quote(obj)

Simple quote in quoted-printable style.

icat.helper.simpleqp_unquote(qs)

Simple unquote from quoted-printable style.

icat.helper.parse_attr_val(avs)

Parse an attribute value list string.

Parse a string representing a list of attribute and value pairs in the form:

attrvaluestring ::= attrvalue 
                |   attrvalue '_' attrvaluestring
attrvalue       ::= attr '-' value
value           ::= simplevalue 
                |   '(' attrvaluestring ')'
attr            ::= [A-Za-z]+
simplevalue     ::= [0-9A-Za-z=]+

Return a dict with the attributes as keys. In the case of an attrvaluestring in parenthesis, this string is set as value in the dict without any further processing.

icat.helper.parse_attr_string(s, attrtype)

Parse the string representation of an entity attribute.

Note: for Date we use the parser from suds.sax.date. If this is the original Suds version, this parser is buggy and might yield wrong results. But the same buggy parser is also applied by Suds internally for the Date values coming from the ICAT server. Since we are mainly interested to compare with values from the ICAT server, we have a fair chance that this comparision nevertheless yields valid results.

icat.helper.ms_timestamp(dt)

Convert datetime.datetime or string to timestamp in milliseconds since epoch.