Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align API for Modest / Lexbor implementations #140

Open
JuroOravec opened this issue Oct 25, 2024 · 0 comments
Open

Align API for Modest / Lexbor implementations #140

JuroOravec opened this issue Oct 25, 2024 · 0 comments

Comments

@JuroOravec
Copy link
Collaborator

As I was looking at #138, I noticed in the codebase that the issue around decoding was already addressed for HTMLParser class (Modest impl), but not for LexborHMLParser (Lexbor impl).

Also it can be error prone, having to check two different places. So to make it easier to maintain, preferably there would be a single source of truth for the public API, while the implementation-specific C code would be abstracted away.

It could look maybe something like this:

class ModestParserImpl:
    def get_body(self, myhtml_tree_t* html_tree):
        cdef myhtml_tree_node_t* body
        body = myhtml_tree_get_node_body(html_tree)
		return body

class LexborParserImpl:
    ...

class HTMLParserABC:
    self.impl = None

    @property
    def body(self):
        cdef myhtml_tree_node_t* body
        body = self.impl.get_body(self.html_tree)

        if body != NULL:
            node = Node()
            node._init(body, self)
            return node

        return None

class HTMLParser(HTMLParserABC):
    impl = ModestParserImpl()

class HTMLParser(HTMLParserABC):
    self.impl = ParserImpl(self)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant