Version: 1.2.0.4.dev0

stix.utils Module

Functions

stix.utils.is_cdata(text)

Returns True if text contains a CDATA block.

Example

>>> is_cdata("<![CDATA[Foo]]>")
True
>>> is_cdata("NOPE")
False
stix.utils.strip_cdata(text)

Removes all CDATA blocks from text if it contains them.

Note

If the function contains escaped XML characters outside of a CDATA block, they will be unescaped.

Parameters:string containing one or more CDATA blocks. (A) –
Returns:An XML unescaped string with CDATA block qualifiers removed.
stix.utils.cdata(text)

Wraps the input text in a <![CDATA[ ]]> block.

If the text contains CDATA sections already, they are stripped and replaced by the application of an outer-most CDATA block.

Parameters:text – A string to wrap in a CDATA block.
Returns:The text value wrapped in <![CDATA[]]>
stix.utils.raise_warnings(func)

Function decorator that causes all Python warnings to be raised as exceptions in the wrapped function.

Example

>>> @raise_warnings
>>> def foo():
>>>     warnings.warn("this will raise an exception")
stix.utils.silence_warnings(func)

Function decorator that silences/ignores all Python warnings in the wrapped function.

Example

>>> @silence_warnings
>>> def foo():
>>>     warnings.warn("this will not appear")
stix.utils.xml_bool(value)

Returns True if value is an acceptable xs:boolean True value. Returns False if value is an acceptable xs:boolean False value. If value is None, this function will return None.