Commit Graph

68 Commits

Author SHA1 Message Date
xuyong
3b30a99471 backup pyyaml from 6.0 to 5.4.1
Signed-off-by: xuyong <xuyong59@huawei.com>
2022-03-16 17:10:07 +08:00
Thom Smith
f20947ae25 Move code from lib3 to lib 2021-09-22 15:52:05 +02:00
Ingy döt Net
ee37f4653c 5.4.1 release 2021-01-20 16:40:50 -05:00
Matt Davis
2b37f155d4 Fix stub compat with older pyyaml versions that may unwittingly load it 2021-01-20 16:39:29 -05:00
Ingy döt Net
58d0cb7ee0 5.4 release 2021-01-19 14:07:59 -05:00
Phil Sphicas
fc914d52c4 Avoid repeatedly appending to yaml_implicit_resolvers
Repeated calls to `resolve` can experience performance degredation, if
`add_implicit_resolver` has been called with `first=None` (to add an
implicit resolver with an unspecified first character).

For example, every time `foo` is encountered, the "wildcard implicit
resolvers" (with `first=None`) will be appended to the list of implicit
resolvers for strings starting with `f`, which will normally be the
resolver for booleans. The list `yaml_implicit_resolvers['f']` will keep
getting longer. The same behavior applies for any first-letter matches
with existing implicit resolvers.

This change avoids unintentionally mutating the lists in the class-level
dict `yaml_implicit_resolvers` by looping through a temporary copy.

