Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/certbot/certbot.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoona Hoikkala <joona@kuori.org>2019-08-18 12:12:23 +0300
committerJoona Hoikkala <joona@kuori.org>2019-08-18 14:31:54 +0300
commit864f06100a2d2a1679b47ef1e34377a29ee72b10 (patch)
treed0e259761d92c847c7960381f9dc270d7f7c272c
parent4975d0a273d490cf3d23dafc0b2a6d03ab8a0bec (diff)
Define initialization for different ParserNode classes
-rw-r--r--certbot-apache/certbot_apache/interfaces.py76
-rw-r--r--certbot-apache/certbot_apache/tests/parsernode_test.py44
2 files changed, 114 insertions, 6 deletions
diff --git a/certbot-apache/certbot_apache/interfaces.py b/certbot-apache/certbot_apache/interfaces.py
index c62885a03..08a749cd2 100644
--- a/certbot-apache/certbot_apache/interfaces.py
+++ b/certbot-apache/certbot_apache/interfaces.py
@@ -123,11 +123,20 @@ class ParserNode(object):
dirty: bool
# Filepath of the file where the configuration element for this ParserNode
- # object resides.
+ # object resides. This can be None if a configuration directive is defined in
+ # for example the httpd command line.
filepath: Optional[str]
"""
@abc.abstractmethod
+ def __init__(self, ancestor=None, filepath="", dirty=False): # pragma: no cover
+ """
+ Initializes the ParserNode instance, and sets the ParserNode specific
+ instance variables. This is not meant to be used directly, but through
+ specific classes implementing ParserNode interface.
+ """
+
+ @abc.abstractmethod
def save(self, msg):
"""
Save traverses the children, and attempts to write the AST to disk for
@@ -163,6 +172,20 @@ class CommentNode(ParserNode):
"""
+ # pylint: disable=super-init-not-called
+ @abc.abstractmethod
+ def __init__(self, comment, ancestor, filepath, dirty=False): # pragma: no cover
+ """
+ Initializes the CommentNode instance and sets its instance variables.
+
+ :param str comment: Contents of the comment.
+ :param BlockNode ancestor: BlockNode ancestor for this CommentNode.
+ :param str filepath: Filesystem path for the file where this CommentNode
+ does or should exist in the filesystem.
+ :param bool dirty: Boolean flag for denoting if this CommentNode has been
+ created or changed after the last save.
+ """
+
@six.add_metaclass(abc.ABCMeta)
class DirectiveNode(ParserNode):
@@ -172,6 +195,10 @@ class DirectiveNode(ParserNode):
single directives, it is not able to have child nodes and hence it is always
treated as a leaf node.
+ If a this directive was defined on the httpd command line, the ancestor instance
+ variable for this DirectiveNode should be None, and it should be inserted to the
+ beginning of root BlockNode children sequence.
+
DirectiveNode objects should have the following attributes:
# True if this DirectiveNode is enabled and False if it is inside of an
@@ -185,6 +212,26 @@ class DirectiveNode(ParserNode):
parameters: Tuple[str, ...]
"""
+ # pylint: disable=too-many-arguments, super-init-not-called
+ def __init__(self, name, parameters=(), ancestor=None, filepath="",
+ dirty=False, enabled=True): # pragma: no cover
+ """
+ Initializes the DirectiveNode instance and sets its instance variables.
+
+ :param name: Name or key of the DirectiveNode object.
+ :param tuple parameters: Tuple of str parameters for this DirectiveNode.
+ :param ancestor: BlockNode ancestor for this DirectiveNode, or None for
+ directives introduced at the httpd command line.
+ :param str filepath: Filesystem path for the file where this DirectiveNode
+ does or should exist in the filesystem, or None for directives introduced
+ in the httpd command line.
+ :param bool dirty: Boolean flag for denoting if this DirectiveNode has been
+ created or changed after the last save.
+ :param bool enabled: True if this DirectiveNode object is parsed in the active
+ configuration of the httpd. False if the DirectiveNode exists within a
+ unmatched conditional configuration block.
+
+ """
@abc.abstractmethod
def set_parameters(self, parameters):
@@ -238,8 +285,9 @@ class BlockNode(ParserNode):
# parsed, but its children should be flagged as disabled.
enabled: bool
- # Name, or key of the configuration directive
- name: str
+ # Name, or key of the configuration directive. If the BlockNode is the root
+ # configuration node, the name should be None.
+ name: Optional[str]
# Tuple of parameters of this ParserNode object, excluding whitespaces.
parameters: Tuple[str, ...]
@@ -249,6 +297,28 @@ class BlockNode(ParserNode):
children: Tuple[ParserNode, ...]
"""
+ # pylint: disable=too-many-arguments, super-init-not-called
+ @abc.abstractmethod
+ def __init__(self, name="", parameters=(), children=(), ancestor=None,
+ filepath="", dirty=False, enabled=True): # pragma: no cover
+ """
+ Initializes the BlockNode instance and sets its instance variables.
+
+ :param name: Name or key of the BlockNode object, or None for root
+ configuration node.
+ :param tuple parameters: Tuple of str parameters for this BlockNode.
+ :param tuple children: Tuple of ParserNode children for this BlockNode.
+ :param ancestor: BlockNode ancestor for this BlockNode, or None for root
+ configuration node.
+ :param str filepath: Filesystem path for the file where this BlockNode does
+ or should exist in the filesystem.
+ :param bool dirty: Boolean flag for denoting if this BlockNode has been
+ created or changed after the last save.
+ :param bool enabled: True if this BlockNode object is parsed in the active
+ configuration object by the httpd. False if the BlockNode exists within
+ a unmatched conditional configuration block.
+ """
+
@abc.abstractmethod
def add_child_block(self, name, parameters=None, position=None):
"""
diff --git a/certbot-apache/certbot_apache/tests/parsernode_test.py b/certbot-apache/certbot_apache/tests/parsernode_test.py
index 650146e96..705dc61a1 100644
--- a/certbot-apache/certbot_apache/tests/parsernode_test.py
+++ b/certbot-apache/certbot_apache/tests/parsernode_test.py
@@ -13,6 +13,15 @@ class DummyParserNode(interfaces.ParserNode):
dirty = False
filepath = None
+ def __init__(self, ancestor=None, filepath=str(), dirty=False):
+ """
+ Initializes the ParserNode instance.
+ """
+ super(DummyParserNode, self).__init__(ancestor, filepath, dirty)
+ self.ancestor = ancestor
+ self.dirty = dirty
+ self.filepath = filepath
+
def save(self, msg): # pragma: no cover
"""Save"""
pass
@@ -20,7 +29,13 @@ class DummyParserNode(interfaces.ParserNode):
class DummyCommentNode(DummyParserNode):
""" A dummy class implementing CommentNode interface """
- comment = ""
+
+ def __init__(self, comment, ancestor, filepath, dirty=False):
+ """
+ Initializes the CommentNode instance and sets its instance variables.
+ """
+ super(DummyCommentNode, self).__init__(ancestor, filepath, dirty)
+ self.comment = comment
class DummyDirectiveNode(DummyParserNode):
@@ -29,6 +44,17 @@ class DummyDirectiveNode(DummyParserNode):
enabled = True
name = ""
+ # pylint: disable=too-many-arguments
+ def __init__(self, name, parameters=(), ancestor=None, filepath="",
+ dirty=False, enabled=True):
+ """
+ Initializes the DirectiveNode instance and sets its instance variables.
+ """
+ super(DummyDirectiveNode, self).__init__(ancestor, filepath, dirty)
+ self.name = name
+ self.parameters = parameters
+ self.enabled = enabled
+
def set_parameters(self, parameters): # pragma: no cover
"""Set parameters"""
pass
@@ -41,6 +67,18 @@ class DummyBlockNode(DummyParserNode):
enabled = True
name = ""
+ # pylint: disable=too-many-arguments
+ def __init__(self, name="", parameters=(), children=(), ancestor=None,
+ filepath="", dirty=False, enabled=True):
+ """
+ Initializes the BlockNode instance and sets its instance variables.
+ """
+ super(DummyBlockNode, self).__init__(ancestor, filepath, dirty)
+ self.name = name
+ self.parameters = parameters
+ self.children = children
+ self.enabled = enabled
+
def add_child_block(self, name, parameters=None, position=None): # pragma: no cover
"""Add child block"""
pass
@@ -87,8 +125,8 @@ class ParserNodeTest(unittest.TestCase):
def test_dummy(self):
dummyblock = DummyBlockNode()
- dummydirective = DummyDirectiveNode()
- dummycomment = DummyCommentNode()
+ dummydirective = DummyDirectiveNode("Name")
+ dummycomment = DummyCommentNode("Comment", dummyblock, "/some/file")
if __name__ == "__main__":