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

Method readline

web/template.py:183–205  ·  view source on GitHub ↗

r"""Reads one line from the text. Newline is suppressed if the line ends with \. >>> readline = Parser().readline >>> readline('hello $name!\nbye!') ( , 'bye!') >>> readline('hello $name!\\\nbye!') (<line: [t'hello ', $name, t

(self, text)

Source from the content-addressed store, hash-verified

181 return SuiteNode(sections)
182
183 def readline(self, text):
184 r"""Reads one line from the text. Newline is suppressed if the line ends with \.
185
186 >>> readline = Parser().readline
187 >>> readline('hello $name!\nbye!')
188 (<line: [t'hello ', $name, t'!\n']>, 'bye!')
189 >>> readline('hello $name!\\\nbye!')
190 (<line: [t'hello ', $name, t'!']>, 'bye!')
191 >>> readline('$f()\n\n')
192 (<line: [$f(), t'\n']>, '\n')
193 """
194 line, text = splitline(text)
195
196 # suppress new line if line ends with \
197 if line.endswith("\\\n"):
198 line = line[:-2]
199
200 nodes = []
201 while line:
202 node, line = self.read_node(line)
203 nodes.append(node)
204
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.

Callers 2

read_sectionMethod · 0.95
read_varMethod · 0.95

Calls 4

read_nodeMethod · 0.95
splitlineFunction · 0.85
LineNodeClass · 0.85
appendMethod · 0.80

Tested by

no test coverage detected