[Python-modules-commits] [ruamel.yaml] 01/12: Imported Upstream version 0.10.12

Vincent Bernat bernat at moszumanska.debian.org
Wed Nov 18 07:57:12 UTC 2015


This is an automated email from the git hooks/post-receive script.

bernat pushed a commit to branch master
in repository ruamel.yaml.

commit 3088dac69e227ca3cb17a24f025c8037194c06ed
Author: Vincent Bernat <bernat at debian.org>
Date:   Mon Nov 16 08:08:18 2015 +0100

    Imported Upstream version 0.10.12
---
 .ruamel/__init__.py                         |     2 +
 CHANGES                                     |   106 +
 LICENSE                                     |    21 +
 MANIFEST.in                                 |     2 +
 PKG-INFO                                    |   301 +
 README.rst                                  |   276 +
 __init__.py                                 |    85 +
 comments.py                                 |   434 +
 compat.py                                   |   106 +
 composer.py                                 |   175 +
 configobjwalker.py                          |    65 +
 constructor.py                              |  1129 ++
 cyaml.py                                    |    92 +
 dumper.py                                   |    91 +
 emitter.py                                  |  1243 ++
 error.py                                    |    84 +
 events.py                                   |   105 +
 ext/_ruamel_yaml.c                          | 25891 ++++++++++++++++++++++++++
 ext/_ruamel_yaml.h                          |    23 +
 ext/_ruamel_yaml.pxd                        |   251 +
 ext/_ruamel_yaml.pyx                        |  1526 ++
 ext/api.c                                   |  1392 ++
 ext/config.h                                |    81 +
 ext/dumper.c                                |   394 +
 ext/emitter.c                               |  2329 +++
 ext/loader.c                                |   444 +
 ext/parser.c                                |  1374 ++
 ext/reader.c                                |   469 +
 ext/scanner.c                               |  3580 ++++
 ext/writer.c                                |   141 +
 ext/yaml.h                                  |  1971 ++
 ext/yaml_private.h                          |   655 +
 loader.py                                   |    62 +
 main.py                                     |   352 +
 make_win_whl.py                             |    32 +
 nodes.py                                    |    84 +
 parser_.py                                  |   664 +
 reader.py                                   |   212 +
 representer.py                              |   842 +
 resolver.py                                 |   239 +
 ruamel.yaml.egg-info/PKG-INFO               |   301 +
 ruamel.yaml.egg-info/SOURCES.txt            |    63 +
 ruamel.yaml.egg-info/dependency_links.txt   |     1 +
 ruamel.yaml.egg-info/namespace_packages.txt |     1 +
 ruamel.yaml.egg-info/requires.txt           |     2 +
 ruamel.yaml.egg-info/top_level.txt          |     2 +
 scalarstring.py                             |    48 +
 scanner.py                                  |  1661 ++
 serializer.py                               |   172 +
 setup.cfg                                   |     5 +
 setup.py                                    |   656 +
 test/test_a_dedent.py                       |    42 +
 test/test_anchor.py                         |   229 +
 test/test_comment_manipulation.py           |   393 +
 test/test_comments.py                       |   271 +
 test/test_cyaml.py                          |    11 +
 test/test_indentation.py                    |   101 +
 test/test_json_numbers.py                   |    48 +
 test/test_line_col.py                       |    93 +
 test/test_program_config.py                 |    58 +
 test/test_string.py                         |   107 +
 test/test_yaml.py                           |   164 +
 test/test_z_data.py                         |    32 +
 tokens.py                                   |   192 +
 64 files changed, 51978 insertions(+)

