MCPcopy Create free account
hub / github.com/webpy/webpy / read_node

Method read_node

web/template.py:207–230  ·  view source on GitHub ↗

r"""Reads a node from the given text and returns the node and remaining text. >>> read_node = Parser().read_node >>> read_node('hello $name') (t'hello ', '$name') >>> read_node('$name') ($name, '')

(self, text)

Source from the content-addressed store, hash-verified

205 return LineNode(nodes), text
206
207 def read_node(self, text):
208 r"""Reads a node from the given text and returns the node and remaining text.
209
210 >>> read_node = Parser().read_node
211 >>> read_node('hello $name')
212 (t'hello ', '$name')
213 >>> read_node('$name')
214 ($name, '')
215 """
216 if text.startswith("$$"):
217 return TextNode("$"), text[2:]
218 elif text.startswith("$#"): # comment
219 line, text = splitline(text)
220 return TextNode("\n"), text
221 elif text.startswith("$"):
222 text = text[1:] # strip $
223 if text.startswith(":"):
224 escape = False
225 text = text[1:] # strip :
226 else:
227 escape = True
228 return self.read_expr(text, escape=escape)
229 else:
230 return self.read_text(text)
231
232 def read_text(self, text):
233 r"""Reads a text node from the given text.

Callers 1

readlineMethod · 0.95

Calls 4

read_exprMethod · 0.95
read_textMethod · 0.95
TextNodeClass · 0.85
splitlineFunction · 0.85

Tested by

no test coverage detected