File: utils.py

package info (click to toggle)
mu-editor 1.0.3%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,440 kB
  • sloc: python: 16,321; makefile: 129; xml: 29; sh: 7
file content (41 lines) | stat: -rw-r--r-- 1,500 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Debug related utility functions for the Mu editor.

Copyright (c) Nicholas H.Tollervey and others (see the AUTHORS file).

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""


def is_breakpoint_line(code):
    """
    Return a boolean indication if the specified code from a single line can
    have a breakpoint added to it.

    Based entirely on simple but effective heuristics (see comments).
    """
    code = code.strip()
    if not code:
        return False
    # Can't set breakpoints on blank lines or comments.
    # TODO: Make this more robust.
    if code[0] == '#' or code[:3] == '"""' or code[:3] == "'''":
        return False
    # Can't set breakpoints on lines that end with opening (, { or [
    if code[-1] in ('(', '{', '['):
        return False
    # Can't set breakpoints on lines that contain only closing ), } or ]
    if len(code) == 1 and code in (')', '}', ']'):
        return False
    return True