soco.utils module
This class contains utility functions used internally by SoCo.
- soco.utils.really_unicode(in_string)[source]
Make a string unicode. Really.
Ensure
in_string
is returned as unicode through a series of progressively relaxed decodings.- Parameters
in_string (str) – The string to convert.
- Returns
Unicode.
- Return type
- Raises
- soco.utils.really_utf8(in_string)[source]
Encode a string with utf-8. Really.
First decode
in_string
viareally_unicode
to ensure it can successfully be encoded as utf-8. This is required since just calling encode on a string will often cause Python 2 to perform a coerced strict auto-decode as ascii first and will result in aUnicodeDecodeError
being raised. Afterreally_unicode
returns a safe unicode string, encode as utf-8 and return the utf-8 encoded string.- Parameters
in_string – The string to convert.
- soco.utils.camel_to_underscore(string)[source]
Convert camelcase to lowercase and underscore.
Recipe from http://stackoverflow.com/a/1176023
- soco.utils.prettify(unicode_text)[source]
Return a pretty-printed version of a unicode XML string.
Useful for debugging.
- soco.utils.show_xml(xml)[source]
Pretty print an
ElementTree
XML object.- Parameters
xml (
ElementTree
) – TheElementTree
to pretty print
Note
This is used a convenience function used during development. It is not used anywhere in the main code base.
- class soco.utils.deprecated(since, alternative=None, will_be_removed_in=None, alternative_not_referable=False)[source]
A decorator for marking deprecated objects.
Used internally by SoCo to cause a warning to be issued when the object is used, and marks the object as deprecated in the Sphinx documentation.
- Parameters
since (str) – The version in which the object is deprecated.
alternative (str, optional) – The name of an alternative object to use
will_be_removed_in (str, optional) – The version in which the object is likely to be removed.
alternative_not_referable (bool) – (optional) Indicate that
alternative
cannot be used as a sphinx reference
Example
@deprecated(since="0.7", alternative="new_function") def old_function(args): pass