def _yield_replaced(self, string, splitter, ignore_errors=False): while splitter.identifier: yield unescape(string[:splitter.start]) try: value = self._get_variable(splitter) except DataError: if not ignore_errors: raise value = string[splitter.start:splitter.end] yield unic(value) string = string[splitter.end:] splitter = VariableSplitter(string) yield unescape(string)
def _replace_list(self, items, ignore_errors): for item in items: if self._cannot_have_variables(item): yield unescape(item) else: for value in self._replace_list_item(item, ignore_errors): yield value
def replace_string(self, string, ignore_errors=False): """Replaces variables from a string. Result is always a string.""" if not is_string(string): return unic(string) if self._cannot_have_variables(string): return unescape(string) return self._replace_string(string, ignore_errors=ignore_errors)
def _replace_scalar(self, item, splitter=None): if not splitter: splitter = VariableSplitter(item) if not splitter.identifier: return unescape(item) if splitter.is_variable(): return self._get_variable(splitter) return self._replace_string(item, splitter)
def UserLibrary(path): """Create a user library instance from given resource file. This is used by Libdoc. """ from robotide.lib.robot import utils from .arguments import ArgumentSpec from .userkeyword import UserLibrary as RuntimeUserLibrary resource = ResourceFileBuilder().build(path) ret = RuntimeUserLibrary(resource.keywords, path) for handler in ret.handlers: if handler.type != "error": handler.doc = utils.unescape(handler._doc) else: handler.arguments = ArgumentSpec(handler.longname) handler.doc = "*Creating keyword failed: %s*" % handler.error ret.doc = utils.unescape(resource.doc) return ret
def UserLibrary(path): """Create a user library instance from given resource file. This is used by Libdoc. """ from robotide.lib.robot import utils from .arguments import ArgumentSpec from .userkeyword import UserLibrary as RuntimeUserLibrary resource = ResourceFileBuilder().build(path) ret = RuntimeUserLibrary(resource.keywords, path) for handler in ret.handlers: if handler.type != 'error': handler.doc = utils.unescape(handler._doc) else: handler.arguments = ArgumentSpec(handler.longname) handler.doc = '*Creating keyword failed: %s*' % handler.error ret.doc = utils.unescape(resource.doc) return ret
def replace_scalar(self, item): """Replaces variables from a scalar item. If the item is not a string it is returned as is. If it is a ${scalar} variable its value is returned. Otherwise variables are replaced with 'replace_string'. Result may be any object. """ if self._cannot_have_variables(item): return unescape(item) return self._replace_scalar(item)
def _replace_list(self, items): for item in items: if self._cannot_have_variables(item): yield unescape(item) else: splitter = VariableSplitter(item) value = self._replace_scalar(item, splitter) if splitter.is_list_variable(): for v in value: yield v else: yield value
def _replace_scalar(self, item, splitter=None, ignore_errors=False): if not splitter: splitter = VariableSplitter(item) if not splitter.identifier: return unescape(item) if not splitter.is_variable(): return self._replace_string(item, splitter, ignore_errors) try: return self._get_variable(splitter) except DataError: if ignore_errors: return item raise
def _html(self, item): return html_format(unescape(item))
def _get_doc(self, res): if res.doc: return unescape(res.doc) return "Documentation for resource file ``%s``." % res.name
def _get_doc(self, kw): if self._resource and not isinstance(kw, UserErrorHandler): return unescape(kw.doc) return kw.doc