Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: scooby/yaml_examples
base: 202d63e9cf
...
head fork: scooby/yaml_examples
compare: 44332baa4d
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
84 README
@@ -1,84 +0,0 @@
-What is it
-----------
-
-I'm using YAML in another project, and I originally thought I'd just
-put some snippets together.
-
-But I wound up doing a number of short tests to see what the basic
-yaml module in Python thinks. As this is getting a bit long to be a
-gist, I'm just putting it up in a repo.
-
-Helpful tools
--------------
-
-I'm using yaml_mode in emacs to edit; it's reasonably good, but
-doesn't give you much help.
-
-I've also done a few tests with Perl; if you have YAML::XS, try:
-
- cat | perl -MYAML::XS -MData::Dumper \
- -e 'print Dumper(Load(join("", <STDIN>)))'
-
-Or install ysh from libyaml-shell-perl on debian derived systems.
-
-Caveats / broken promises
--------------------------
-
-In many cases, YAML will happily let you express things that are
-perfectly valid YAML, but that make no sense.
-
-Much of the specs are like this, and in fairness, there were only a
-few things that didn't parse.
-
-My big annoyance is that YAML allows mappings to have complex keys and
-python does too, so this should work, right?
-
- [ foo, bar ] : stuff
-
-Not a chance. The sequence is translated to a Python list, not a
-Python tuple. A Python dict can't have a modifiable object as a
-key. In fact, if you're using the dominant heap-centric view of
-objects, it is pretty much impossible to have a mapping data-type
-whose keys are modifiable.
-
-There's an issue attached to this that claims it's not a bug. The docs
-show that you can create complex keys by demonstrating:
-
- ? !!python/tuple [ foo, bar ] : stuff
-
-But once you've got !!python in there, you may as well use pickle.
-
-Before we try to fix this, how do we handle:
-
- - &test [ 1, 2, 3, 4 ]
- - ? *test
- : *test
-
-I'm perfectly happy, the way I work, for the loader to recast this as:
-
- - &test [ 1, 2, 3, 4 ]
- - ? !!python/tuple [ 1, 2, 3, 4]
- : *test
-
-But that might not suit others. YAML doesn't make strong guarantees
-that, after loading, different YAML nodes represent different objects
-in the heap.
-
-TODOs
------
-
-Pull the Unicode linebreak tests out into a separate file so they
-don't confuse every tool (which is almost all of them) that doesn't
-grok Unicode linebreaks.
-
-PROBABLY NOT GOING TODOs
-------------------------
-
-Put together an actual makefile to test that stuff works with
-different combinations of language, test and whatever. After all,
-someone must have done this, right?
-
-Handy Links
------------
-
-http://pyyaml.org/wiki/PyYAMLDocumentation
View
43 README.markdown
@@ -34,3 +34,46 @@ PROBABLY NOT GOING TODOs
Put together an actual makefile to test that stuff works with
different combinations of language, test and whatever. After all,
someone must have done this, right?
+
+Caveats / broken promises
+-------------------------
+
+In many cases, YAML will happily let you express things that are
+perfectly valid YAML, but that make no sense.
+
+Much of the specs are like this, and in fairness, there were only a
+few things that didn't parse.
+
+My big annoyance is that YAML allows mappings to have complex keys and
+python does too, so this should work, right?
+
+ [ foo, bar ] : stuff
+
+Not a chance. The sequence is translated to a Python list, not a
+Python tuple. A Python dict can't have a modifiable object as a
+key. In fact, if you're using the dominant heap-centric view of
+objects, it is pretty much impossible to have a mapping data-type
+whose keys are modifiable.
+
+There's an issue attached to this that claims it's not a bug. The docs
+show that you can create complex keys by demonstrating:
+
+ ? !!python/tuple [ foo, bar ] : stuff
+
+But once you've got !!python in there, you may as well use pickle.
+
+Before we try to fix this, how do we handle:
+
+ - &test [ 1, 2, 3, 4 ]
+ - ? *test
+ : *test
+
+I'm perfectly happy, the way I work, for the loader to recast this as:
+
+ - &test [ 1, 2, 3, 4 ]
+ - ? !!python/tuple [ 1, 2, 3, 4]
+ : *test
+
+But that might not suit others. YAML doesn't make strong guarantees
+that, after loading, different YAML nodes represent different objects
+in the heap.
View
5 example_dumper.py
@@ -79,9 +79,10 @@ def make_hashable(value):
if isinstance(value, list):
return tuple(map(make_hashable, value))
elif isinstance(value, set):
- return frozenset(map(make_hashable, value))
+ return frozenset(value)
elif isinstance(value, dict):
- return tuple(sorted((make_hashable(key), val) for key, val in value.items()))
+ return frozenset((make_hashable(key), make_hashable(val))
+ for key, val in value.items())
else:
return value
def new_items():
View
5 handle_mappings.py
@@ -20,9 +20,10 @@ def make_hashable(value):
if isinstance(value, list):
return tuple(map(make_hashable, value))
elif isinstance(value, set):
- return frozenset(map(make_hashable, value))
+ return frozenset(value)
elif isinstance(value, dict):
- return tuple(sorted((make_hashable(key), val) for key, val in value.items()))
+ return frozenset((make_hashable(key), make_hashable(val))
+ for key, val in value.items())
else:
return value
def new_items():

No commit comments for this range

Something went wrong with that request. Please try again.