text
stringlengths
0
828
:param data | <variant>
xparent | <xml.etree.ElementTree.Element> || None
:return <xml.etree.ElementTree.Element>
""""""
if xparent is not None:
elem = ElementTree.SubElement(xparent, 'list')
else:
elem = ElementTree.Element('list')
for item in data:
XmlDataIO.toXml(item, elem)
return elem"
3797,"def load(self, elem):
""""""
Converts the inputted set tag to Python.
:param elem | <xml.etree.ElementTree>
:return <set>
""""""
self.testTag(elem, 'set')
out = set()
for xitem in elem:
out.add(XmlDataIO.fromXml(xitem))
return out"
3798,"def load(self, elem):
""""""
Converts the inputted string tag to Python.
:param elem | <xml.etree.ElementTree>
:return <str>
""""""
self.testTag(elem, 'str')
return elem.text if elem.text is not None else ''"
3799,"def template_substitute(text, **kwargs):
""""""
Replace placeholders in text by using the data mapping.
Other placeholders that is not represented by data is left untouched.
:param text: Text to search and replace placeholders.
:param data: Data mapping/dict for placeholder key and values.
:return: Potentially modified text with replaced placeholders.
""""""
for name, value in kwargs.items():
placeholder_pattern = ""{%s}"" % name
if placeholder_pattern in text:
text = text.replace(placeholder_pattern, value)
return text"
3800,"def text_remove_empty_lines(text):
""""""
Whitespace normalization:
- Strip empty lines
- Strip trailing whitespace
""""""
lines = [ line.rstrip() for line in text.splitlines() if line.strip() ]
return ""\n"".join(lines)"
3801,"def text_normalize(text):
""""""
Whitespace normalization:
- Strip empty lines
- Strip leading whitespace in a line
- Strip trailing whitespace in a line
- Normalize line endings
""""""
# if not isinstance(text, str):
if isinstance(text, bytes):
# -- MAYBE: command.ouput => bytes, encoded stream output.
text = codecs.decode(text)
lines = [ line.strip() for line in text.splitlines() if line.strip() ]
return ""\n"".join(lines)"
3802,"def _wva(values, weights):
"""""" Calculates a weighted average
""""""
assert len(values) == len(weights) and len(weights) > 0
return sum([mul(*x) for x in zip(values, weights)]) / sum(weights)"
3803,"def mode_interactive(options):
""""""Interactive Mode: terminal prompts repeatedly for a url to fetch""""""
articles = set()
failures = set()
url = input('Enter a URL: ')
while url != '':
article = _get_article(url=url, bodyLines=options.bodyLines, debug=options.debug)
if (article):
articles.add(article)
else:
failures.add(url)
url = input('Enter a URL (press enter to end): ')
_output(articles, options.outputFile, failures, options.failureFile)"
3804,"def mode_clipboard_watch(options):
""""""Clipboard Watch Mode: watches for a new string on the clipboard, and tries to fetch that URL""""""
articles = set()
failures = set()