'Context manager to control how XML data tags are cleaned (escaped) to
remove potentially unsafe characters or constructs.
The default (``method=\'escape_xml\'``) applies brute-force escaping of
certain key XML characters like ``<``, ``>``, and ``&`` to ensure that
the output is not valid XML.
In order to explicitly allow certain XML tags (e.g. link reference or
emphasis tags), use ``method=\'bleach_clean\'``.  This sanitizes the data
string using the ``clean`` function of the
`http://bleach.readthedocs.io/en/latest/clean.html <bleach>`_ package.
Any additional keyword arguments will be passed directly to the
``clean`` function.
Finally, use ``method=\'none\'`` to disable any sanitization. This should
be used sparingly.
Example::
w = writer.XMLWriter(ListWriter(lines))
with w.xml_cleaning_method(\'bleach_clean\'):
w.start(\'td\')
w.data(\'<a href="http://google.com">google.com</a>\')
w.end()
Parameters
method : str
Cleaning method.  Allowed values are "escape_xml",
"bleach_clean", and "none".
**clean_kwargs : keyword args
Additional keyword args that are passed to the
bleach.clean() function.'

@contextlib.contextmanager
def xml_cleaning_method(self, method=u'escape_xml', **clean_kwargs):

    current_xml_escape_cdata = self.xml_escape_cdata
    if (method == u'bleach_clean'):
        if HAS_BLEACH:
            if (clean_kwargs is None):
                clean_kwargs = {}
            self.xml_escape_cdata = (lambda x: bleach.clean(x, **clean_kwargs))
        else:
            raise ValueError(u'bleach    package    is    required    when    HTML    escaping    is    disabled.\nUse    "pip    install    bleach".')
    elif (method == u'none'):
        self.xml_escape_cdata = (lambda x: x)
    elif (method != u'escape_xml'):
        raise ValueError(u'allowed    values    of    method    are    "escape_xml",    "bleach_clean",    and    "none"')
    (yield)
    self.xml_escape_cdata = current_xml_escape_cdata
