Creates object for an ordered list of ``apacheconfig.AbstractASTNode``s. Every configuration file's root should be a ``apacheconfig.ListNode``. Children can be ``apacheconfig.BlockNode`` or ``apacheconfig.LeafNode``. Args: raw (list): Data returned from ``apacheconfig.parser``.
| 128 | |
| 129 | |
| 130 | class ListNode(AbstractASTNode): |
| 131 | """Creates object for an ordered list of ``apacheconfig.AbstractASTNode``s. |
| 132 | |
| 133 | Every configuration file's root should be a ``apacheconfig.ListNode``. |
| 134 | Children can be ``apacheconfig.BlockNode`` or ``apacheconfig.LeafNode``. |
| 135 | |
| 136 | Args: |
| 137 | raw (list): Data returned from ``apacheconfig.parser``. To construct |
| 138 | from a string containing config directives, use the `parse` factory |
| 139 | function. |
| 140 | |
| 141 | Raises: |
| 142 | ApacheConfigError: If `raw` is not formed as expected. In particular, |
| 143 | if `raw` is too short, or has the wrong `typestring`, or if |
| 144 | one of this list's children is not formed as expected. |
| 145 | """ |
| 146 | def __init__(self, raw, parser): |
| 147 | if len(raw) < 2: |
| 148 | raise error.ApacheConfigError( |
| 149 | "Expected properly-formatted `contents` data returned from " |
| 150 | "``apacheconfig.parser``. Got a list that is too short.") |
| 151 | self._type = raw[0] |
| 152 | if self._type != "contents": |
| 153 | raise error.ApacheConfigError( |
| 154 | "Expected properly-formatted `contents` data returned from " |
| 155 | "``apacheconfig.parser``. First element of data is not " |
| 156 | "\"contents\" typestring.") |
| 157 | self._contents = [] |
| 158 | self._trailing_whitespace = "" |
| 159 | self._parser = parser |
| 160 | for elem in raw[1:]: |
| 161 | if isinstance(elem, six.string_types) and elem.isspace(): |
| 162 | self._trailing_whitespace = elem |
| 163 | elif elem[0] == "block": |
| 164 | self._contents.append(BlockNode(elem, parser)) |
| 165 | elif elem[0] == "contents": |
| 166 | raise error.ApacheConfigError( |
| 167 | "Expected properly-formatted `contents` data returned " |
| 168 | "from ``apacheconfig.parser``. Got `contents` data as " |
| 169 | "a child of this `contents` data.") |
| 170 | else: |
| 171 | self._contents.append(LeafNode(elem)) |
| 172 | |
| 173 | @classmethod |
| 174 | def parse(cls, raw_str, parser): |
| 175 | """Factory for :class:`apacheconfig.ListNode` from a config string. |
| 176 | |
| 177 | Args: |
| 178 | raw_str (str): Config string to parse. |
| 179 | parser (:class:`apacheconfig.ApacheConfigParser`): parser object |
| 180 | to use. |
| 181 | Returns: |
| 182 | :class:`apacheconfig.ListNode` containing data parsed from |
| 183 | ``raw_str``. |
| 184 | """ |
| 185 | raw = parser.parse(raw_str) |
| 186 | return cls(raw, parser) |
| 187 |
no outgoing calls
no test coverage detected
searching dependent graphs…