diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/python/PyYAML/py2/yaml | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/PyYAML/py2/yaml')
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/__init__.py | 268 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/_yaml.h | 2 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/_yaml.pxd | 42 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/_yaml.pyx | 78 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/composer.py | 4 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/constructor.py | 312 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/cyaml.py | 56 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/dumper.py | 18 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/emitter.py | 22 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/loader.py | 48 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/reader.py | 24 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/representer.py | 16 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/resolver.py | 4 | ||||
-rw-r--r-- | contrib/python/PyYAML/py2/yaml/scanner.py | 32 |
14 files changed, 463 insertions, 463 deletions
diff --git a/contrib/python/PyYAML/py2/yaml/__init__.py b/contrib/python/PyYAML/py2/yaml/__init__.py index 3c988198d5..72d4f23eff 100644 --- a/contrib/python/PyYAML/py2/yaml/__init__.py +++ b/contrib/python/PyYAML/py2/yaml/__init__.py @@ -8,7 +8,7 @@ from nodes import * from loader import * from dumper import * -__version__ = '5.4.1' +__version__ = '5.4.1' try: from cyaml import * @@ -16,45 +16,45 @@ try: except ImportError: __with_libyaml__ = False - -#------------------------------------------------------------------------------ -# Warnings control -#------------------------------------------------------------------------------ - -# 'Global' warnings state: -_warnings_enabled = { - 'YAMLLoadWarning': True, -} - -# Get or set global warnings' state -def warnings(settings=None): - if settings is None: - return _warnings_enabled - - if type(settings) is dict: - for key in settings: - if key in _warnings_enabled: - _warnings_enabled[key] = settings[key] - -# Warn when load() is called without Loader=... -class YAMLLoadWarning(RuntimeWarning): - pass - -def load_warning(method): - if _warnings_enabled['YAMLLoadWarning'] is False: - return - - import warnings - - message = ( - "calling yaml.%s() without Loader=... is deprecated, as the " - "default Loader is unsafe. Please read " - "https://msg.pyyaml.org/load for full details." - ) % method - - warnings.warn(message, YAMLLoadWarning, stacklevel=3) - -#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# Warnings control +#------------------------------------------------------------------------------ + +# 'Global' warnings state: +_warnings_enabled = { + 'YAMLLoadWarning': True, +} + +# Get or set global warnings' state +def warnings(settings=None): + if settings is None: + return _warnings_enabled + + if type(settings) is dict: + for key in settings: + if key in _warnings_enabled: + _warnings_enabled[key] = settings[key] + +# Warn when load() is called without Loader=... +class YAMLLoadWarning(RuntimeWarning): + pass + +def load_warning(method): + if _warnings_enabled['YAMLLoadWarning'] is False: + return + + import warnings + + message = ( + "calling yaml.%s() without Loader=... is deprecated, as the " + "default Loader is unsafe. Please read " + "https://msg.pyyaml.org/load for full details." + ) % method + + warnings.warn(message, YAMLLoadWarning, stacklevel=3) + +#------------------------------------------------------------------------------ def scan(stream, Loader=Loader): """ Scan a YAML stream and produce scanning tokens. @@ -100,30 +100,30 @@ def compose_all(stream, Loader=Loader): finally: loader.dispose() -def load(stream, Loader=None): +def load(stream, Loader=None): """ Parse the first YAML document in a stream and produce the corresponding Python object. """ - if Loader is None: - load_warning('load') - Loader = FullLoader - + if Loader is None: + load_warning('load') + Loader = FullLoader + loader = Loader(stream) try: return loader.get_single_data() finally: loader.dispose() -def load_all(stream, Loader=None): +def load_all(stream, Loader=None): """ Parse all YAML documents in a stream and produce corresponding Python objects. """ - if Loader is None: - load_warning('load_all') - Loader = FullLoader - + if Loader is None: + load_warning('load_all') + Loader = FullLoader + loader = Loader(stream) try: while loader.check_data(): @@ -131,33 +131,33 @@ def load_all(stream, Loader=None): finally: loader.dispose() -def full_load(stream): - """ - Parse the first YAML document in a stream - and produce the corresponding Python object. - - Resolve all tags except those known to be - unsafe on untrusted input. - """ - return load(stream, FullLoader) - -def full_load_all(stream): - """ - Parse all YAML documents in a stream - and produce corresponding Python objects. - - Resolve all tags except those known to be - unsafe on untrusted input. - """ - return load_all(stream, FullLoader) - +def full_load(stream): + """ + Parse the first YAML document in a stream + and produce the corresponding Python object. + + Resolve all tags except those known to be + unsafe on untrusted input. + """ + return load(stream, FullLoader) + +def full_load_all(stream): + """ + Parse all YAML documents in a stream + and produce corresponding Python objects. + + Resolve all tags except those known to be + unsafe on untrusted input. + """ + return load_all(stream, FullLoader) + def safe_load(stream): """ Parse the first YAML document in a stream and produce the corresponding Python object. - - Resolve only basic YAML tags. This is known - to be safe for untrusted input. + + Resolve only basic YAML tags. This is known + to be safe for untrusted input. """ return load(stream, SafeLoader) @@ -165,32 +165,32 @@ def safe_load_all(stream): """ Parse all YAML documents in a stream and produce corresponding Python objects. - - Resolve only basic YAML tags. This is known - to be safe for untrusted input. + + Resolve only basic YAML tags. This is known + to be safe for untrusted input. """ return load_all(stream, SafeLoader) -def unsafe_load(stream): - """ - Parse the first YAML document in a stream - and produce the corresponding Python object. - - Resolve all tags, even those known to be - unsafe on untrusted input. - """ - return load(stream, UnsafeLoader) - -def unsafe_load_all(stream): - """ - Parse all YAML documents in a stream - and produce corresponding Python objects. - - Resolve all tags, even those known to be - unsafe on untrusted input. - """ - return load_all(stream, UnsafeLoader) - +def unsafe_load(stream): + """ + Parse the first YAML document in a stream + and produce the corresponding Python object. + + Resolve all tags, even those known to be + unsafe on untrusted input. + """ + return load(stream, UnsafeLoader) + +def unsafe_load_all(stream): + """ + Parse all YAML documents in a stream + and produce corresponding Python objects. + + Resolve all tags, even those known to be + unsafe on untrusted input. + """ + return load_all(stream, UnsafeLoader) + def emit(events, stream=None, Dumper=Dumper, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None): @@ -252,11 +252,11 @@ def serialize(node, stream=None, Dumper=Dumper, **kwds): return serialize_all([node], stream, Dumper=Dumper, **kwds) def dump_all(documents, stream=None, Dumper=Dumper, - default_style=None, default_flow_style=False, + default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding='utf-8', explicit_start=None, explicit_end=None, - version=None, tags=None, sort_keys=True): + version=None, tags=None, sort_keys=True): """ Serialize a sequence of Python objects into a YAML stream. If stream is None, return the produced string instead. @@ -274,7 +274,7 @@ def dump_all(documents, stream=None, Dumper=Dumper, canonical=canonical, indent=indent, width=width, allow_unicode=allow_unicode, line_break=line_break, encoding=encoding, version=version, tags=tags, - explicit_start=explicit_start, explicit_end=explicit_end, sort_keys=sort_keys) + explicit_start=explicit_start, explicit_end=explicit_end, sort_keys=sort_keys) try: dumper.open() for data in documents: @@ -309,62 +309,62 @@ def safe_dump(data, stream=None, **kwds): return dump_all([data], stream, Dumper=SafeDumper, **kwds) def add_implicit_resolver(tag, regexp, first=None, - Loader=None, Dumper=Dumper): + Loader=None, Dumper=Dumper): """ Add an implicit scalar detector. If an implicit scalar value matches the given regexp, the corresponding tag is assigned to the scalar. first is a sequence of possible initial characters or None. """ - if Loader is None: - loader.Loader.add_implicit_resolver(tag, regexp, first) - loader.FullLoader.add_implicit_resolver(tag, regexp, first) - loader.UnsafeLoader.add_implicit_resolver(tag, regexp, first) - else: - Loader.add_implicit_resolver(tag, regexp, first) + if Loader is None: + loader.Loader.add_implicit_resolver(tag, regexp, first) + loader.FullLoader.add_implicit_resolver(tag, regexp, first) + loader.UnsafeLoader.add_implicit_resolver(tag, regexp, first) + else: + Loader.add_implicit_resolver(tag, regexp, first) Dumper.add_implicit_resolver(tag, regexp, first) -def add_path_resolver(tag, path, kind=None, Loader=None, Dumper=Dumper): +def add_path_resolver(tag, path, kind=None, Loader=None, Dumper=Dumper): """ Add a path based resolver for the given tag. A path is a list of keys that forms a path to a node in the representation tree. Keys can be string values, integers, or None. """ - if Loader is None: - loader.Loader.add_path_resolver(tag, path, kind) - loader.FullLoader.add_path_resolver(tag, path, kind) - loader.UnsafeLoader.add_path_resolver(tag, path, kind) - else: - Loader.add_path_resolver(tag, path, kind) + if Loader is None: + loader.Loader.add_path_resolver(tag, path, kind) + loader.FullLoader.add_path_resolver(tag, path, kind) + loader.UnsafeLoader.add_path_resolver(tag, path, kind) + else: + Loader.add_path_resolver(tag, path, kind) Dumper.add_path_resolver(tag, path, kind) -def add_constructor(tag, constructor, Loader=None): +def add_constructor(tag, constructor, Loader=None): """ Add a constructor for the given tag. Constructor is a function that accepts a Loader instance and a node object and produces the corresponding Python object. """ - if Loader is None: - loader.Loader.add_constructor(tag, constructor) - loader.FullLoader.add_constructor(tag, constructor) - loader.UnsafeLoader.add_constructor(tag, constructor) - else: - Loader.add_constructor(tag, constructor) + if Loader is None: + loader.Loader.add_constructor(tag, constructor) + loader.FullLoader.add_constructor(tag, constructor) + loader.UnsafeLoader.add_constructor(tag, constructor) + else: + Loader.add_constructor(tag, constructor) -def add_multi_constructor(tag_prefix, multi_constructor, Loader=None): +def add_multi_constructor(tag_prefix, multi_constructor, Loader=None): """ Add a multi-constructor for the given tag prefix. Multi-constructor is called for a node if its tag starts with tag_prefix. Multi-constructor accepts a Loader instance, a tag suffix, and a node object and produces the corresponding Python object. """ - if Loader is None: - loader.Loader.add_multi_constructor(tag_prefix, multi_constructor) - loader.FullLoader.add_multi_constructor(tag_prefix, multi_constructor) - loader.UnsafeLoader.add_multi_constructor(tag_prefix, multi_constructor) - else: - Loader.add_multi_constructor(tag_prefix, multi_constructor) + if Loader is None: + loader.Loader.add_multi_constructor(tag_prefix, multi_constructor) + loader.FullLoader.add_multi_constructor(tag_prefix, multi_constructor) + loader.UnsafeLoader.add_multi_constructor(tag_prefix, multi_constructor) + else: + Loader.add_multi_constructor(tag_prefix, multi_constructor) def add_representer(data_type, representer, Dumper=Dumper): """ @@ -391,12 +391,12 @@ class YAMLObjectMetaclass(type): def __init__(cls, name, bases, kwds): super(YAMLObjectMetaclass, cls).__init__(name, bases, kwds) if 'yaml_tag' in kwds and kwds['yaml_tag'] is not None: - if isinstance(cls.yaml_loader, list): - for loader in cls.yaml_loader: - loader.add_constructor(cls.yaml_tag, cls.from_yaml) - else: - cls.yaml_loader.add_constructor(cls.yaml_tag, cls.from_yaml) - + if isinstance(cls.yaml_loader, list): + for loader in cls.yaml_loader: + loader.add_constructor(cls.yaml_tag, cls.from_yaml) + else: + cls.yaml_loader.add_constructor(cls.yaml_tag, cls.from_yaml) + cls.yaml_dumper.add_representer(cls, cls.to_yaml) class YAMLObject(object): @@ -408,7 +408,7 @@ class YAMLObject(object): __metaclass__ = YAMLObjectMetaclass __slots__ = () # no direct instantiation, so allow immutable subclasses - yaml_loader = [Loader, FullLoader, UnsafeLoader] + yaml_loader = [Loader, FullLoader, UnsafeLoader] yaml_dumper = Dumper yaml_tag = None diff --git a/contrib/python/PyYAML/py2/yaml/_yaml.h b/contrib/python/PyYAML/py2/yaml/_yaml.h index 21fd6a991b..2d593e7f70 100644 --- a/contrib/python/PyYAML/py2/yaml/_yaml.h +++ b/contrib/python/PyYAML/py2/yaml/_yaml.h @@ -3,7 +3,7 @@ #if PY_MAJOR_VERSION < 3 -#define PyUnicode_FromString(s) PyUnicode_DecodeUTF8((s), strlen(s), "strict") +#define PyUnicode_FromString(s) PyUnicode_DecodeUTF8((s), strlen(s), "strict") #else diff --git a/contrib/python/PyYAML/py2/yaml/_yaml.pxd b/contrib/python/PyYAML/py2/yaml/_yaml.pxd index 7937c9db51..e6913b5847 100644 --- a/contrib/python/PyYAML/py2/yaml/_yaml.pxd +++ b/contrib/python/PyYAML/py2/yaml/_yaml.pxd @@ -1,5 +1,5 @@ -cdef extern from "_yaml.h": +cdef extern from "_yaml.h": void malloc(int l) void memcpy(char *d, char *s, int l) @@ -85,22 +85,22 @@ cdef extern from "_yaml.h": YAML_MAPPING_START_EVENT YAML_MAPPING_END_EVENT - ctypedef int yaml_read_handler_t(void *data, char *buffer, + ctypedef int yaml_read_handler_t(void *data, char *buffer, size_t size, size_t *size_read) except 0 - ctypedef int yaml_write_handler_t(void *data, char *buffer, + ctypedef int yaml_write_handler_t(void *data, char *buffer, size_t size) except 0 ctypedef struct yaml_mark_t: - size_t index - size_t line - size_t column + size_t index + size_t line + size_t column ctypedef struct yaml_version_directive_t: int major int minor ctypedef struct yaml_tag_directive_t: - char *handle - char *prefix + char *handle + char *prefix ctypedef struct _yaml_token_stream_start_data_t: yaml_encoding_t encoding @@ -109,18 +109,18 @@ cdef extern from "_yaml.h": ctypedef struct _yaml_token_anchor_data_t: char *value ctypedef struct _yaml_token_tag_data_t: - char *handle - char *suffix + char *handle + char *suffix ctypedef struct _yaml_token_scalar_data_t: char *value - size_t length + size_t length yaml_scalar_style_t style ctypedef struct _yaml_token_version_directive_data_t: int major int minor ctypedef struct _yaml_token_tag_directive_data_t: - char *handle - char *prefix + char *handle + char *prefix ctypedef union _yaml_token_data_t: _yaml_token_stream_start_data_t stream_start _yaml_token_alias_data_t alias @@ -152,7 +152,7 @@ cdef extern from "_yaml.h": char *anchor char *tag char *value - size_t length + size_t length int plain_implicit int quoted_implicit yaml_scalar_style_t style @@ -183,7 +183,7 @@ cdef extern from "_yaml.h": ctypedef struct yaml_parser_t: yaml_error_type_t error char *problem - size_t problem_offset + size_t problem_offset int problem_value yaml_mark_t problem_mark char *context @@ -208,23 +208,23 @@ cdef extern from "_yaml.h": int implicit) int yaml_document_end_event_initialize(yaml_event_t *event, int implicit) - int yaml_alias_event_initialize(yaml_event_t *event, char *anchor) + int yaml_alias_event_initialize(yaml_event_t *event, char *anchor) int yaml_scalar_event_initialize(yaml_event_t *event, - char *anchor, char *tag, char *value, size_t length, + char *anchor, char *tag, char *value, size_t length, int plain_implicit, int quoted_implicit, yaml_scalar_style_t style) int yaml_sequence_start_event_initialize(yaml_event_t *event, - char *anchor, char *tag, int implicit, yaml_sequence_style_t style) + char *anchor, char *tag, int implicit, yaml_sequence_style_t style) int yaml_sequence_end_event_initialize(yaml_event_t *event) int yaml_mapping_start_event_initialize(yaml_event_t *event, - char *anchor, char *tag, int implicit, yaml_mapping_style_t style) + char *anchor, char *tag, int implicit, yaml_mapping_style_t style) int yaml_mapping_end_event_initialize(yaml_event_t *event) void yaml_event_delete(yaml_event_t *event) int yaml_parser_initialize(yaml_parser_t *parser) void yaml_parser_delete(yaml_parser_t *parser) void yaml_parser_set_input_string(yaml_parser_t *parser, - char *input, size_t size) + char *input, size_t size) void yaml_parser_set_input(yaml_parser_t *parser, yaml_read_handler_t *handler, void *data) void yaml_parser_set_encoding(yaml_parser_t *parser, @@ -235,7 +235,7 @@ cdef extern from "_yaml.h": int yaml_emitter_initialize(yaml_emitter_t *emitter) void yaml_emitter_delete(yaml_emitter_t *emitter) void yaml_emitter_set_output_string(yaml_emitter_t *emitter, - char *output, size_t size, size_t *size_written) + char *output, size_t size, size_t *size_written) void yaml_emitter_set_output(yaml_emitter_t *emitter, yaml_write_handler_t *handler, void *data) void yaml_emitter_set_encoding(yaml_emitter_t *emitter, diff --git a/contrib/python/PyYAML/py2/yaml/_yaml.pyx b/contrib/python/PyYAML/py2/yaml/_yaml.pyx index ff4efe80b5..9a8daeecbf 100644 --- a/contrib/python/PyYAML/py2/yaml/_yaml.pyx +++ b/contrib/python/PyYAML/py2/yaml/_yaml.pyx @@ -2,7 +2,7 @@ import yaml def get_version_string(): - cdef char *value + cdef char *value value = yaml_get_version_string() if PY_MAJOR_VERSION < 3: return value @@ -63,13 +63,13 @@ MappingNode = yaml.nodes.MappingNode cdef class Mark: cdef readonly object name - cdef readonly size_t index - cdef readonly size_t line - cdef readonly size_t column + cdef readonly size_t index + cdef readonly size_t line + cdef readonly size_t column cdef readonly buffer cdef readonly pointer - def __init__(self, object name, size_t index, size_t line, size_t column, + def __init__(self, object name, size_t index, size_t line, size_t column, object buffer, object pointer): self.name = name self.index = index @@ -255,8 +255,8 @@ cdef class CParser: cdef object current_event cdef object anchors cdef object stream_cache - cdef int stream_cache_len - cdef int stream_cache_pos + cdef int stream_cache_len + cdef int stream_cache_pos cdef int unicode_source def __init__(self, stream): @@ -302,7 +302,7 @@ cdef class CParser: else: raise TypeError(u"a string or stream input is required") self.stream = stream - yaml_parser_set_input_string(&self.parser, PyString_AS_STRING(stream), PyString_GET_SIZE(stream)) + yaml_parser_set_input_string(&self.parser, PyString_AS_STRING(stream), PyString_GET_SIZE(stream)) self.current_token = None self.current_event = None self.anchors = {} @@ -414,8 +414,8 @@ cdef class CParser: token.data.version_directive.minor), start_mark, end_mark) elif token.type == YAML_TAG_DIRECTIVE_TOKEN: - handle = PyUnicode_FromString(token.data.tag_directive.handle) - prefix = PyUnicode_FromString(token.data.tag_directive.prefix) + handle = PyUnicode_FromString(token.data.tag_directive.handle) + prefix = PyUnicode_FromString(token.data.tag_directive.prefix) return DirectiveToken(u"TAG", (handle, prefix), start_mark, end_mark) elif token.type == YAML_DOCUMENT_START_TOKEN: @@ -451,13 +451,13 @@ cdef class CParser: value = PyUnicode_FromString(token.data.anchor.value) return AnchorToken(value, start_mark, end_mark) elif token.type == YAML_TAG_TOKEN: - handle = PyUnicode_FromString(token.data.tag.handle) - suffix = PyUnicode_FromString(token.data.tag.suffix) + handle = PyUnicode_FromString(token.data.tag.handle) + suffix = PyUnicode_FromString(token.data.tag.suffix) if not handle: handle = None return TagToken((handle, suffix), start_mark, end_mark) elif token.type == YAML_SCALAR_TOKEN: - value = PyUnicode_DecodeUTF8(token.data.scalar.value, + value = PyUnicode_DecodeUTF8(token.data.scalar.value, token.data.scalar.length, 'strict') plain = False style = None @@ -571,8 +571,8 @@ cdef class CParser: tags = {} tag_directive = event.data.document_start.tag_directives.start while tag_directive != event.data.document_start.tag_directives.end: - handle = PyUnicode_FromString(tag_directive.handle) - prefix = PyUnicode_FromString(tag_directive.prefix) + handle = PyUnicode_FromString(tag_directive.handle) + prefix = PyUnicode_FromString(tag_directive.prefix) tags[handle] = prefix tag_directive = tag_directive+1 return DocumentStartEvent(start_mark, end_mark, @@ -592,7 +592,7 @@ cdef class CParser: tag = None if event.data.scalar.tag != NULL: tag = PyUnicode_FromString(event.data.scalar.tag) - value = PyUnicode_DecodeUTF8(event.data.scalar.value, + value = PyUnicode_DecodeUTF8(event.data.scalar.value, event.data.scalar.length, 'strict') plain_implicit = False if event.data.scalar.plain_implicit == 1: @@ -762,11 +762,11 @@ cdef class CParser: self.parsed_event.start_mark.column, None, None) if PY_MAJOR_VERSION < 3: - raise ComposerError("found duplicate anchor; first occurrence", - self.anchors[anchor].start_mark, "second occurrence", mark) + raise ComposerError("found duplicate anchor; first occurrence", + self.anchors[anchor].start_mark, "second occurrence", mark) else: - raise ComposerError(u"found duplicate anchor; first occurrence", - self.anchors[anchor].start_mark, u"second occurrence", mark) + raise ComposerError(u"found duplicate anchor; first occurrence", + self.anchors[anchor].start_mark, u"second occurrence", mark) self.descend_resolver(parent, index) if self.parsed_event.type == YAML_SCALAR_EVENT: node = self._compose_scalar_node(anchor) @@ -788,7 +788,7 @@ cdef class CParser: self.parsed_event.end_mark.line, self.parsed_event.end_mark.column, None, None) - value = PyUnicode_DecodeUTF8(self.parsed_event.data.scalar.value, + value = PyUnicode_DecodeUTF8(self.parsed_event.data.scalar.value, self.parsed_event.data.scalar.length, 'strict') plain_implicit = False if self.parsed_event.data.scalar.plain_implicit == 1: @@ -905,7 +905,7 @@ cdef class CParser: raise error return 1 -cdef int input_handler(void *data, char *buffer, size_t size, size_t *read) except 0: +cdef int input_handler(void *data, char *buffer, size_t size, size_t *read) except 0: cdef CParser parser parser = <CParser>data if parser.stream_cache is None: @@ -924,7 +924,7 @@ cdef int input_handler(void *data, char *buffer, size_t size, size_t *read) exce if (parser.stream_cache_len - parser.stream_cache_pos) < size: size = parser.stream_cache_len - parser.stream_cache_pos if size > 0: - memcpy(buffer, PyString_AS_STRING(parser.stream_cache) + memcpy(buffer, PyString_AS_STRING(parser.stream_cache) + parser.stream_cache_pos, size) read[0] = size parser.stream_cache_pos += size @@ -964,7 +964,7 @@ cdef class CEmitter: if hasattr(stream, u'encoding'): self.dump_unicode = 1 self.use_encoding = encoding - yaml_emitter_set_output(&self.emitter, output_handler, <void *>self) + yaml_emitter_set_output(&self.emitter, output_handler, <void *>self) if canonical: yaml_emitter_set_canonical(&self.emitter, 1) if indent is not None: @@ -1071,7 +1071,7 @@ cdef class CEmitter: raise TypeError("tag handle must be a string") else: raise TypeError(u"tag handle must be a string") - tag_directives_end.handle = PyString_AS_STRING(handle) + tag_directives_end.handle = PyString_AS_STRING(handle) if PyUnicode_CheckExact(prefix): prefix = PyUnicode_AsUTF8String(prefix) cache.append(prefix) @@ -1080,7 +1080,7 @@ cdef class CEmitter: raise TypeError("tag prefix must be a string") else: raise TypeError(u"tag prefix must be a string") - tag_directives_end.prefix = PyString_AS_STRING(prefix) + tag_directives_end.prefix = PyString_AS_STRING(prefix) tag_directives_end = tag_directives_end+1 implicit = 1 if event_object.explicit: @@ -1104,7 +1104,7 @@ cdef class CEmitter: else: raise TypeError(u"anchor must be a string") anchor = PyString_AS_STRING(anchor_object) - if yaml_alias_event_initialize(event, anchor) == 0: + if yaml_alias_event_initialize(event, anchor) == 0: raise MemoryError elif event_class is ScalarEvent: anchor = NULL @@ -1154,7 +1154,7 @@ cdef class CEmitter: scalar_style = YAML_LITERAL_SCALAR_STYLE elif style_object == ">" or style_object == u">": scalar_style = YAML_FOLDED_SCALAR_STYLE - if yaml_scalar_event_initialize(event, anchor, tag, value, length, + if yaml_scalar_event_initialize(event, anchor, tag, value, length, plain_implicit, quoted_implicit, scalar_style) == 0: raise MemoryError elif event_class is SequenceStartEvent: @@ -1186,7 +1186,7 @@ cdef class CEmitter: sequence_style = YAML_BLOCK_SEQUENCE_STYLE if event_object.flow_style: sequence_style = YAML_FLOW_SEQUENCE_STYLE - if yaml_sequence_start_event_initialize(event, anchor, tag, + if yaml_sequence_start_event_initialize(event, anchor, tag, implicit, sequence_style) == 0: raise MemoryError elif event_class is MappingStartEvent: @@ -1218,7 +1218,7 @@ cdef class CEmitter: mapping_style = YAML_BLOCK_MAPPING_STYLE if event_object.flow_style: mapping_style = YAML_FLOW_MAPPING_STYLE - if yaml_mapping_start_event_initialize(event, anchor, tag, + if yaml_mapping_start_event_initialize(event, anchor, tag, implicit, mapping_style) == 0: raise MemoryError elif event_class is SequenceEndEvent: @@ -1326,7 +1326,7 @@ cdef class CEmitter: raise TypeError("tag handle must be a string") else: raise TypeError(u"tag handle must be a string") - tag_directives_end.handle = PyString_AS_STRING(handle) + tag_directives_end.handle = PyString_AS_STRING(handle) if PyUnicode_CheckExact(prefix): prefix = PyUnicode_AsUTF8String(prefix) cache.append(prefix) @@ -1335,7 +1335,7 @@ cdef class CEmitter: raise TypeError("tag prefix must be a string") else: raise TypeError(u"tag prefix must be a string") - tag_directives_end.prefix = PyString_AS_STRING(prefix) + tag_directives_end.prefix = PyString_AS_STRING(prefix) tag_directives_end = tag_directives_end+1 if yaml_document_start_event_initialize(&event, version_directive, tag_directives_start, tag_directives_end, @@ -1396,7 +1396,7 @@ cdef class CEmitter: raise TypeError(u"anchor must be a string") anchor = PyString_AS_STRING(anchor_object) if node in self.serialized_nodes: - if yaml_alias_event_initialize(&event, anchor) == 0: + if yaml_alias_event_initialize(&event, anchor) == 0: raise MemoryError if yaml_emitter_emit(&self.emitter, &event) == 0: error = self._emitter_error() @@ -1443,7 +1443,7 @@ cdef class CEmitter: scalar_style = YAML_LITERAL_SCALAR_STYLE elif style_object == ">" or style_object == u">": scalar_style = YAML_FOLDED_SCALAR_STYLE - if yaml_scalar_event_initialize(&event, anchor, tag, value, length, + if yaml_scalar_event_initialize(&event, anchor, tag, value, length, plain_implicit, quoted_implicit, scalar_style) == 0: raise MemoryError if yaml_emitter_emit(&self.emitter, &event) == 0: @@ -1467,7 +1467,7 @@ cdef class CEmitter: sequence_style = YAML_BLOCK_SEQUENCE_STYLE if node.flow_style: sequence_style = YAML_FLOW_SEQUENCE_STYLE - if yaml_sequence_start_event_initialize(&event, anchor, tag, + if yaml_sequence_start_event_initialize(&event, anchor, tag, implicit, sequence_style) == 0: raise MemoryError if yaml_emitter_emit(&self.emitter, &event) == 0: @@ -1499,7 +1499,7 @@ cdef class CEmitter: mapping_style = YAML_BLOCK_MAPPING_STYLE if node.flow_style: mapping_style = YAML_FLOW_MAPPING_STYLE - if yaml_mapping_start_event_initialize(&event, anchor, tag, + if yaml_mapping_start_event_initialize(&event, anchor, tag, implicit, mapping_style) == 0: raise MemoryError if yaml_emitter_emit(&self.emitter, &event) == 0: @@ -1515,13 +1515,13 @@ cdef class CEmitter: self.ascend_resolver() return 1 -cdef int output_handler(void *data, char *buffer, size_t size) except 0: +cdef int output_handler(void *data, char *buffer, size_t size) except 0: cdef CEmitter emitter emitter = <CEmitter>data if emitter.dump_unicode == 0: - value = PyString_FromStringAndSize(buffer, size) + value = PyString_FromStringAndSize(buffer, size) else: - value = PyUnicode_DecodeUTF8(buffer, size, 'strict') + value = PyUnicode_DecodeUTF8(buffer, size, 'strict') emitter.stream.write(value) return 1 diff --git a/contrib/python/PyYAML/py2/yaml/composer.py b/contrib/python/PyYAML/py2/yaml/composer.py index df85ef653b..5ace29064f 100644 --- a/contrib/python/PyYAML/py2/yaml/composer.py +++ b/contrib/python/PyYAML/py2/yaml/composer.py @@ -72,9 +72,9 @@ class Composer(object): anchor = event.anchor if anchor is not None: if anchor in self.anchors: - raise ComposerError("found duplicate anchor %r; first occurrence" + raise ComposerError("found duplicate anchor %r; first occurrence" % anchor.encode('utf-8'), self.anchors[anchor].start_mark, - "second occurrence", event.start_mark) + "second occurrence", event.start_mark) self.descend_resolver(parent, index) if self.check_event(ScalarEvent): node = self.compose_scalar_node(anchor) diff --git a/contrib/python/PyYAML/py2/yaml/constructor.py b/contrib/python/PyYAML/py2/yaml/constructor.py index ff4e36828e..41144077b0 100644 --- a/contrib/python/PyYAML/py2/yaml/constructor.py +++ b/contrib/python/PyYAML/py2/yaml/constructor.py @@ -1,12 +1,12 @@ -__all__ = [ - 'BaseConstructor', - 'SafeConstructor', - 'FullConstructor', - 'UnsafeConstructor', - 'Constructor', - 'ConstructorError' -] +__all__ = [ + 'BaseConstructor', + 'SafeConstructor', + 'FullConstructor', + 'UnsafeConstructor', + 'Constructor', + 'ConstructorError' +] from error import * from nodes import * @@ -18,35 +18,35 @@ import binascii, re, sys, types class ConstructorError(MarkedYAMLError): pass - -class timezone(datetime.tzinfo): - def __init__(self, offset): - self._offset = offset - seconds = abs(offset).total_seconds() - self._name = 'UTC%s%02d:%02d' % ( - '-' if offset.days < 0 else '+', - seconds // 3600, - seconds % 3600 // 60 - ) - - def tzname(self, dt=None): - return self._name - - def utcoffset(self, dt=None): - return self._offset - - def dst(self, dt=None): - return datetime.timedelta(0) - - def __copy__(self): - return self.__deepcopy__() - - def __deepcopy__(self, memodict={}): - return self.__class__(self.utcoffset()) - - __repr__ = __str__ = tzname - - + +class timezone(datetime.tzinfo): + def __init__(self, offset): + self._offset = offset + seconds = abs(offset).total_seconds() + self._name = 'UTC%s%02d:%02d' % ( + '-' if offset.days < 0 else '+', + seconds // 3600, + seconds % 3600 // 60 + ) + + def tzname(self, dt=None): + return self._name + + def utcoffset(self, dt=None): + return self._offset + + def dst(self, dt=None): + return datetime.timedelta(0) + + def __copy__(self): + return self.__deepcopy__() + + def __deepcopy__(self, memodict={}): + return self.__class__(self.utcoffset()) + + __repr__ = __str__ = tzname + + class BaseConstructor(object): yaml_constructors = {} @@ -62,14 +62,14 @@ class BaseConstructor(object): # If there are more documents available? return self.check_node() - def check_state_key(self, key): - """Block special attributes/methods from being set in a newly created - object, to prevent user-controlled methods from being called during - deserialization""" - if self.get_state_keys_blacklist_regexp().match(key): - raise ConstructorError(None, None, - "blacklisted key '%s' in instance state found" % (key,), None) - + def check_state_key(self, key): + """Block special attributes/methods from being set in a newly created + object, to prevent user-controlled methods from being called during + deserialization""" + if self.get_state_keys_blacklist_regexp().match(key): + raise ConstructorError(None, None, + "blacklisted key '%s' in instance state found" % (key,), None) + def get_data(self): # Construct and return the next document. if self.check_node(): @@ -111,7 +111,7 @@ class BaseConstructor(object): constructor = self.yaml_constructors[node.tag] else: for tag_prefix in self.yaml_multi_constructors: - if tag_prefix is not None and node.tag.startswith(tag_prefix): + if tag_prefix is not None and node.tag.startswith(tag_prefix): tag_suffix = node.tag[len(tag_prefix):] constructor = self.yaml_multi_constructors[tag_prefix] break @@ -330,7 +330,7 @@ class SafeConstructor(BaseConstructor): return str(value).decode('base64') except (binascii.Error, UnicodeEncodeError), exc: raise ConstructorError(None, None, - "failed to decode base64 data: %s" % exc, node.start_mark) + "failed to decode base64 data: %s" % exc, node.start_mark) timestamp_regexp = re.compile( ur'''^(?P<year>[0-9][0-9][0-9][0-9]) @@ -357,7 +357,7 @@ class SafeConstructor(BaseConstructor): minute = int(values['minute']) second = int(values['second']) fraction = 0 - tzinfo = None + tzinfo = None if values['fraction']: fraction = values['fraction'][:6] while len(fraction) < 6: @@ -369,11 +369,11 @@ class SafeConstructor(BaseConstructor): delta = datetime.timedelta(hours=tz_hour, minutes=tz_minute) if values['tz_sign'] == '-': delta = -delta - tzinfo = timezone(delta) - elif values['tz']: - tzinfo = timezone(datetime.timedelta(0)) - return datetime.datetime(year, month, day, hour, minute, second, fraction, - tzinfo=tzinfo) + tzinfo = timezone(delta) + elif values['tz']: + tzinfo = timezone(datetime.timedelta(0)) + return datetime.datetime(year, month, day, hour, minute, second, fraction, + tzinfo=tzinfo) def construct_yaml_omap(self, node): # Note: we do not check for duplicate keys, because it's too @@ -508,18 +508,18 @@ SafeConstructor.add_constructor( SafeConstructor.add_constructor(None, SafeConstructor.construct_undefined) -class FullConstructor(SafeConstructor): - # 'extend' is blacklisted because it is used by - # construct_python_object_apply to add `listitems` to a newly generate - # python instance - def get_state_keys_blacklist(self): - return ['^extend$', '^__.*__$'] - - def get_state_keys_blacklist_regexp(self): - if not hasattr(self, 'state_keys_blacklist_regexp'): - self.state_keys_blacklist_regexp = re.compile('(' + '|'.join(self.get_state_keys_blacklist()) + ')') - return self.state_keys_blacklist_regexp - +class FullConstructor(SafeConstructor): + # 'extend' is blacklisted because it is used by + # construct_python_object_apply to add `listitems` to a newly generate + # python instance + def get_state_keys_blacklist(self): + return ['^extend$', '^__.*__$'] + + def get_state_keys_blacklist_regexp(self): + if not hasattr(self, 'state_keys_blacklist_regexp'): + self.state_keys_blacklist_regexp = re.compile('(' + '|'.join(self.get_state_keys_blacklist()) + ')') + return self.state_keys_blacklist_regexp + def construct_python_str(self, node): return self.construct_scalar(node).encode('utf-8') @@ -535,22 +535,22 @@ class FullConstructor(SafeConstructor): def construct_python_tuple(self, node): return tuple(self.construct_sequence(node)) - def find_python_module(self, name, mark, unsafe=False): + def find_python_module(self, name, mark, unsafe=False): if not name: raise ConstructorError("while constructing a Python module", mark, "expected non-empty name appended to the tag", mark) - if unsafe: - try: - __import__(name) - except ImportError, exc: - raise ConstructorError("while constructing a Python module", mark, - "cannot find module %r (%s)" % (name.encode('utf-8'), exc), mark) - if name not in sys.modules: + if unsafe: + try: + __import__(name) + except ImportError, exc: + raise ConstructorError("while constructing a Python module", mark, + "cannot find module %r (%s)" % (name.encode('utf-8'), exc), mark) + if name not in sys.modules: raise ConstructorError("while constructing a Python module", mark, - "module %r is not imported" % name.encode('utf-8'), mark) + "module %r is not imported" % name.encode('utf-8'), mark) return sys.modules[name] - def find_python_name(self, name, mark, unsafe=False): + def find_python_name(self, name, mark, unsafe=False): if not name: raise ConstructorError("while constructing a Python object", mark, "expected non-empty name appended to the tag", mark) @@ -559,15 +559,15 @@ class FullConstructor(SafeConstructor): else: module_name = '__builtin__' object_name = name - if unsafe: - try: - __import__(module_name) - except ImportError, exc: - raise ConstructorError("while constructing a Python object", mark, - "cannot find module %r (%s)" % (module_name.encode('utf-8'), exc), mark) - if module_name not in sys.modules: + if unsafe: + try: + __import__(module_name) + except ImportError, exc: + raise ConstructorError("while constructing a Python object", mark, + "cannot find module %r (%s)" % (module_name.encode('utf-8'), exc), mark) + if module_name not in sys.modules: raise ConstructorError("while constructing a Python object", mark, - "module %r is not imported" % module_name.encode('utf-8'), mark) + "module %r is not imported" % module_name.encode('utf-8'), mark) module = sys.modules[module_name] if not hasattr(module, object_name): raise ConstructorError("while constructing a Python object", mark, @@ -594,16 +594,16 @@ class FullConstructor(SafeConstructor): class classobj: pass def make_python_instance(self, suffix, node, - args=None, kwds=None, newobj=False, unsafe=False): + args=None, kwds=None, newobj=False, unsafe=False): if not args: args = [] if not kwds: kwds = {} cls = self.find_python_name(suffix, node.start_mark) - if not (unsafe or isinstance(cls, type) or isinstance(cls, type(self.classobj))): - raise ConstructorError("while constructing a Python instance", node.start_mark, - "expected a class, but found %r" % type(cls), - node.start_mark) + if not (unsafe or isinstance(cls, type) or isinstance(cls, type(self.classobj))): + raise ConstructorError("while constructing a Python instance", node.start_mark, + "expected a class, but found %r" % type(cls), + node.start_mark) if newobj and isinstance(cls, type(self.classobj)) \ and not args and not kwds: instance = self.classobj() @@ -614,7 +614,7 @@ class FullConstructor(SafeConstructor): else: return cls(*args, **kwds) - def set_python_instance_state(self, instance, state, unsafe=False): + def set_python_instance_state(self, instance, state, unsafe=False): if hasattr(instance, '__setstate__'): instance.__setstate__(state) else: @@ -622,16 +622,16 @@ class FullConstructor(SafeConstructor): if isinstance(state, tuple) and len(state) == 2: state, slotstate = state if hasattr(instance, '__dict__'): - if not unsafe and state: - for key in state.keys(): - self.check_state_key(key) + if not unsafe and state: + for key in state.keys(): + self.check_state_key(key) instance.__dict__.update(state) elif state: slotstate.update(state) for key, value in slotstate.items(): - if not unsafe: - self.check_state_key(key) - setattr(instance, key, value) + if not unsafe: + self.check_state_key(key) + setattr(instance, key, value) def construct_python_object(self, suffix, node): # Format: @@ -680,87 +680,87 @@ class FullConstructor(SafeConstructor): def construct_python_object_new(self, suffix, node): return self.construct_python_object_apply(suffix, node, newobj=True) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/none', - FullConstructor.construct_yaml_null) + FullConstructor.construct_yaml_null) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/bool', - FullConstructor.construct_yaml_bool) + FullConstructor.construct_yaml_bool) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/str', - FullConstructor.construct_python_str) + FullConstructor.construct_python_str) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/unicode', - FullConstructor.construct_python_unicode) + FullConstructor.construct_python_unicode) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/int', - FullConstructor.construct_yaml_int) + FullConstructor.construct_yaml_int) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/long', - FullConstructor.construct_python_long) + FullConstructor.construct_python_long) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/float', - FullConstructor.construct_yaml_float) + FullConstructor.construct_yaml_float) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/complex', - FullConstructor.construct_python_complex) + FullConstructor.construct_python_complex) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/list', - FullConstructor.construct_yaml_seq) + FullConstructor.construct_yaml_seq) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/tuple', - FullConstructor.construct_python_tuple) + FullConstructor.construct_python_tuple) -FullConstructor.add_constructor( +FullConstructor.add_constructor( u'tag:yaml.org,2002:python/dict', - FullConstructor.construct_yaml_map) + FullConstructor.construct_yaml_map) -FullConstructor.add_multi_constructor( +FullConstructor.add_multi_constructor( u'tag:yaml.org,2002:python/name:', - FullConstructor.construct_python_name) - -class UnsafeConstructor(FullConstructor): - - def find_python_module(self, name, mark): - return super(UnsafeConstructor, self).find_python_module(name, mark, unsafe=True) - - def find_python_name(self, name, mark): - return super(UnsafeConstructor, self).find_python_name(name, mark, unsafe=True) - - def make_python_instance(self, suffix, node, args=None, kwds=None, newobj=False): - return super(UnsafeConstructor, self).make_python_instance( - suffix, node, args, kwds, newobj, unsafe=True) - - def set_python_instance_state(self, instance, state): - return super(UnsafeConstructor, self).set_python_instance_state( - instance, state, unsafe=True) - -UnsafeConstructor.add_multi_constructor( - u'tag:yaml.org,2002:python/module:', - UnsafeConstructor.construct_python_module) - -UnsafeConstructor.add_multi_constructor( - u'tag:yaml.org,2002:python/object:', - UnsafeConstructor.construct_python_object) - -UnsafeConstructor.add_multi_constructor( - u'tag:yaml.org,2002:python/object/new:', - UnsafeConstructor.construct_python_object_new) - -UnsafeConstructor.add_multi_constructor( - u'tag:yaml.org,2002:python/object/apply:', - UnsafeConstructor.construct_python_object_apply) - -# Constructor is same as UnsafeConstructor. Need to leave this in place in case -# people have extended it directly. -class Constructor(UnsafeConstructor): - pass + FullConstructor.construct_python_name) + +class UnsafeConstructor(FullConstructor): + + def find_python_module(self, name, mark): + return super(UnsafeConstructor, self).find_python_module(name, mark, unsafe=True) + + def find_python_name(self, name, mark): + return super(UnsafeConstructor, self).find_python_name(name, mark, unsafe=True) + + def make_python_instance(self, suffix, node, args=None, kwds=None, newobj=False): + return super(UnsafeConstructor, self).make_python_instance( + suffix, node, args, kwds, newobj, unsafe=True) + + def set_python_instance_state(self, instance, state): + return super(UnsafeConstructor, self).set_python_instance_state( + instance, state, unsafe=True) + +UnsafeConstructor.add_multi_constructor( + u'tag:yaml.org,2002:python/module:', + UnsafeConstructor.construct_python_module) + +UnsafeConstructor.add_multi_constructor( + u'tag:yaml.org,2002:python/object:', + UnsafeConstructor.construct_python_object) + +UnsafeConstructor.add_multi_constructor( + u'tag:yaml.org,2002:python/object/new:', + UnsafeConstructor.construct_python_object_new) + +UnsafeConstructor.add_multi_constructor( + u'tag:yaml.org,2002:python/object/apply:', + UnsafeConstructor.construct_python_object_apply) + +# Constructor is same as UnsafeConstructor. Need to leave this in place in case +# people have extended it directly. +class Constructor(UnsafeConstructor): + pass diff --git a/contrib/python/PyYAML/py2/yaml/cyaml.py b/contrib/python/PyYAML/py2/yaml/cyaml.py index 768b49d6b9..c671e70831 100644 --- a/contrib/python/PyYAML/py2/yaml/cyaml.py +++ b/contrib/python/PyYAML/py2/yaml/cyaml.py @@ -1,10 +1,10 @@ -__all__ = [ - 'CBaseLoader', 'CSafeLoader', 'CFullLoader', 'CUnsafeLoader', 'CLoader', - 'CBaseDumper', 'CSafeDumper', 'CDumper' -] +__all__ = [ + 'CBaseLoader', 'CSafeLoader', 'CFullLoader', 'CUnsafeLoader', 'CLoader', + 'CBaseDumper', 'CSafeDumper', 'CDumper' +] -from yaml._yaml import CParser, CEmitter +from yaml._yaml import CParser, CEmitter from constructor import * @@ -27,20 +27,20 @@ class CSafeLoader(CParser, SafeConstructor, Resolver): SafeConstructor.__init__(self) Resolver.__init__(self) -class CFullLoader(CParser, FullConstructor, Resolver): - - def __init__(self, stream): - CParser.__init__(self, stream) - FullConstructor.__init__(self) - Resolver.__init__(self) - -class CUnsafeLoader(CParser, UnsafeConstructor, Resolver): - - def __init__(self, stream): - CParser.__init__(self, stream) - UnsafeConstructor.__init__(self) - Resolver.__init__(self) - +class CFullLoader(CParser, FullConstructor, Resolver): + + def __init__(self, stream): + CParser.__init__(self, stream) + FullConstructor.__init__(self) + Resolver.__init__(self) + +class CUnsafeLoader(CParser, UnsafeConstructor, Resolver): + + def __init__(self, stream): + CParser.__init__(self, stream) + UnsafeConstructor.__init__(self) + Resolver.__init__(self) + class CLoader(CParser, Constructor, Resolver): def __init__(self, stream): @@ -51,51 +51,51 @@ class CLoader(CParser, Constructor, Resolver): class CBaseDumper(CEmitter, BaseRepresenter, BaseResolver): def __init__(self, stream, - default_style=None, default_flow_style=False, + 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): + version=None, tags=None, sort_keys=True): CEmitter.__init__(self, stream, canonical=canonical, indent=indent, width=width, encoding=encoding, allow_unicode=allow_unicode, line_break=line_break, explicit_start=explicit_start, explicit_end=explicit_end, version=version, tags=tags) Representer.__init__(self, default_style=default_style, - default_flow_style=default_flow_style, sort_keys=sort_keys) + default_flow_style=default_flow_style, sort_keys=sort_keys) Resolver.__init__(self) class CSafeDumper(CEmitter, SafeRepresenter, Resolver): def __init__(self, stream, - default_style=None, default_flow_style=False, + 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): + version=None, tags=None, sort_keys=True): CEmitter.__init__(self, stream, canonical=canonical, indent=indent, width=width, encoding=encoding, allow_unicode=allow_unicode, line_break=line_break, explicit_start=explicit_start, explicit_end=explicit_end, version=version, tags=tags) SafeRepresenter.__init__(self, default_style=default_style, - default_flow_style=default_flow_style, sort_keys=sort_keys) + default_flow_style=default_flow_style, sort_keys=sort_keys) Resolver.__init__(self) class CDumper(CEmitter, Serializer, Representer, Resolver): def __init__(self, stream, - default_style=None, default_flow_style=False, + 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): + version=None, tags=None, sort_keys=True): CEmitter.__init__(self, stream, canonical=canonical, indent=indent, width=width, encoding=encoding, allow_unicode=allow_unicode, line_break=line_break, explicit_start=explicit_start, explicit_end=explicit_end, version=version, tags=tags) Representer.__init__(self, default_style=default_style, - default_flow_style=default_flow_style, sort_keys=sort_keys) + default_flow_style=default_flow_style, sort_keys=sort_keys) Resolver.__init__(self) diff --git a/contrib/python/PyYAML/py2/yaml/dumper.py b/contrib/python/PyYAML/py2/yaml/dumper.py index f9cd49fda5..53750021b9 100644 --- a/contrib/python/PyYAML/py2/yaml/dumper.py +++ b/contrib/python/PyYAML/py2/yaml/dumper.py @@ -9,11 +9,11 @@ from resolver import * class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver): def __init__(self, stream, - default_style=None, default_flow_style=False, + 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): + 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) @@ -21,17 +21,17 @@ class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver): explicit_start=explicit_start, explicit_end=explicit_end, version=version, tags=tags) Representer.__init__(self, default_style=default_style, - default_flow_style=default_flow_style, sort_keys=sort_keys) + default_flow_style=default_flow_style, sort_keys=sort_keys) Resolver.__init__(self) class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver): def __init__(self, stream, - default_style=None, default_flow_style=False, + 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): + 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) @@ -39,17 +39,17 @@ class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver): explicit_start=explicit_start, explicit_end=explicit_end, version=version, tags=tags) SafeRepresenter.__init__(self, default_style=default_style, - default_flow_style=default_flow_style, sort_keys=sort_keys) + default_flow_style=default_flow_style, sort_keys=sort_keys) Resolver.__init__(self) class Dumper(Emitter, Serializer, Representer, Resolver): def __init__(self, stream, - default_style=None, default_flow_style=False, + 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): + 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) @@ -57,6 +57,6 @@ class Dumper(Emitter, Serializer, Representer, Resolver): explicit_start=explicit_start, explicit_end=explicit_end, version=version, tags=tags) Representer.__init__(self, default_style=default_style, - default_flow_style=default_flow_style, sort_keys=sort_keys) + default_flow_style=default_flow_style, sort_keys=sort_keys) Resolver.__init__(self) diff --git a/contrib/python/PyYAML/py2/yaml/emitter.py b/contrib/python/PyYAML/py2/yaml/emitter.py index 23c25ca80a..7c18ba5c30 100644 --- a/contrib/python/PyYAML/py2/yaml/emitter.py +++ b/contrib/python/PyYAML/py2/yaml/emitter.py @@ -8,13 +8,13 @@ __all__ = ['Emitter', 'EmitterError'] -import sys - +import sys + from error import YAMLError from events import * -has_ucs4 = sys.maxunicode > 0xffff - +has_ucs4 = sys.maxunicode > 0xffff + class EmitterError(YAMLError): pass @@ -45,7 +45,7 @@ class Emitter(object): # The stream should have the methods `write` and possibly `flush`. self.stream = stream - # Encoding can be overridden by STREAM-START. + # Encoding can be overridden by STREAM-START. self.encoding = None # Emitter is a state machine with a stack of states to handle nested @@ -659,7 +659,7 @@ class Emitter(object): flow_indicators = True # First character or preceded by a whitespace. - preceded_by_whitespace = True + preceded_by_whitespace = True # Last character or followed by a whitespace. followed_by_whitespace = (len(scalar) == 1 or @@ -678,7 +678,7 @@ class Emitter(object): # Check for indicators. if index == 0: # Leading indicators are special characters. - if ch in u'#,[]{}&*!|>\'\"%@`': + if ch in u'#,[]{}&*!|>\'\"%@`': flow_indicators = True block_indicators = True if ch in u'?:': @@ -696,7 +696,7 @@ class Emitter(object): flow_indicators = True if followed_by_whitespace: block_indicators = True - if ch == u'#' and preceded_by_whitespace: + if ch == u'#' and preceded_by_whitespace: flow_indicators = True block_indicators = True @@ -705,8 +705,8 @@ class Emitter(object): line_breaks = True if not (ch == u'\n' or u'\x20' <= ch <= u'\x7E'): if (ch == u'\x85' or u'\xA0' <= ch <= u'\uD7FF' - or u'\uE000' <= ch <= u'\uFFFD' - or (u'\U00010000' <= ch < u'\U0010ffff')) and ch != u'\uFEFF': + or u'\uE000' <= ch <= u'\uFFFD' + or (u'\U00010000' <= ch < u'\U0010ffff')) and ch != u'\uFEFF': unicode_characters = True if not self.allow_unicode: special_characters = True @@ -738,7 +738,7 @@ class Emitter(object): # Prepare for the next character. index += 1 - preceded_by_whitespace = (ch in u'\0 \t\r\n\x85\u2028\u2029') + preceded_by_whitespace = (ch in u'\0 \t\r\n\x85\u2028\u2029') followed_by_whitespace = (index+1 >= len(scalar) or scalar[index+1] in u'\0 \t\r\n\x85\u2028\u2029') diff --git a/contrib/python/PyYAML/py2/yaml/loader.py b/contrib/python/PyYAML/py2/yaml/loader.py index 4d773c3cc1..bc93d97582 100644 --- a/contrib/python/PyYAML/py2/yaml/loader.py +++ b/contrib/python/PyYAML/py2/yaml/loader.py @@ -1,5 +1,5 @@ -__all__ = ['BaseLoader', 'FullLoader', 'SafeLoader', 'Loader', 'UnsafeLoader'] +__all__ = ['BaseLoader', 'FullLoader', 'SafeLoader', 'Loader', 'UnsafeLoader'] from reader import * from scanner import * @@ -18,16 +18,16 @@ class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor, BaseResolve BaseConstructor.__init__(self) BaseResolver.__init__(self) -class FullLoader(Reader, Scanner, Parser, Composer, FullConstructor, Resolver): - - def __init__(self, stream): - Reader.__init__(self, stream) - Scanner.__init__(self) - Parser.__init__(self) - Composer.__init__(self) - FullConstructor.__init__(self) - Resolver.__init__(self) - +class FullLoader(Reader, Scanner, Parser, Composer, FullConstructor, Resolver): + + def __init__(self, stream): + Reader.__init__(self, stream) + Scanner.__init__(self) + Parser.__init__(self) + Composer.__init__(self) + FullConstructor.__init__(self) + Resolver.__init__(self) + class SafeLoader(Reader, Scanner, Parser, Composer, SafeConstructor, Resolver): def __init__(self, stream): @@ -48,16 +48,16 @@ class Loader(Reader, Scanner, Parser, Composer, Constructor, Resolver): Constructor.__init__(self) Resolver.__init__(self) -# UnsafeLoader is the same as Loader (which is and was always unsafe on -# untrusted input). Use of either Loader or UnsafeLoader should be rare, since -# FullLoad should be able to load almost all YAML safely. Loader is left intact -# to ensure backwards compatibility. -class UnsafeLoader(Reader, Scanner, Parser, Composer, Constructor, Resolver): - - def __init__(self, stream): - Reader.__init__(self, stream) - Scanner.__init__(self) - Parser.__init__(self) - Composer.__init__(self) - Constructor.__init__(self) - Resolver.__init__(self) +# UnsafeLoader is the same as Loader (which is and was always unsafe on +# untrusted input). Use of either Loader or UnsafeLoader should be rare, since +# FullLoad should be able to load almost all YAML safely. Loader is left intact +# to ensure backwards compatibility. +class UnsafeLoader(Reader, Scanner, Parser, Composer, Constructor, Resolver): + + def __init__(self, stream): + Reader.__init__(self, stream) + Scanner.__init__(self) + Parser.__init__(self) + Composer.__init__(self) + Constructor.__init__(self) + Resolver.__init__(self) diff --git a/contrib/python/PyYAML/py2/yaml/reader.py b/contrib/python/PyYAML/py2/yaml/reader.py index 4c42150989..d998dceb7c 100644 --- a/contrib/python/PyYAML/py2/yaml/reader.py +++ b/contrib/python/PyYAML/py2/yaml/reader.py @@ -19,10 +19,10 @@ __all__ = ['Reader', 'ReaderError'] from error import YAMLError, Mark -import codecs, re, sys - -has_ucs4 = sys.maxunicode > 0xffff +import codecs, re, sys +has_ucs4 = sys.maxunicode > 0xffff + class ReaderError(YAMLError): def __init__(self, name, position, character, encoding, reason): @@ -136,15 +136,15 @@ class Reader(object): self.encoding = 'utf-8' self.update(1) - if has_ucs4: - NON_PRINTABLE = u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD\U00010000-\U0010ffff]' - elif sys.platform.startswith('java'): - # Jython doesn't support lone surrogates https://bugs.jython.org/issue2048 - NON_PRINTABLE = u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]' - else: - # Need to use eval here due to the above Jython issue - NON_PRINTABLE = eval(r"u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uFFFD]|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?:[^\uDC00-\uDFFF]|$)'") - NON_PRINTABLE = re.compile(NON_PRINTABLE) + if has_ucs4: + NON_PRINTABLE = u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD\U00010000-\U0010ffff]' + elif sys.platform.startswith('java'): + # Jython doesn't support lone surrogates https://bugs.jython.org/issue2048 + NON_PRINTABLE = u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]' + else: + # Need to use eval here due to the above Jython issue + NON_PRINTABLE = eval(r"u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uFFFD]|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?:[^\uDC00-\uDFFF]|$)'") + NON_PRINTABLE = re.compile(NON_PRINTABLE) def check_printable(self, data): match = self.NON_PRINTABLE.search(data) if match: diff --git a/contrib/python/PyYAML/py2/yaml/representer.py b/contrib/python/PyYAML/py2/yaml/representer.py index 93e09b67b3..fec15eb201 100644 --- a/contrib/python/PyYAML/py2/yaml/representer.py +++ b/contrib/python/PyYAML/py2/yaml/representer.py @@ -3,12 +3,12 @@ __all__ = ['BaseRepresenter', 'SafeRepresenter', 'Representer', 'RepresenterError'] from error import * - + from nodes import * import datetime -import copy_reg, types +import copy_reg, types class RepresenterError(YAMLError): pass @@ -18,10 +18,10 @@ class BaseRepresenter(object): yaml_representers = {} yaml_multi_representers = {} - def __init__(self, default_style=None, default_flow_style=False, sort_keys=True): + def __init__(self, default_style=None, default_flow_style=False, sort_keys=True): self.default_style = default_style self.default_flow_style = default_flow_style - self.sort_keys = sort_keys + self.sort_keys = sort_keys self.represented_objects = {} self.object_keeper = [] self.alias_key = None @@ -119,8 +119,8 @@ class BaseRepresenter(object): best_style = True if hasattr(mapping, 'items'): mapping = mapping.items() - if self.sort_keys: - mapping.sort() + if self.sort_keys: + mapping.sort() for item_key, item_value in mapping: node_key = self.represent_data(item_key) node_value = self.represent_data(item_value) @@ -249,7 +249,7 @@ class SafeRepresenter(BaseRepresenter): return self.represent_mapping(tag, state, flow_style=flow_style) def represent_undefined(self, data): - raise RepresenterError("cannot represent an object", data) + raise RepresenterError("cannot represent an object", data) SafeRepresenter.add_representer(type(None), SafeRepresenter.represent_none) @@ -414,7 +414,7 @@ class Representer(SafeRepresenter): elif hasattr(data, '__reduce__'): reduce = data.__reduce__() else: - raise RepresenterError("cannot represent an object", data) + raise RepresenterError("cannot represent an object", data) reduce = (list(reduce)+[None]*5)[:5] function, args, state, listitems, dictitems = reduce args = list(args) diff --git a/contrib/python/PyYAML/py2/yaml/resolver.py b/contrib/python/PyYAML/py2/yaml/resolver.py index ba9aeab21d..3565d20872 100644 --- a/contrib/python/PyYAML/py2/yaml/resolver.py +++ b/contrib/python/PyYAML/py2/yaml/resolver.py @@ -146,8 +146,8 @@ class BaseResolver(object): resolvers = self.yaml_implicit_resolvers.get(u'', []) else: resolvers = self.yaml_implicit_resolvers.get(value[0], []) - wildcard_resolvers = self.yaml_implicit_resolvers.get(None, []) - for tag, regexp in resolvers + wildcard_resolvers: + wildcard_resolvers = self.yaml_implicit_resolvers.get(None, []) + for tag, regexp in resolvers + wildcard_resolvers: if regexp.match(value): return tag implicit = implicit[1] diff --git a/contrib/python/PyYAML/py2/yaml/scanner.py b/contrib/python/PyYAML/py2/yaml/scanner.py index 587b73d8b4..00beebc30d 100644 --- a/contrib/python/PyYAML/py2/yaml/scanner.py +++ b/contrib/python/PyYAML/py2/yaml/scanner.py @@ -126,13 +126,13 @@ class Scanner(object): def peek_token(self): # Return the next token, but do not delete if from the queue. - # Return None if no more tokens. + # Return None if no more tokens. while self.need_more_tokens(): self.fetch_more_tokens() if self.tokens: return self.tokens[0] - else: - return None + else: + return None def get_token(self): # Return the next token. @@ -334,7 +334,7 @@ class Scanner(object): ## } #if self.flow_level and self.indent > column: # raise ScannerError(None, None, - # "invalid indentation or unclosed '[' or '{'", + # "invalid indentation or unclosed '[' or '{'", # self.get_mark()) # In the flow context, indentation is ignored. We make the scanner less @@ -372,7 +372,7 @@ class Scanner(object): def fetch_stream_end(self): - # Set the current indentation to -1. + # Set the current indentation to -1. self.unwind_indent(-1) # Reset simple keys. @@ -391,7 +391,7 @@ class Scanner(object): def fetch_directive(self): - # Set the current indentation to -1. + # Set the current indentation to -1. self.unwind_indent(-1) # Reset simple keys. @@ -409,7 +409,7 @@ class Scanner(object): def fetch_document_indicator(self, TokenClass): - # Set the current indentation to -1. + # Set the current indentation to -1. self.unwind_indent(-1) # Reset simple keys. Note that there could not be a block collection @@ -521,7 +521,7 @@ class Scanner(object): # Block context needs additional checks. if not self.flow_level: - # Are we allowed to start a key (not necessary a simple)? + # Are we allowed to start a key (not necessary a simple)? if not self.allow_simple_key: raise ScannerError(None, None, "mapping keys are not allowed here", @@ -569,7 +569,7 @@ class Scanner(object): else: # Block context needs additional checks. - # (Do we really need them? They will be caught by the parser + # (Do we really need them? They will be caught by the parser # anyway.) if not self.flow_level: @@ -907,7 +907,7 @@ class Scanner(object): # The specification does not restrict characters for anchors and # aliases. This may lead to problems, for instance, the document: # [ *alias, value ] - # can be interpreted in two ways, as + # can be interpreted in two ways, as # [ "value" ] # and # [ *alias , "value" ] @@ -1177,7 +1177,7 @@ class Scanner(object): u' ': u'\x20', u'\"': u'\"', u'\\': u'\\', - u'/': u'/', + u'/': u'/', u'N': u'\x85', u'_': u'\xA0', u'L': u'\u2028', @@ -1281,7 +1281,7 @@ class Scanner(object): def scan_plain(self): # See the specification for details. # We add an additional restriction for the flow context: - # plain scalars in the flow context cannot contain ',' or '?'. + # plain scalars in the flow context cannot contain ',' or '?'. # We also keep track of the `allow_simple_key` flag here. # Indentation rules are loosed for the flow context. chunks = [] @@ -1300,10 +1300,10 @@ class Scanner(object): while True: ch = self.peek(length) if ch in u'\0 \t\r\n\x85\u2028\u2029' \ - or (ch == u':' and - self.peek(length+1) in u'\0 \t\r\n\x85\u2028\u2029' - + (u',[]{}' if self.flow_level else u''))\ - or (self.flow_level and ch in u',?[]{}'): + or (ch == u':' and + self.peek(length+1) in u'\0 \t\r\n\x85\u2028\u2029' + + (u',[]{}' if self.flow_level else u''))\ + or (self.flow_level and ch in u',?[]{}'): break length += 1 if length == 0: |