mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-01-07 21:40:36 +01:00
scanner: separate the parser from the actual protocol
Let's not leak anything related to XML parsing into the class we use as the actual protocol description.
This commit is contained in:
parent
4414c91fca
commit
5e6e4d8fc9
1 changed files with 9 additions and 4 deletions
|
|
@ -361,7 +361,12 @@ class XmlError(Exception):
|
|||
|
||||
|
||||
@attr.s
|
||||
class Protocol(xml.sax.handler.ContentHandler):
|
||||
class Protocol:
|
||||
interfaces: list[Interface] = attr.ib(factory=list)
|
||||
|
||||
|
||||
@attr.s
|
||||
class ProtocolParser(xml.sax.handler.ContentHandler):
|
||||
component: str = attr.ib()
|
||||
interfaces: list[Interface] = attr.ib(factory=list)
|
||||
|
||||
|
|
@ -613,17 +618,17 @@ class Protocol(xml.sax.handler.ContentHandler):
|
|||
pass
|
||||
|
||||
@classmethod
|
||||
def create(cls, component: str) -> "Protocol":
|
||||
def create(cls, component: str) -> "ProtocolParser":
|
||||
h = cls(component=component)
|
||||
return h
|
||||
|
||||
|
||||
def parse(protofile: Path, component: str) -> Protocol:
|
||||
proto = Protocol.create(component=component)
|
||||
proto = ProtocolParser.create(component=component)
|
||||
xml.sax.parse(os.fspath(protofile), proto)
|
||||
# We parse two times, once to fetch all the interfaces, then to parse the details
|
||||
xml.sax.parse(os.fspath(protofile), proto)
|
||||
return proto
|
||||
return Protocol(proto.interfaces)
|
||||
|
||||
|
||||
def generate_source(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue