def __init__(self, stream, default_style=None, default_flow_style=None, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None): Emitter.__init__(self, stream, canonical=canonical, indent=indent, width=width, allow_unicode=allow_unicode, line_break=line_break) Serializer.__init__(self, encoding=encoding, explicit_start=explicit_start, explicit_end=explicit_end, version=version, tags=tags) SzradmRepresenter.__init__(self, default_style=default_style, default_flow_style=default_flow_style) Resolver.__init__(self)
def __init__(self, stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None): Emitter.__init__(self, stream, canonical=canonical, indent=indent, width=width, allow_unicode=allow_unicode, line_break=line_break) Serializer.__init__(self, encoding=encoding, explicit_start=explicit_start, explicit_end=explicit_end, version=version, tags=tags) _EmptyNoneRepresenter.__init__(self, default_style=default_style, default_flow_style=default_flow_style) Resolver.__init__(self)
def __init__( self, stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True, ): Emitter.__init__( self, stream, canonical=canonical, indent=indent, width=width, allow_unicode=allow_unicode, line_break=line_break, ) Serializer.__init__( self, encoding=encoding, explicit_start=explicit_start, explicit_end=explicit_end, version=version, tags=tags, ) CustomRepresenter.__init__( self, default_style=default_style, default_flow_style=default_flow_style, sort_keys=sort_keys, ) Resolver.__init__(self)
def _write_styled_literal(self, string): """ Produce a properly formatted YAML string Properly format translation string based on string's style on the original source file using yaml.emitter.Emitter class. Args: string: An OpenString instance Returns: The formatted string. """ if string.flags is None: return string.string stream = StringIO() emitter = Emitter(stream, allow_unicode=True) indent = self.indent * (len(string.key.split('.')) + self.extra_indent) emitter.indent = indent # set best_width to `float(inf)` so that long strings are not broken # into multiple lines emitter.best_width = float('inf') analysis = emitter.analyze_scalar(string.string) style = string.flags.split(':')[-1] if style == '"': emitter.write_double_quoted(string.string) elif style == '\'': if analysis.allow_single_quoted: emitter.write_single_quoted(string.string) else: emitter.write_double_quoted(string.string) elif style == '': if analysis.allow_block_plain and analysis.allow_flow_plain: emitter.write_plain(string.string) else: emitter.write_double_quoted(string.string) elif style == '|': emitter.write_literal(string.string) elif style == '>': emitter.write_folded(string.string) translation = emitter.stream.getvalue() or string.string emitter.stream.close() return translation
def _write_styled_literal(self, string): """ Produce a properly formatted YAML string Properly format translation string based on string's style on the original source file using yaml.emitter.Emitter class. Args: string: An OpenString instance Returns: The formatted string. """ if string.flags is None: return string.string stream = StringIO() emitter = Emitter(stream, allow_unicode=True) indent = self.indent * (len(string.key.split('.')) + self.extra_indent) emitter.indent = indent # set best_width to `float(inf)` so that long strings are not broken # into multiple lines emitter.best_width = float('inf') analysis = emitter.analyze_scalar(string.string) style = string.flags.split(':')[-1] if style == '"': emitter.write_double_quoted(string.string) elif style == '\'': if analysis.allow_single_quoted: emitter.write_single_quoted(string.string) else: emitter.write_double_quoted(string.string) elif style == '': if analysis.allow_block_plain and analysis.allow_flow_plain: emitter.write_plain(string.string) else: emitter.write_double_quoted(string.string) elif style == '|': emitter.write_literal(string.string) elif style == '>': emitter.write_folded(string.string) translation = emitter.stream.getvalue() or string.string if translation.startswith(">-") and not translation.endswith("\n"): translation += "\n" emitter.stream.close() return translation