Fixes: #439
2021-01-13 16:58:40 -05:00
Ingy döt Net
a001f27825 Fix for CVE-2020-14343
Per suggestion https://github.com/yaml/pyyaml/issues/420#issuecomment-663888344
move a few constructors from full_load to unsafe_load.
2021-01-13 16:58:40 -05:00
Brad Solomon
89f608599d Build modernization (GHA, wheels, setuptools) (#407)
* Move most CI to GitHub Actions
* Build sdist
* Build manylinux1 wheels with libyaml ext (also tested with 2010 and 2014)
* Build MacOS x86_64 wheels with libyaml ext
* Windows wheel builds remain on AppVeyor until we drop 2.7 support in 6.0
* Smoke tests of all post-build artifacts
* Add PEP517/518 build declaration (pyproject.toml with setuptools backend)
* Fully move build to setuptools
* Drop Python 3.5 support
* Declare Python 3.9 support
* Update PyPI metadata now that setuptools lets it flow through

Co-authored-by: Matt Davis <mrd@redhat.com>
2021-01-13 16:58:40 -05:00
Tina Müller
91bca4b856 Update version to 5.3.1 2020-03-17 20:52:26 +01:00
Riccardo Schirone
5080ba5133
Prevents arbitrary code execution during python/object/new constructor (#386)
* Prevents arbitrary code execution during python/object/new constructor

In FullLoader python/object/new constructor, implemented by
construct_python_object_apply, has support for setting the state of a
deserialized instance through the set_python_instance_state method.
After setting the state, some operations are performed on the instance
to complete its initialization, however it is possible for an attacker
to set the instance' state in such a way that arbitrary code is executed
by the FullLoader.

This patch tries to block such attacks in FullLoader by preventing
set_python_instance_state from setting arbitrary properties. It
implements a blacklist that includes `extend` method (called by
construct_python_object_apply) and all special methods (e.g. __set__,
__setitem__, etc.).

Users who need special attributes being set in the state of a
deserialized object can still do it through the UnsafeLoader, which
however should not be used on untrusted input. Additionally, they can
subclass FullLoader and redefine `get_state_keys_blacklist()` to
extend/replace the list of blacklisted keys, passing the subclassed
loader to yaml.load.

* Make sure python/object/new constructor does not set some properties

* Add test to show how to subclass FullLoader with new blacklist
2020-03-17 19:09:55 +01:00
Tina Müller
377092fb2e Changes for 5.3 2020-01-06 20:37:50 +01:00
Tina Müller
69b025a9f3 Changes for 5.3b1 2019-12-21 22:49:24 +01:00
Mattijs Ugen
96d65f3de1 Create timezone-aware datetimes when parsed as such (#163)
* On load, now use aware datetimes if possible

On loading data, if timestamps have an ISO "+HH:MM" UTC offset then the resultant datetime is converted to UTC.  This change adds that timezone information to the datetime objects.

Importantly, this addresses a Django warning (and potential error) that appears when using both YAML fixtures in a timezone-aware project.  It was raised as a Django issue (https://code.djangoproject.com/ticket/18867), but subsequently closed because the Django devs felt that this is a PyYAML problem.

* Create timezone-aware datetime in timezone from data

* Create timezone-aware datetime in timezone from data for python2

* Define better timezone implementation for python2

* Handle timezone "Z" for python 3

* Handle timezone "Z" for python 2

* Fix code structure for Python 3

Call datetime.datetime constructor once at return.

* Fix code structure for Python 2

Call datetime.datetime constructor once at return.
2019-12-20 20:38:46 +01:00
Frédéric Chapoton
36fdf0c486 remove some unused imports (#260)
* remove some unused imports

as suggested by lgtm

https://lgtm.com/projects/g/yaml/pyyaml/

* add back import * from nodes

* remove also sys import

* remove mkpath import
2019-12-20 20:38:46 +01:00
Tina Müller (tinita)
03b378d039
Allow add_multi_constructor with None (#358)
Loader.add_multi_constructor(None, myconstructor)

Also add test for add_multi_constructor('!', ...) etc.

See issue #317
2019-12-07 22:40:48 +01:00
Filip Salomonsson
5a0cfab86f Fix handling of __slots__ (#161) 2019-12-07 22:34:23 +01:00
Tim Gates
eb459f842f Fix up small typo
Replace `intendation` with `indentation`.
2019-12-04 00:31:05 +01:00
Sergey Fursov
e21af4a092 Use is instead of equality for comparing with None 2019-12-04 00:04:05 +01:00
David Kao
de11e43d52 fix typos and stylistic nit 2019-12-03 23:58:55 +01:00
Tina Müller
a5c2a043a2 Version 5.2 2019-12-02 21:13:24 +01:00
Matt Davis
3f3c373f50 bump version to 5.2b1 2019-11-25 23:39:55 +01:00
Tina Müller
8c5e47fe62 Move constructor for object/apply to Unsafe 2019-11-20 20:48:47 +01:00
Tina Müller
4a31b16b04 Change default loader for add_implicit_resolver, add_path_resolver
If the Loader parameter is not given, add constructor to
all three loaders
2019-11-18 12:28:20 +01:00
Ingy döt Net
a5394c04a2 Add custom constructors to multiple loaders
When someone writes a subclass of the YAMLObject class, the constructors
will now be added to all 3 (non-safe) loaders.

Furthermore, we support the class variable `yaml_loader` being a list,
offering more control of which loaders are affected.

To support safe_load in your custom class you could add this:

    yaml_loader = yaml.SafeLoader

    yaml_loader = yaml.YAMLObject.yaml_loader
    yaml_loader.append(yaml.SafeLoader)
2019-11-18 11:59:54 +01:00
Tina Müller (tinita)
8d7a78003a Change default loader for yaml.add_constructor (#287)
* Change default loader for yaml.add_constructor

If the Loader parameter is not given, add constructor to
all three loaders
2019-11-18 11:59:54 +01:00
Matt Davis
0f64cbfa54 changes for 5.1.2 release 2019-07-30 18:21:30 -07:00
Matt Davis
5986257f9f changes for 5.1.1 release 2019-06-06 15:14:10 -07:00
Ingy döt Net
e471e86bf6 Updates for 5.1 release 2019-03-13 08:45:34 -07:00
Tina Müller
507a464ce6 Make default_flow_style=False 2019-03-08 09:09:48 -08:00
Tina Müller
07c88c6c1b Allow to turn off sorting keys in Dumper 2019-03-08 09:09:48 -08:00
Tina Müller
857dff153d Apply FullLoader/UnsafeLoader changes to lib3 2019-03-08 09:09:48 -08:00
scauligi
d13a3d0f96 Fix for bug https://github.com/yaml/pyyaml/issues/118 2019-02-27 18:07:29 -08:00
Florian Bruhin
9959328b41 Import Hashable from collections.abc
In Python 3.7, importing ABCs directly from the 'collections' module shows a
warning (and in Python 3.8 it will stop working) - see
c66f9f8d39

Since this is only done in lib3/ which is Python 3 only, we can unconditionally
import it from collections.abc instead.

This fixes the following DeprecationWarning:

.../site-packages/yaml/__init__.py:75: in load
    return loader.get_single_data()
.../site-packages/yaml/constructor.py:37: in get_single_data
    return self.construct_document(node)
.../site-packages/yaml/constructor.py:46: in construct_document
    for dummy in generator:
.../site-packages/yaml/constructor.py:398: in construct_yaml_map
    value = self.construct_mapping(node)
.../site-packages/yaml/constructor.py:204: in construct_mapping
    return super().construct_mapping(node, deep=deep)
.../site-packages/yaml/constructor.py:126: in construct_mapping
    if not isinstance(key, collections.Hashable):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

name = 'Hashable'

    def __getattr__(name):
        # For backwards compatibility, continue to make the collections ABCs
        # through Python 3.6 available through the collections module.
        # Note, no new collections ABCs were added in Python 3.7
        if name in _collections_abc.__all__:
            obj = getattr(_collections_abc, name)
            import warnings
            warnings.warn("Using or importing the ABCs from 'collections' instead "
                          "of from 'collections.abc' is deprecated, "
                          "and in 3.8 it will stop working",
>                         DeprecationWarning, stacklevel=2)
E           DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
2019-02-27 18:06:38 -08:00
Ingy döt Net
ccc40f3e2b Reverting https://github.com/yaml/pyyaml/pull/74
Revert "Make pyyaml safe by default."

This reverts commit bbcf95fa05.
This reverts commit 7b68405c81.
This reverts commit 517e83e805.
2018-06-30 15:46:56 -07:00
Alex Gaynor
d3eb7daf88 Changes for 4.1 release 2018-06-26 15:08:15 -07:00
Ingy döt Net
4c2e993321 Changes for 4.01 release
This is the first release under new maintainership. A bunch of things
involving resource URLs and copyright details needed updating; in
addition to the normal version and changelog updates.
2018-06-24 17:08:57 -06:00
Tina Müller
f6049c8cd6 Support escaped slash in double quotes "\/"
YAML 1.2 JSON compat
2018-06-24 22:15:31 +02:00
Jon Dufresne
801288d796 Remove commented out Psyco code
From the Psyco website:

> 12 March 2012
>
> Psyco is unmaintained and dead. Please look at PyPy for the
> state-of-the-art in JIT compilers for Python.

http://psyco.sourceforge.net/
2018-04-11 10:02:31 -07:00
Ingy döt Net
0f2afdea77 Revert PR #150 per @asomov
and also explicitly return None if no tokens exist.

Also add a comment to show this.

This 'None' behavior should be tested at some point.
2018-04-10 16:51:43 -07:00
Andrey Somov
a02d17a027 Remove redundant code in Scanner.peek_token() 2018-03-28 10:07:27 +02:00
Alex Gaynor
bbcf95fa05 Now, for py3k! 2017-08-26 10:26:01 -05:00
Jakub Wilk
d856c206fd
Fix typos 2017-08-08 06:05:28 -05:00
Timofei Bondarev
ef744d8609
Improve RepresenterError creation 2017-08-08 06:02:01 -05:00
Peter Murphy
cf1c86cb86 First attack at pyyaml does not support literals in unicode over codepoint 0xffff #25 2017-05-08 16:39:26 +10:00
Daniel Beer
c5b135fe39 Allow colon in a plain scalar in a flow context (#45)
* Allow colon in a plain scalar in a flow context

* Restore behavior of flow mapping with empty value
2017-02-08 13:50:53 -06:00
Kirill Simonov
37be8e0c17 Merged in scorphus/pyyaml (pull request #9)
scanner: use infinitive verb after auxiliary word could
2016-08-25 22:20:32 -05:00
Kirill Simonov
153a194e86 Adding an implicit resolver to a derived loader should not affect the base loader (fixes issue #57). 2016-08-25 17:42:41 -05:00
Kirill Simonov
c95586cfb6 Uniform representation for OrderedDict (fixes issue #61). 2016-08-25 17:30:28 -05:00
Kirill Simonov
f10d92f87b Fixed comparison to () (closes #64). 2016-08-25 16:27:19 -05:00
Kirill Simonov
d737907354 Fixed comparison to None warning (closes issue #64). 2016-08-25 15:55:09 -05:00