def _compactRepr(obj, alwaysShow=None, flagNames=None, fieldNames=None,
                 sectionNames=None):
    """
    Return a L{str} representation of C{obj} which only shows fields with
    non-default values, flags which are True and sections which have been
    explicitly set.

    @param obj: The instance whose repr is being generated.
    @param alwaysShow: A L{list} of field names which should always be shown.
    @param flagNames: A L{list} of flag attribute names which should be shown if
        they are L{True}.
    @param fieldNames: A L{list} of field attribute names which should be shown
        if they have non-default values.
    @param sectionNames: A L{list} of section attribute names which should be
        shown if they have been assigned a value.

    @return: A L{str} representation of C{obj}.
    """
    if alwaysShow is None:
        alwaysShow = []

    if flagNames is None:
        flagNames = []

    if fieldNames is None:
        fieldNames = []

    if sectionNames is None:
        sectionNames = []

    setFlags = []
    for name in flagNames:
        if name in alwaysShow or getattr(obj, name, False) == True:
            setFlags.append(name)

    displayableArgs = _getDisplayableArguments(obj, alwaysShow, fieldNames)
    out = ['<', obj.__class__.__name__] + displayableArgs

    if setFlags:
        out.append(' flags=%s' % (','.join(setFlags),))

    for name in sectionNames:
        section = getattr(obj, name, [])
        if section:
            out.append(' %s=%r' % (name, section))

    out.append('>')

    return ''.join(out)

    Return a L{str} representation of C{obj} which only shows fields with
    non-default values, flags which are True and sections which have been
    explicitly set.

    @param obj: The instance whose repr is being generated.
    @param alwaysShow: A L{list} of field names which should always be shown.
    @param flagNames: A L{list} of flag attribute names which should be shown if
        they are L{True}.
    @param fieldNames: A L{list} of field attribute names which should be shown
        if they have non-default values.
    @param sectionNames: A L{list} of section attribute names which should be
        shown if they have been assigned a value.

    @return: A L{str} representation of C{obj}.
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/names/dns.py