• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Hekxsler / pudding / 18522040615

15 Oct 2025 08:00AM UTC coverage: 86.741% (-0.2%) from 86.918%
18522040615

push

github

web-flow
[all]: Linting

1086 of 1252 relevant lines covered (86.74%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
pudding/reader/reader.py
1
"""Module defining Reader class."""
2

3
import logging
1✔
4
from re import Match, Pattern
1✔
5

6
logger = logging.getLogger(__name__)
1✔
7

8

9
class Reader:
1✔
10
    """Base Reader class.
11

12
    :var current_pos: Current position in content.
13
    :var last_match: Last Match object or None if regex did not match.
14
    """
15

16
    current_pos = 0
1✔
17
    last_match: Match[str] | None = None
1✔
18

19
    def __init__(self, content: str) -> None:
1✔
20
        """Init class."""
21
        self.content = content
1✔
22
        self.endpos = len(content)
1✔
23

24
    @property
1✔
25
    def eof(self) -> bool:
1✔
26
        """Boolean if end of content has been reached."""
27
        return self.current_pos >= self.endpos
1✔
28

29
    @property
1✔
30
    def current_line_number(self) -> int:
1✔
31
        """Line number of the current position."""
32
        return self.content.count("\n", None, self.current_pos) + 1
×
33

34
    def _match(self, regex: Pattern[str]) -> Match[str] | None:
1✔
35
        """Match a regex to the content ahead and set the result as last_match.
36

37
        The attribute last_match will be set to the match object or None if it did not
38
        match the content ahead. If end of file has been reached, always return None.
39

40
        :param regex: The pattern to match.
41
        :returns: The match object or None.
42
        """
43
        logger.debug(
1✔
44
            "Trying to match /%s/ on %s...",
45
            regex.pattern,
46
            repr(self.content[self.current_pos : self.current_pos + 35]),
47
        )
48
        if self.eof:
1✔
49
            return None
1✔
50
        self.last_match = regex.match(self.content, self.current_pos)
1✔
51
        return self.last_match
1✔
52

53
    def find(self, regex: Pattern[str]) -> Match[str] | None:
1✔
54
        """Try matching a regex in the content ahead.
55

56
        :param regex: The pattern to match.
57
        :returns: The match object or None if it did not match.
58
        """
59
        return self._match(regex)
1✔
60

61
    def match(self, regex: Pattern[str]) -> Match[str] | None:
1✔
62
        """Try matching a regex to the content ahead and advance.
63

64
        If the pattern matches the current_pos is advanced by the length of the match.
65

66
        :param regex: The pattern to match.
67
        :returns: The match object or None if it did not match.
68
        """
69
        match = self._match(regex)
1✔
70
        if match is not None:
1✔
71
            self.current_pos += len(match.group(0))
1✔
72
        return match
1✔
73

74
    def would_match(self, regex: Pattern[str]) -> bool:
1✔
75
        """Test if a pattern would match.
76

77
        Test if a pattern would match the content ahead without advancing the current
78
        position or changing the last_match attribute of the reader.
79

80
        :param trigger: The trigger object.
81
        :returns: Boolean if trigger matches.
82
        """
83
        return regex.match(self.content, self.current_pos) is not None
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc