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

rafalp / Misago / 9487666026

12 Jun 2024 06:16PM UTC coverage: 97.699% (-1.0%) from 98.716%
9487666026

push

github

web-flow
Replace forum options with account settings (#1742)

1947 of 1979 new or added lines in 68 files covered. (98.38%)

661 existing lines in 143 files now uncovered.

52601 of 53840 relevant lines covered (97.7%)

0.98 hits per line

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

84.62
/misago/parser/hooks/setup_parser_context.py
1
from typing import TYPE_CHECKING, Protocol
1✔
2

3
from ...plugins.hooks import FilterHook
1✔
4

5
if TYPE_CHECKING:
1✔
6
    from ..context import ParserContext
×
7

8

9
class SetupParserContextHookAction(Protocol):
1✔
10
    """
11
    A standard Misago function used to setup the Parser Context data class
12
    instance or the next filter function from another plugin.
13

14
    # Arguments
15

16
    ## `context: ParserContext`
17

18
    A `ParserContext` data class instance to setup.
19

20
    # Return value
21

22
    A `ParserContext` instance to use during parsing.
23
    """
24

25
    def __call__(self, context: "ParserContext") -> "ParserContext": ...
1✔
26

27

28
class SetupParserContextHookFilter(Protocol):
1✔
29
    """
30
    A function implemented by a plugin that can be registered in this hook.
31

32
    # Arguments
33

34
    ## `action: SetupParserContextHookAction`
35

36
    A standard Misago function used to setup the Parser Context data class
37
    instance or the next filter function from another plugin.
38

39
    See the [action](#action) section for details.
40

41
    ## `context: ParserContext`
42

43
    A `ParserContext` data class instance to setup.
44

45
    # Return value
46

47
    A `ParserContext` instance to use during parsing.
48
    """
49

50
    def __call__(
1✔
51
        self,
52
        action: SetupParserContextHookAction,
53
        context: "ParserContext",
54
    ) -> "ParserContext": ...
55

56

57
class SetupParserContextHook(
1✔
58
    FilterHook[SetupParserContextHookAction, SetupParserContextHookFilter]
59
):
60
    """
61
    This hook wraps the standard function that Misago uses to setup a `ParserContext`
62
    instance.
63

64
    # Example
65

66
    The code below implements a custom filter function that adds extra data to
67
    `plugin_data` dictionary on `ParserContext`:
68

69
    ```python
70
    from misago.parser.context import ParserContext
71

72

73
    @setup_parser_context_hook.append_filter
74
    def register_plugin_data_in_parser_context(
75
        action: SetupParserContextHookAction, context: ParserContext
76
    ) -> ParserContext:
77
        if context.request:
78
            context.plugin_data["my_plugin"] = request.my_plugin.get_parser_context()
79

80
        # Call the next function in chain
81
        return action(context)
82
    ```
83
    """
84

85
    __slots__ = FilterHook.__slots__
1✔
86

87
    def __call__(
1✔
88
        self,
89
        action: SetupParserContextHookAction,
90
        context: "ParserContext",
91
    ) -> "ParserContext":
UNCOV
92
        return super().__call__(action, context)
×
93

94

95
setup_parser_context_hook = SetupParserContextHook()
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