def get_lexer(text, lang):
    """Return the Pygments lexer for parsing this sourcecode.

    :Parameters:
        text
            The sourcecode to be lexed for highlighting. This is analysed if
            the language is 'guess'.
        lang
            An abbreviation for the programming langauge of the code. Can be
            any 'name' accepted by Pygments, including 'none' (plain text) or
            'guess' (analyse the passed code for clues).

    :Returns:
        A Pygments lexer.

    """
    from pygments.lexers import get_lexer_by_name, TextLexer, guess_lexer
    if lang == 'guess':
        try:
            return guess_lexer(text)
        except ValueError:
            return None
    elif lang == 'none':
        return TextLexer
    else:
        return get_lexer_by_name(lang)
