'Closes the current element (opened by the most recent call to
`start`).
Parameters
tag : str
Element name.  If given, the tag must match the start tag.
If omitted, the current element is closed.'

def end(self, tag=None, indent=True, wrap=False):

    if tag:
        if (not self._tags):
            raise ValueError(u'unbalanced    end({})'.format(tag))
        if (tag != self._tags[(-1)]):
            raise ValueError(u'expected    end({}),    got    {}'.format(self._tags[(-1)], tag))
    elif (not self._tags):
        raise ValueError(u'unbalanced    end()')
    tag = self._tags.pop()
    if self._data:
        self._flush(indent, wrap)
    elif self._open:
        self._open = 0
        self.write(u'/>\n')
        return
    if indent:
        self.write(self.get_indentation_spaces())
    self.write(u'</{}>\n'.format(tag))
