summaryrefslogtreecommitdiff
path: root/_doc/api.ryd
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-07-15 20:17:29 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-07-15 20:17:29 +0200
commit0efe181f5bdf6f961aa7658b4a0288af1b63213b (patch)
treebb2ab46a852444b11376108009408ee823a73331 /_doc/api.ryd
parentf6c3fcef0eedf42ad6e25c639091d00dd51e2e99 (diff)
downloadruamel.yaml-0efe181f5bdf6f961aa7658b4a0288af1b63213b.tar.gz
convert to ryd
Diffstat (limited to '_doc/api.ryd')
-rw-r--r--_doc/api.ryd31
1 files changed, 13 insertions, 18 deletions
diff --git a/_doc/api.ryd b/_doc/api.ryd
index 24f06e6..c03355a 100644
--- a/_doc/api.ryd
+++ b/_doc/api.ryd
@@ -14,9 +14,9 @@ istream = stream = doc = "a: 1"
data = dict(a=1)
from pathlib import Path # or: from ruamel.std.pathlib import Path
--- |
-
++++++++++++++++++++++++++++
Departure from previous API
----------------------------
++++++++++++++++++++++++++++
With version 0.15.0 ``ruamel.yaml`` starts to depart from the previous (PyYAML) way
of loading and dumping. During a transition period the original
@@ -68,9 +68,8 @@ yaml.default_flow_style = False
data = yaml.load("abc: 1")
out = Path('/tmp/out.yaml')
yaml.dump(data, out)
-
--- |
-If you previously used an keyword argument ``explicit_start=True`` you
+If you previously used a keyword argument ``explicit_start=True`` you
now do ``yaml.explicit_start = True`` before calling ``dump()``. The
``Loader`` and ``Dumper`` keyword arguments are not supported that
way. You can provide the ``typ`` keyword to ``rt`` (default),
@@ -80,7 +79,7 @@ is possible by setting the attributes ``.Parser``, ``.Constructor``,
``.Emitter``, etc., to the class of the type to create for that stage
(typically a subclass of an existing class implementing that).
-The default loader (`rt`) is a direct derivative of the safe loader, without the
+The default loader (``t`` is a direct derivative of the safe loader, without the
methods to construct arbitrary Python objects that make the ``unsafe`` loader
unsafe, but with the changes needed for round-trip preservation of comments,
etc.. For trusted Python classes a constructor can of course be added to the round-trip
@@ -97,10 +96,10 @@ all functionality of the old interface will be available via
``YAML`` instances (if you are using something that isn't let me know).
Loading
--------
++++++++
Duplicate keys
-++++++++++++++
+^^^^^^^^^^^^^^
In JSON mapping keys should be unique, in YAML they must be unique.
PyYAML never enforced this although the YAML 1.1 specification already
@@ -118,10 +117,10 @@ In the old API this is a warning starting with 0.15.2 and an error in
0.16.0.
Dumping
--------
++++++++
Controls
-++++++++
+^^^^^^^^
On your ``YAML()`` instance you can set attributes e.g with::
@@ -135,7 +134,7 @@ available attributes include:
enforce output of the form ``\U0001f601`` (ignored if ``allow_unicode`` is ``False``)
Transparent usage of new and old API
-------------------------------------
+++++++++++++++++++++++++++++++++++++
If you have multiple packages depending on ``ruamel.yaml``, or install
your utility together with other packages not under your control, then
@@ -159,11 +158,9 @@ else:
data = yml.load(istream)
yml.dump(data, ostream)
--- |
-
Loading with the ``CSafeLoader``, dumping with
``RoundTripLoader``. You need two ``YAML`` instances, but each of them
can be re-used::
-
--- !python |
if ruamel.yaml.version_info < (0, 15):
data = yaml.load(istream, Loader=yaml.CSafeLoader)
@@ -176,8 +173,6 @@ else:
ymlo.explicit_start = True
ymlo.dump(data, ostream)
--- |
-
-
Loading and dumping from ``pathlib.Path`` instances using the
round-trip-loader::
@@ -213,9 +208,9 @@ else:
data = yml.load(inf)
yml.dump(data, outf)
--- |
-
++++++++++++++++++++++
Reason for API change
----------------------
++++++++++++++++++++++
``ruamel.yaml`` inherited the way of doing things from ``PyYAML``. In
particular when calling the function ``load()`` or ``dump()`` a
@@ -256,8 +251,8 @@ This way of doing things leads to several problems:
to enable that another 50+ line changes (non-contiguous) in 3 more files resulting
in diff that is far over 200 lines long.
-- replacing libyaml with something that doesn't both support `0o52`
- and `052` for the integer ``42`` (instead of ``52`` as per YAML 1.2)
+- replacing libyaml with something that doesn't both support ``0o52``
+ and ``052`` for the integer ``42`` (instead of ``52`` as per YAML 1.2)
is difficult