import re


def abbreviate_package(stack_line):
    """ Abbreviate the package from a stack line: foo.bar.Class.method -> f.b.Class.method

    In a package name cannot be found the string is unchanged
    """
    match_object = re.match(r'(?P<package>.*\.)(?P<remainder>[^.]+\.[^.]+)$', stack_line)
    if match_object is None:
        return stack_line

    shortened_pkg = re.sub(r'(\w)\w*', r'\1', match_object.group('package'))
    return "%s%s" % (shortened_pkg, match_object.group('remainder'))