Skip to content

Commit 74d8014

Browse files
committed
Move HelperHandlerRegistry to helper_registry.py
1 parent 5d0a888 commit 74d8014

File tree

4 files changed

+31
-29
lines changed

4 files changed

+31
-29
lines changed

pythonbpf/helper/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from .helper_utils import HelperHandlerRegistry, reset_scratch_pool
1+
from .helper_registry import HelperHandlerRegistry
2+
from .helper_utils import reset_scratch_pool
23
from .bpf_helper_handler import handle_helper_call
34
from .helpers import ktime, pid, deref, XDP_DROP, XDP_PASS
45

pythonbpf/helper/bpf_helper_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import ast
22
from llvmlite import ir
33
from enum import Enum
4+
5+
from .helper_registry import HelperHandlerRegistry
46
from .helper_utils import (
5-
HelperHandlerRegistry,
67
get_or_create_ptr_from_arg,
78
get_flags_val,
89
handle_fstring_print,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import Callable
2+
3+
4+
class HelperHandlerRegistry:
5+
"""Registry for BPF helpers"""
6+
7+
_handlers: dict[str, Callable] = {}
8+
9+
@classmethod
10+
def register(cls, helper_name):
11+
"""Decorator to register a handler function for a helper"""
12+
13+
def decorator(func):
14+
cls._handlers[helper_name] = func
15+
return func
16+
17+
return decorator
18+
19+
@classmethod
20+
def get_handler(cls, helper_name):
21+
"""Get the handler function for a helper"""
22+
return cls._handlers.get(helper_name)
23+
24+
@classmethod
25+
def has_handler(cls, helper_name):
26+
"""Check if a handler function is registered for a helper"""
27+
return helper_name in cls._handlers

pythonbpf/helper/helper_utils.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ast
22
import logging
3-
from collections.abc import Callable
43

54
from llvmlite import ir
65
from pythonbpf.expr import (
@@ -13,32 +12,6 @@
1312
logger = logging.getLogger(__name__)
1413

1514

16-
class HelperHandlerRegistry:
17-
"""Registry for BPF helpers"""
18-
19-
_handlers: dict[str, Callable] = {}
20-
21-
@classmethod
22-
def register(cls, helper_name):
23-
"""Decorator to register a handler function for a helper"""
24-
25-
def decorator(func):
26-
cls._handlers[helper_name] = func
27-
return func
28-
29-
return decorator
30-
31-
@classmethod
32-
def get_handler(cls, helper_name):
33-
"""Get the handler function for a helper"""
34-
return cls._handlers.get(helper_name)
35-
36-
@classmethod
37-
def has_handler(cls, helper_name):
38-
"""Check if a handler function is registered for a helper"""
39-
return helper_name in cls._handlers
40-
41-
4215
class ScratchPoolManager:
4316
"""Manage the temporary helper variables in local_sym_tab"""
4417

0 commit comments

Comments
 (0)