[master] d95b853f2 Reduce duplication in vmodtool.py
Nils Goroll
nils.goroll at uplex.de
Tue Jun 13 13:27:09 UTC 2023
commit d95b853f20b6eb4e2cbc4287fc67027432ad52f6
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Tue Jun 13 15:10:50 2023 +0200
Reduce duplication in vmodtool.py
diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py
index 58fbc3041..4112e05e8 100755
--- a/lib/libvcc/vmodtool.py
+++ b/lib/libvcc/vmodtool.py
@@ -710,18 +710,9 @@ class EventStanza(Stanza):
jl.append(["$EVENT", "%s._event" % self.vcc.csn])
-class FunctionStanza(Stanza):
+class FunctionMethodStanzaBase(Stanza):
- ''' $Function TYPE name ( ARGUMENTS ) '''
-
- def parse(self):
- self.proto = ProtoType(self)
- self.rstlbl = '%s.%s()' % (self.vcc.modname, self.proto.name)
- self.vcc.contents.append(self)
- self.restrict = None
-
- def cstuff(self, fo, where):
- fo.write(self.proto.cproto(['VRT_CTX'], where))
+ ''' Base class for $Function and Method '''
def cstruct(self, fo, define):
self.fmt_cstruct_proto(fo, self.proto, define)
@@ -733,12 +724,29 @@ class FunctionStanza(Stanza):
self.restrict.rstdoc(fo, unused_man)
def json(self, jl):
- jl.append(["$FUNC", "%s" % self.proto.name])
self.proto.jsonproto(jl[-1], self.proto.cname())
if (self.restrict is not None):
self.restrict.json(jl)
+class FunctionStanza(FunctionMethodStanzaBase):
+
+ ''' $Function TYPE name ( ARGUMENTS ) '''
+
+ def parse(self):
+ self.proto = ProtoType(self)
+ self.rstlbl = '%s.%s()' % (self.vcc.modname, self.proto.name)
+ self.vcc.contents.append(self)
+ self.restrict = None
+
+ def cstuff(self, fo, where):
+ fo.write(self.proto.cproto(['VRT_CTX'], where))
+
+ def json(self, jl):
+ jl.append(["$FUNC", "%s" % self.proto.name])
+ super().json(jl)
+
+
class ObjectStanza(Stanza):
''' $Object TYPE class ( ARGUMENTS ) '''
@@ -828,7 +836,7 @@ class ObjectStanza(Stanza):
#######################################################################
-class MethodStanza(Stanza):
+class MethodStanza(FunctionMethodStanzaBase):
''' $Method TYPE . method ( ARGUMENTS ) '''
@@ -845,20 +853,9 @@ class MethodStanza(Stanza):
p.methods.append(self)
self.restrict = None
- def cstruct(self, fo, define):
- self.fmt_cstruct_proto(fo, self.proto, define)
-
- def rstdoc(self, fo, unused_man):
- super().rstdoc(fo,unused_man)
- if (self.restrict is not None):
- fo.write("\nRestricted to: ``%s``\n\n" % ', '.join(self.restrict.restrict_toks))
- self.restrict.rstdoc(fo, unused_man)
-
def json(self, jl):
jl.append(["$METHOD", self.proto.name[len(self.pfx)+1:]])
- self.proto.jsonproto(jl[-1], self.proto.cname())
- if (self.restrict is not None):
- self.restrict.json(jl)
+ super().json(jl)
class RestrictStanza(Stanza):
More information about the varnish-commit
mailing list