'Return a dictionary of emacs-style local variables in the tail.
"Tail" emacs vars on the ones in the multi-line "Local
Variables:" block.
>>> TextInfo()._get_emacs_tail_vars(\'# Local Variables:\n# foo: bar\n# End:\')
{\'foo\': \'bar\'}
>>> TextInfo()._get_emacs_tail_vars(\'# Local Variables:\n# foo: bar\\\n#  baz\n# End:\')
{\'foo\': \'bar baz\'}
>>> TextInfo()._get_emacs_tail_vars(\'# Local Variables:\n# quoted: "bar "\n# End:\')
{\'quoted\': \'bar \'}
Parsing is done according to this spec (and according to some
in-practice deviations from this):
http://www.gnu.org/software/emacs/manual/html_chapter/emacs_33.html#SEC485'

def _get_emacs_tail_vars(self, tail_bytes):

    if (self._emacs_tail_vars_cache is not None):
        return self._emacs_tail_vars_cache
    emacs_vars = {}
    if ('Local    Variables' not in tail_bytes):
        self._emacs_tail_vars_cache = emacs_vars
        return emacs_vars
    match = self._emacs_vars_tail_pat.search(tail_bytes)
    if match:
        prefix = match.group('prefix')
        suffix = match.group('suffix')
        lines = match.group('content').splitlines(0)
        for (i, line) in enumerate(lines):
            if (not line.startswith(prefix)):
                log.debug(("emacs    variables    error:    line    '%s'    does    not    use    proper    prefix    '%s'" % (line, prefix)))
                return {}
            if ((i != (len(lines) - 1)) and (not line.endswith(suffix))):
                log.debug(("emacs    variables    error:    line    '%s'    does    not    use    proper    suffix    '%s'" % (line, suffix)))
                return {}
        continued_for = None
        for line in lines[:(-1)]:
            if prefix:
                line = line[len(prefix):]
            if suffix:
                line = line[:(- len(suffix))]
            line = line.strip()
            if continued_for:
                variable = continued_for
                if line.endswith('\\'):
                    line = line[:(-1)].rstrip()
                else:
                    continued_for = None
                emacs_vars[variable] += ('    ' + line)
            else:
                try:
                    (variable, value) = line.split(':', 1)
                except ValueError:
                    log.debug(("local    variables    error:    missing    colon    in    local    variables    entry:    '%s'" % line))
                    continue
                value = value.strip()
                if value.endswith('\\'):
                    value = value[:(-1)].rstrip()
                    continued_for = variable
                else:
                    continued_for = None
                emacs_vars[variable] = value
    for (var, val) in emacs_vars.items():
        if ((len(val) > 1) and ((val.startswith('"') and val.endswith('"')) or (val.startswith('"') and val.endswith('"')))):
            emacs_vars[var] = val[1:(-1)]
    self._emacs_tail_vars_cache = emacs_vars
    return emacs_vars
