'Lint the Python inside a single Python expression in a Mako template.
Arguments:
python_code: The Python contents of an expression.
start_offset: The offset of the Python content inside the original
Mako template.
has_page_default: True if the page is marked as default, False
otherwise.
results: A list of results into which violations will be added.
Side effect:
Adds Python violations to results.'

def _check_expression_python(self, python_code, start_offset, has_page_default, results):

    python_results = FileResults('')
    adjusted_python_code = textwrap.dedent(python_code)
    first_letter_match = re.search('\\w', python_code)
    adjusted_first_letter_match = re.search('\\w', adjusted_python_code)
    if ((first_letter_match is not None) and (adjusted_first_letter_match is not None)):
        start_offset += (first_letter_match.start() - adjusted_first_letter_match.start())
    python_code = adjusted_python_code
    root_node = self.python_linter.parse_python_code(python_code, python_results)
    self.python_linter.check_python_code_is_safe(python_code, root_node, python_results)
    if (root_node is not None):
        visitor = HtmlStringVisitor(python_code, python_results, True)
        visitor.visit(root_node)
        for unsafe_html_string_node in visitor.unsafe_html_string_nodes:
            python_results.violations.append(ExpressionRuleViolation(Rules.python_wrap_html, visitor.node_to_expression(unsafe_html_string_node)))
        if has_page_default:
            for over_escaped_entity_string_node in visitor.over_escaped_entity_string_nodes:
                python_results.violations.append(ExpressionRuleViolation(Rules.mako_html_entities, visitor.node_to_expression(over_escaped_entity_string_node)))
    python_results.prepare_results(python_code, line_comment_delim=self.LINE_COMMENT_DELIM)
    self._shift_and_add_violations(python_results, start_offset, results)