diff --git a/.ruamel/__init__.py b/.ruamel/__init__.py
new file mode 100644
index 0000000..ece379c
--- /dev/null
+++ b/.ruamel/__init__.py
@@ -0,0 +1,2 @@
+import pkg_resources
+pkg_resources.declare_namespace(__name__)
diff --git a/CHANGES b/CHANGES
new file mode 100644
index 0000000..f7590e6
--- /dev/null
+++ b/CHANGES
@@ -0,0 +1,106 @@
+0.10.11: 2015-09-17
+- Fix issue 13: dependency on libyaml to be installed for yaml.h
+
+0.10.10: 2015-09-15
+- Python 3.5 tested with tox
+- pypy full test (old PyYAML tests failed on too many open file handles)
+
+0.10.6-0.10.9: 2015-09-14
+- Fix for issue 9
+- Fix for issue 11: double dump losing comments
+- Include libyaml code
+- move code from 'py' subdir for proper namespace packaging.
+
+0.10.5: 2015-08-25
+- preservation of newlines after block scalars. Contributed by Sam Thursfield.
+
+0.10: 2015-06-22
+- preservation of hand crafted anchor names ( not of the form "idNNN")
+- preservation of map merges ( <<< )
+
+0.9: 2015-04-18
+- collections read in by the RoundTripLoader now have a ``lc`` property
+  that can be quired for line and column ( ``lc.line`` resp. ``lc.col``)
+
+0.8: 2015-04-15
+- bug fix for non-roundtrip save of ordereddict
+- adding/replacing end of line comments on block style mappings/sequences
+
+0.7.2: 2015-03-29
+- support for end-of-line comments on flow style sequences and mappings
+
+0.7.1: 2015-03-27
+- RoundTrip capability of flow style sequences ( 'a: b, c, d' )
+
+0.7 2015-03-26
+- tests (currently failing) for inline sequece and non-standard spacing between
+  block sequence dash and scalar (Anthony Sottile)
+- initial possibility (on list, i.e. CommentedSeq) to set the flow format
+  explicitly
+- RoundTrip capability of flow style sequences ( 'a: b, c, d' )
+
+0.6.1 2015-03-15
+- setup.py changed so ruamel.ordereddict no longer is a dependency
+  if not on CPython 2.x (used to test only for 2.x, which breaks pypy 2.5.0
+  reported by Anthony Sottile)
+
+0.6 2015-03-11
+- basic support for scalars with preserved newlines
+- html option for yaml command
+- check if yaml C library is available before trying to compile C extension
+- include unreleased change in PyYAML dd 20141128
+
+0.5 2015-01-14
+- move configobj -> YAML generator to own module
+- added dependency on ruamel.base (based on feedback from  Sess
+  <leycec at gmail.com>
+
+0.4: 20141125
+- move comment classes in own module comments
+- fix omap pre comment
+- make !!omap and !!set take parameters. There are still some restrictions:
+  - no comments before the !!tag
+- extra tests
+
+0.3: 20141124
+- fix value comment occuring as on previous line (looking like eol comment)
+- INI conversion in yaml + tests
+- (hidden) test in yaml for debugging with auto command
+- fix for missing comment in middel of simple map + test
+
+0.2: 20141123
+- add ext/_yaml.c etc to the source tree
+- tests for yaml to work on 2.6/3.3/3.4
+- change install so that you can include ruamel.yaml instead of ruamel.yaml.py
+- add "yaml" utility with initial subcommands (test rt, from json)
+
+0.1: 20141122
+- merge py2 and py3 code bases
+- remove support for 2.5/3.0/3.1/3.2 (this merge relies on u"" as
+  available in 3.3 and . imports not available in 2.5)
+- tox.ini for 2.7/3.4/2.6/3.3
+- remove lib3/ and tests/lib3 directories and content
+- commit
+- correct --verbose for test application
+- DATA=changed to be relative to __file__ of code
+- DATA using os.sep
+- remove os.path from imports as os is already imported
+- have test_yaml.py exit with value 0 on success, 1 on failures, 2 on
+  error
+- added support for octal integers starting with '0o'
+  keep support for 01234 as well as 0o1234
+- commit
+- added test_roundtrip_data:
+  requirest a .data file and .roundtrip (empty), yaml_load .data
+  and compare dump against original.
+- fix grammar as per David Pursehouse:
+  https://bitbucket.org/xi/pyyaml/pull-request/5/fix-grammar-in-error-messages/diff
+- http://www.json.org/ extra escaped char \/
+  add .skip-ext as libyaml is not updated
+- David Fraser: Extract a method to represent keys in mappings, so that
+  a subclass can choose not to quote them, used in repesent_mapping
+  https://bitbucket.org/davidfraser/pyyaml/
+- add CommentToken and percolate through parser and composer and constructor
+- add Comments to wrapped mapping and sequence constructs (not to scalars)
+- generate YAML with comments
+- initial README
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f6f753a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+ 
+ The MIT License (MIT)
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+     
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
+ THE SOFTWARE.
+
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..aa076f5
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,2 @@
+include README.rst LICENSE CHANGES setup.py
+recursive-include ext *
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..236f99a
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,301 @@
+Metadata-Version: 1.1
+Name: ruamel.yaml
+Version: 0.10.12
+Summary: ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order
+Home-page: https://bitbucket.org/ruamel/yaml
+Author: Anthon van der Neut
+Author-email: a.van.der.neut at ruamel.eu
+License: MIT license
+Description: 
+        ruamel.yaml
+        ===========
+        
+        Starting with 0.10.7 the package has been reorganise and the
+        commandline utility is in its own package ``ruamel.yaml.cmd`` (so
+        installing ``ruamel.yaml`` doesn't pull in possible irrelevant modules
+        only used in the commandline utility)
+        
+        ``ruamel.yaml`` is a YAML package for Python. It is a derivative
+        of Kirill Simonov's `PyYAML 3.11 <https://bitbucket.org/xi/pyyaml>`_
+        which supports YAML1.1
+        
+        Major differences with PyYAML 3.11:
+        
+        - intergrated Python 2 and 3 sources, running on Python 2.6, 2.7 (CPython,
+          PyPy), 3.3 and 3.4.
+        - round trip mode that **includes comments** (block mode, key ordering kept)
+        - support for simple lists as mapping keys by transformation to tuples
+        - ``!!omap`` generates ordereddict (C) on Python 2, collections.OrderedDict
+          on Python 3, and ``!!omap`` is generated for these types.
+        - some `YAML 1.2 <http://yaml.org/spec/1.2/spec.html>`_ enhancements
+          (``0o`` octal prefix, ``\/`` escape)
+        - pep8 compliance
+        - tox and py.test based testing
+        - Tests whether the C yaml library is installed as well as the header
+          files. That library  doesn't generate CommentTokens, so it cannot be used to
+          do round trip editing on comments. It can be used for speeded up normal
+          processing (so you don't need to install ``ruamel.yaml`` and ``PyYaml``).
+          See the section *Optional requirements*.
+        - Basic support for multiline strings with preserved newlines and
+          chomping ( '``|``', '``|+``', '``|-``' ). As this subclasses the string type
+          the information is lost on reassignment. (This might be changed
+          in the future so that the preservation/folding/chomping is part of the
+          parent container, like comments).
+        - RoundTrip preservation of flow style sequences ( 'a: b, c, d') (based
+          on request and test by Anthony Sottile)
+        - anchors names that are hand-crafted (not of the form``idNNN``), are preserved
+        - `merges <http://yaml.org/type/merge.html>`_ in dictionaries are preserved
+        - adding/replacing of comments on block style sequences and mappings
+          with smart column positioning
+        - collection objects (when read in via RoundTripParser) have an ``lc``
+          property that contains line and column info ``lc.line`` and ``lc.col``.
+          Individual positions for mappings and sequences can also be retrieved
+          (``lc.key('a')``, ``lc.value('a')`` resp. ``lc.item(3)``)
+        - preservation of whitelines after block scalars. Contributed by Sam Thursfield.
+        
+        Round trip including comments
+        =============================
+        
+        The major motivation for this fork is the round-trip capability for
+        comments. The integration of the sources was just an initial step to
+        make this easier.
+        
+        adding/replacing comments
+        -------------------------
+        
+        Starting with version 0.8, you can add/replace comments on block style
+        collections (mappings/sequences resuting in Python dict/list). The basic
+        for for this is::
+        
+          from __future__ import print_function
+        
+          import ruamel.yaml
+        
+          inp = """\
+          abc:
+            - a     # comment 1
+          xyz:
+            a: 1    # comment 2
+            b: 2
+            c: 3
+            d: 4
+            e: 5
+            f: 6 # comment 3
+          """
+        
+          data = ruamel.yaml.load(inp, ruamel.yaml.RoundTripLoader)
+          data['abc'].append('b')
+          data['abc'].yaml_add_eol_comment('comment 4', 1)  # takes column of comment 1
+          data['xyz'].yaml_add_eol_comment('comment 5', 'c')  # takes column of comment 2
+          data['xyz'].yaml_add_eol_comment('comment 6', 'e')  # takes column of comment 3
+          data['xyz'].yaml_add_eol_comment('comment 7', 'd', column=20)
+        
+          print(ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper), end='')
+        
+        .. example code add_comment.py
+        
+        Resulting in::
+        
+          abc:
+          - a       # comment 1
+          - b       # comment 4
+          xyz:
+            a: 1    # comment 2
+            b: 2
+            c: 3    # comment 5
+            d: 4              # comment 7
+            e: 5 # comment 6
+            f: 6 # comment 3
+        
+        
+        .. example output add_comment.py
+        
+        
+        If the comment doesn't start with '#', this will be added. The key is is
+        the element index for list, the actual key for dictionaries. As can be seen
+        from the example, the column to choose for a comment is derived
+        from the previous, next or preceding comment column (picking the first one
+        found).
+        
+        Config file formats
+        ===================
+        
+        There are only a few configuration file formats that are easily
+        readable, and editable: JSON, INI/ConfigParser, YAML (XML is to cluttered
+        to be called easily readable).
+        
+        Unfortunately `JSON <http://www.json.org/>`_ doesn't support comments,
+        and although there are some solutions with pre-processed filtering of
+        comments, there are no libraries that support round trip updating of
+        such commented files.
+        
+        INI files support comments, and the excellent `ConfigObj
+        <http://www.voidspace.org.uk/python/configobj.html>`_ library by Foord
+        and Larosa even supports round trip editing with comment preservation,
+        nesting of sections and limited lists (within a value). Retrieval of
+        particular value format is explicit (and extensible).
+        
+        YAML has basic mapping and sequence structures as well support for
+        ordered mappings and sets. It supports scalars are of various types
+        including dates and datetimes (missing in JSON) as a list of
+        YAML has comments, but these are normally thrown away.
+        
+        Block structured YAML is a clean and very human readable
+        format. By extending the Python YAML parser to support round trip
+        preservation of comments, it makes YAML a very good choice for
+        configuration files that are human readable and editable while at
+        the same time interpretable and modifiable by a program.
+        
+        Extending
+        =========
+        
+        There are normally 6 files involved when extending the roundtrip
+        capabilities: the reader, parser, composer and constructor to go from YAML to
+        Python and the resolver, representer, serializer and emitter to go the other
+        way.
+        
+        Extending involves keeping extra data around for the next process step,
+        eventuallly resulting in a different Python object (subclass or alternative),
+        that should behave like the original, but on the way from Python to YAML
+        generates the original (or at least something much closer).
+        
+        Smartening
+        ==========
+        
+        When you use round-tripping, then the complex data you get are
+        already subclasses of the build in types. So you can patch
+        in extra methods or override existing ones. Some methods are already
+        included and you can do::
+        
+            yaml_str = """\
+            a:
+            - b:
+              c: 42
+            - d:
+                f: 196
+              e:
+                g: 3.14
+            """
+        
+        
+            data = yaml.load(yaml_str, Loader=yaml.RoundTripLoader)
+        
+            assert data.mlget(['a', 1, 'd', 'f'], list_ok=True) == 196
+        
+        
+        Examples
+        ========
+        
+        Basic round trip of parsing YAML to Python objects, modifying
+        and generating YAML::
+        
+          from __future__ import print_function
+        
+          import ruamel.yaml
+        
+          inp = """\
+          # example
+          name:
+            # details
+            family: Smith   # very common
+            given: Alice    # one of the siblings
+          """
+        
+          code = ruamel.yaml.load(inp, ruamel.yaml.RoundTripLoader)
+          code['name']['given'] = 'Bob'
+        
+          print(ruamel.yaml.dump(code, Dumper=ruamel.yaml.RoundTripDumper), end='')
+        
+        .. example code small.py
+        
+        Resulting in ::
+        
+          # example
+          name:
+            # details
+            family: Smith   # very common
+            given: Bob      # one of the siblings
+        
+        
+        .. example output small.py
+        
+        
+        YAML handcrafted anchors and references as well as key merging
+        is preserved. The merged keys can transparently be accessed
+        using ``[]`` and ``.get()``::
+        
+          import ruamel.yaml
+        
+          inp = """\
+          - &CENTER {x: 1, y: 2}
+          - &LEFT {x: 0, y: 2}
+          - &BIG {r: 10}
+          - &SMALL {r: 1}
+          # All the following maps are equal:
+          # Explicit keys
+          - x: 1
+            y: 2
+            r: 10
+            label: center/big
+          # Merge one map
+          - <<: *CENTER
+            r: 10
+            label: center/big
+          # Merge multiple maps
+          - <<: [*CENTER, *BIG]
+            label: center/big
+          # Override
+          - <<: [*BIG, *LEFT, *SMALL]
+            x: 1
+            label: center/big
+          """
+        
+          data = ruamel.yaml.load(inp, ruamel.yaml.RoundTripLoader)
+          assert data[7]['y'] == 2
+        
+        
+        .. example code anchor_merge.py
+        
+        
+        Optional requirements
+        =====================
+        
+        If you have the C yaml library and headers installed, as well as
+        the header files for your Python executables then you can use the
+        non-roundtrip but faster C loader en emitter.
+        
+        On Debian systems you should use::
+        
+            sudo apt-get install libyaml-dev python-dev python3-dev
+        
+        you can leave out ``python3-dev`` if you don't use python3
+        
+        For CentOS (7) based systems you should do::
+        
+           sudo yum install libyaml-devel python-devel
+        
+        Testing
+        =======
+        
+        Testing is done using the `tox <https://pypi.python.org/pypi/tox>`_, which
+        uses `virtualenv <https://pypi.python.org/pypi/virtualenv>`_ and
+        `pytest <http://pytest.org/latest/>`_.
+        
+        
+        
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: OS Independent
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Programming Language :: Python :: Implementation :: PyPy
+Classifier: Programming Language :: Python :: Implementation :: Jython
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
+Classifier: Topic :: Text Processing :: Markup
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..3f75a17
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,276 @@
+
+ruamel.yaml
+===========
+
+Starting with 0.10.7 the package has been reorganise and the
+commandline utility is in its own package ``ruamel.yaml.cmd`` (so
+installing ``ruamel.yaml`` doesn't pull in possible irrelevant modules
+only used in the commandline utility)
+
+``ruamel.yaml`` is a YAML package for Python. It is a derivative
+of Kirill Simonov's `PyYAML 3.11 <https://bitbucket.org/xi/pyyaml>`_
+which supports YAML1.1
+
+Major differences with PyYAML 3.11:
+
+- intergrated Python 2 and 3 sources, running on Python 2.6, 2.7 (CPython,
+  PyPy), 3.3 and 3.4.
+- round trip mode that **includes comments** (block mode, key ordering kept)
+- support for simple lists as mapping keys by transformation to tuples
+- ``!!omap`` generates ordereddict (C) on Python 2, collections.OrderedDict
+  on Python 3, and ``!!omap`` is generated for these types.
+- some `YAML 1.2 <http://yaml.org/spec/1.2/spec.html>`_ enhancements
+  (``0o`` octal prefix, ``\/`` escape)
+- pep8 compliance
+- tox and py.test based testing
+- Tests whether the C yaml library is installed as well as the header
+  files. That library  doesn't generate CommentTokens, so it cannot be used to
+  do round trip editing on comments. It can be used for speeded up normal
+  processing (so you don't need to install ``ruamel.yaml`` and ``PyYaml``).
+  See the section *Optional requirements*.
+- Basic support for multiline strings with preserved newlines and
+  chomping ( '``|``', '``|+``', '``|-``' ). As this subclasses the string type
+  the information is lost on reassignment. (This might be changed
+  in the future so that the preservation/folding/chomping is part of the
+  parent container, like comments).
+- RoundTrip preservation of flow style sequences ( 'a: b, c, d') (based
+  on request and test by Anthony Sottile)
+- anchors names that are hand-crafted (not of the form``idNNN``), are preserved
+- `merges <http://yaml.org/type/merge.html>`_ in dictionaries are preserved
+- adding/replacing of comments on block style sequences and mappings
+  with smart column positioning
+- collection objects (when read in via RoundTripParser) have an ``lc``
+  property that contains line and column info ``lc.line`` and ``lc.col``.
+  Individual positions for mappings and sequences can also be retrieved
+  (``lc.key('a')``, ``lc.value('a')`` resp. ``lc.item(3)``)
+- preservation of whitelines after block scalars. Contributed by Sam Thursfield.
+
+Round trip including comments
+=============================
+
+The major motivation for this fork is the round-trip capability for
+comments. The integration of the sources was just an initial step to
+make this easier.
+
+adding/replacing comments
+-------------------------
+
+Starting with version 0.8, you can add/replace comments on block style
+collections (mappings/sequences resuting in Python dict/list). The basic
+for for this is::
+
+  from __future__ import print_function
+
+  import ruamel.yaml
+
+  inp = """\
+  abc:
+    - a     # comment 1
+  xyz:
+    a: 1    # comment 2
+    b: 2
+    c: 3
+    d: 4
+    e: 5
+    f: 6 # comment 3
+  """
+
+  data = ruamel.yaml.load(inp, ruamel.yaml.RoundTripLoader)
+  data['abc'].append('b')
+  data['abc'].yaml_add_eol_comment('comment 4', 1)  # takes column of comment 1
+  data['xyz'].yaml_add_eol_comment('comment 5', 'c')  # takes column of comment 2
+  data['xyz'].yaml_add_eol_comment('comment 6', 'e')  # takes column of comment 3
+  data['xyz'].yaml_add_eol_comment('comment 7', 'd', column=20)
+
+  print(ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper), end='')
+
+.. example code add_comment.py
+
+Resulting in::
+
+  abc:
+  - a       # comment 1
+  - b       # comment 4
+  xyz:
+    a: 1    # comment 2
+    b: 2
+    c: 3    # comment 5
+    d: 4              # comment 7
+    e: 5 # comment 6
+    f: 6 # comment 3
+
+
+.. example output add_comment.py
+
+
+If the comment doesn't start with '#', this will be added. The key is is
+the element index for list, the actual key for dictionaries. As can be seen
+from the example, the column to choose for a comment is derived
+from the previous, next or preceding comment column (picking the first one
+found).
+
+Config file formats
+===================
+
+There are only a few configuration file formats that are easily
+readable, and editable: JSON, INI/ConfigParser, YAML (XML is to cluttered
+to be called easily readable).
+
+Unfortunately `JSON <http://www.json.org/>`_ doesn't support comments,
+and although there are some solutions with pre-processed filtering of
+comments, there are no libraries that support round trip updating of
+such commented files.
+
+INI files support comments, and the excellent `ConfigObj
+<http://www.voidspace.org.uk/python/configobj.html>`_ library by Foord
+and Larosa even supports round trip editing with comment preservation,
+nesting of sections and limited lists (within a value). Retrieval of
+particular value format is explicit (and extensible).
+
+YAML has basic mapping and sequence structures as well support for
+ordered mappings and sets. It supports scalars are of various types
+including dates and datetimes (missing in JSON) as a list of
+YAML has comments, but these are normally thrown away.
+
+Block structured YAML is a clean and very human readable
+format. By extending the Python YAML parser to support round trip
+preservation of comments, it makes YAML a very good choice for
+configuration files that are human readable and editable while at
+the same time interpretable and modifiable by a program.
+
+Extending
+=========
+
+There are normally 6 files involved when extending the roundtrip
+capabilities: the reader, parser, composer and constructor to go from YAML to
+Python and the resolver, representer, serializer and emitter to go the other
+way.
+
+Extending involves keeping extra data around for the next process step,
+eventuallly resulting in a different Python object (subclass or alternative),
+that should behave like the original, but on the way from Python to YAML
+generates the original (or at least something much closer).
+
+Smartening
+==========
+
+When you use round-tripping, then the complex data you get are
+already subclasses of the build in types. So you can patch
+in extra methods or override existing ones. Some methods are already
+included and you can do::
+
+    yaml_str = """\
+    a:
+    - b:
+      c: 42
+    - d:
+        f: 196
+      e:
+        g: 3.14
+    """
+
+
+    data = yaml.load(yaml_str, Loader=yaml.RoundTripLoader)
+
+    assert data.mlget(['a', 1, 'd', 'f'], list_ok=True) == 196
+
+
+Examples
+========
+
+Basic round trip of parsing YAML to Python objects, modifying
+and generating YAML::
+
+  from __future__ import print_function
+
+  import ruamel.yaml
+
+  inp = """\
+  # example
+  name:
+    # details
+    family: Smith   # very common
+    given: Alice    # one of the siblings
+  """
+
+  code = ruamel.yaml.load(inp, ruamel.yaml.RoundTripLoader)
+  code['name']['given'] = 'Bob'
+
+  print(ruamel.yaml.dump(code, Dumper=ruamel.yaml.RoundTripDumper), end='')
+
+.. example code small.py
+
+Resulting in ::
+
+  # example
+  name:
+    # details
+    family: Smith   # very common
+    given: Bob      # one of the siblings
+
+
+.. example output small.py
+
+
+YAML handcrafted anchors and references as well as key merging
+is preserved. The merged keys can transparently be accessed
+using ``[]`` and ``.get()``::
+
+  import ruamel.yaml
+
+  inp = """\
+  - &CENTER {x: 1, y: 2}
+  - &LEFT {x: 0, y: 2}
+  - &BIG {r: 10}
+  - &SMALL {r: 1}
+  # All the following maps are equal:
+  # Explicit keys
+  - x: 1
+    y: 2
+    r: 10
+    label: center/big
+  # Merge one map
+  - <<: *CENTER
+    r: 10
+    label: center/big
+  # Merge multiple maps
+  - <<: [*CENTER, *BIG]
+    label: center/big
+  # Override
+  - <<: [*BIG, *LEFT, *SMALL]
+    x: 1
+    label: center/big
+  """
+
+  data = ruamel.yaml.load(inp, ruamel.yaml.RoundTripLoader)
+  assert data[7]['y'] == 2
+
+
+.. example code anchor_merge.py
+
+
+Optional requirements
+=====================
+
+If you have the C yaml library and headers installed, as well as
+the header files for your Python executables then you can use the
+non-roundtrip but faster C loader en emitter.
+
+On Debian systems you should use::
+
+    sudo apt-get install libyaml-dev python-dev python3-dev
+
+you can leave out ``python3-dev`` if you don't use python3
+
+For CentOS (7) based systems you should do::
+
+   sudo yum install libyaml-devel python-devel
+
+Testing
+=======
+
+Testing is done using the `tox <https://pypi.python.org/pypi/tox>`_, which
+uses `virtualenv <https://pypi.python.org/pypi/virtualenv>`_ and
+`pytest <http://pytest.org/latest/>`_.
+
+
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..be2bf4b
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,85 @@
+# coding: utf-8
+
+from __future__ import print_function
+from __future__ import absolute_import
+
+# install_requires of ruamel.base is not really required but the old
+# ruamel.base installed __init__.py, and thus a new version should
+# be installed at some point
+
+_package_data = dict(
+    full_package_name="ruamel.yaml",
+    version_info=(0, 10, 12),
+    author="Anthon van der Neut",
+    author_email="a.van.der.neut at ruamel.eu",
+    description="ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order",  # NOQA
+    entry_points=None,
+    install_requires=dict(
+        any=["ruamel.base>=1.0.0"],
+        py26=["ruamel.ordereddict"],
+        py27=["ruamel.ordereddict"]
+    ),
+    ext_modules=[ dict(
+        name="_ruamel_yaml",
+        src=["ext/_ruamel_yaml.c", "ext/api.c", "ext/writer.c", "ext/dumper.c",
+                "ext/loader.c", "ext/reader.c", "ext/scanner.c", "ext/parser.c",
+                "ext/emitter.c"],
+        lib=[],
+        # test='#include "ext/yaml.h"\n\nint main(int argc, char* argv[])\n{\nyaml_parser_t parser;\nparser = parser;  /* prevent warning */\nreturn 0;\n}\n'  # NOQA
+        )
+    ],
+    classifiers=[
+        "Programming Language :: Python :: 2.6",
+        "Programming Language :: Python :: 2.7",
+        "Programming Language :: Python :: 3.3",
+        "Programming Language :: Python :: 3.4",
+        "Programming Language :: Python :: 3.5",
+        "Programming Language :: Python :: Implementation :: CPython",
+        "Programming Language :: Python :: Implementation :: PyPy",
+        "Programming Language :: Python :: Implementation :: Jython",
+        "Topic :: Software Development :: Libraries :: Python Modules",
+        "Topic :: Text Processing :: Markup"
+    ]
+)
+
+
+# < from ruamel.util.new import _convert_version
+def _convert_version(tup):
+    """create a PEP 386 pseudo-format conformant string from tuple tup"""
+    ret_val = str(tup[0])  # first is always digit
+    next_sep = "."  # separator for next extension, can be "" or "."
+    for x in tup[1:]:
+        if isinstance(x, int):
+            ret_val += next_sep + str(x)
+            next_sep = '.'
+            continue
+        first_letter = x[0].lower()
+        next_sep = ''
+        if first_letter in 'abcr':
+            ret_val += 'rc' if first_letter == 'r' else first_letter
+        elif first_letter in 'pd':
+            ret_val += '.post' if first_letter == 'p' else '.dev'
+    return ret_val
+
+
+# <
+version_info = _package_data['version_info']
+__version__ = _convert_version(version_info)
+
+del _convert_version
+
+try:
+    from .cyaml import *
+    __with_libyaml__ = True
+except (ImportError, ValueError):  # for Jython
+    __with_libyaml__ = False
+
+import sys
+
+# body extracted to main.py
+try:
+    from .main import *
+except ImportError:
+    from ruamel.yaml.main import *
+
+
diff --git a/comments.py b/comments.py
new file mode 100644
index 0000000..5db056f
--- /dev/null
+++ b/comments.py
@@ -0,0 +1,434 @@
+# coding: utf-8
+
+from __future__ import absolute_import
+from __future__ import print_function
+
+__all__ = ["CommentedSeq", "CommentedMap", "CommentedOrderedMap",
+           "CommentedSet", 'comment_attrib', 'merge_attrib']
+
+"""
+stuff to deal with comments and formatting on dict/list/ordereddict/set
+these are not really related, formatting could be factored out as
+a separate base
+"""
+
+from collections import MutableSet
+
+try:
+    from .compat import ordereddict
+except ImportError:
+    from ruamel.yaml.compat import ordereddict
+
+comment_attrib = '_yaml_comment'
+format_attrib = '_yaml_format'
+line_col_attrib = '_yaml_line_col'
+anchor_attrib = '_yaml_anchor'
+merge_attrib = '_yaml_merge'
+
+class Comment(object):
+    # sys.getsize tested the Comment objects, __slots__ make them bigger
+    # and adding self.end did not matter
+    attrib = comment_attrib
+
+    def __init__(self):
+        self.comment = None  # [post, [pre]]
+        # map key (mapping/omap/dict) or index (sequence/list) to a  list of
+        # dict: post_key, pre_key, post_value, pre_value
+        # list: pre item, post item
+        self._items = {}
+        # self._start = [] # should not put these on first item
+        self._end = []  # end of document comments
+
+    def __str__(self):
+        if self._end:
+            end = ',\n  end=' + str(self._end)
+        else:
+            end = ''
+        return "Comment(comment={0},\n  items={1}{2})".format(
+            self.comment, self._items, end)
+
+    @property
+    def items(self):
+        return self._items
+
+    @property
+    def end(self):
+        return self._end
+
+    @end.setter
+    def end(self, value):
+        self._end = value
+
+    @property
+    def start(self):
+        return self._start
+
+    @end.setter
+    def start(self, value):
+        self._start = value
+
+
+# to distinguish key from None
+def NoComment():
+    pass
+
+
+class Format(object):
+    attrib = format_attrib
+
+    def __init__(self):
+        self._flow_style = None
+
+    def set_flow_style(self):
+        self._flow_style = True
+
+    def set_block_style(self):
+        self._flow_style = False
+
... 51437 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/ruamel.yaml.git



More information about the Python-modules-commits mailing list