'Handle object nesting before content
:py:class:`PyObject` represents Python language constructs. For
constructs that are nestable, such as a Python classes, this method will
build up a stack of the nesting heirarchy so that it can be later
de-nested correctly, in :py:meth:`after_content`.
For constructs that aren\'t nestable, the stack is bypassed, and instead
only the most recent object is tracked. This object prefix name will be
removed with :py:meth:`after_content`.'

def before_content(self):

    prefix = None
    if self.names:
        (fullname, name_prefix) = self.names[(-1)]
        if self.allow_nesting:
            prefix = fullname
        elif name_prefix:
            prefix = name_prefix.strip('.')
    if prefix:
        self.env.ref_context['py:class'] = prefix
        if self.allow_nesting:
            classes = self.env.ref_context.setdefault('py:classes', [])
            classes.append(prefix)
