Custom Query (132 matches)

Filters
 
Or
 
  
 
Columns

Show under each result:


Results (43 - 45 of 132)

Ticket Resolution Summary Owner Reporter
#41 fixed Patch: Use types module instead of hand crafted entities and type(). xi v.haisman@…

Reported by v.haisman@…, 7 years ago.

Description

Hi, I have a patch that makes PyYAML use types module instead of hand crafted entities and type(). The motivation is that it silences some PyDev? error complains, like methods not having self parameter and such.

#167 worksforme Please help saving dict to yaml xi anonymous

Reported by anonymous, 4 years ago.

Description
Hi, is there any way of saving dict to a file in yaml format? I'm using:
----------------------------------------
#!/usr/bin/python
import yaml
y = """
    root:
         - subject1:
            desc: msg1
         - subject2:
            desc: msg2
"""
settings=yaml.load(y)

settings['root'][0]['subject1']['desc'] = "new msg"
print settings

f = open("temp", "w")
f.write(str(settings))
----------------------------------------
but failing miserably, contents of the temp file:
{'root': [{'subject1': {'desc': 'new msg'}}, {'subject2': {'desc': 'msg2'}}]}

expected result:
    root:
         - subject1:
            desc: new msg
         - subject2:
            desc: msg2

Is there anything like yaml.save? Any help greatly appreciated!

Regards,
Tomas
#136 invalid Pure-python emitter fails emitting tag represented as a mapping xi julians@…

Reported by julians@…, 5 years ago.

Description

Hi,

the following snippet will fail with PyYAML 3.08:

#!/usr/bin/env python2.5

import yaml

Dumper = yaml.Dumper

class FooTag(yaml.YAMLObject):

    yaml_dumper = Dumper

    yaml_tag = u'!foo'

    @classmethod
    def to_yaml(cls, dumper, foo):
        return dumper.represent_mapping(None, 
                                        {"foo": "bar"} )

print(yaml.dump(FooTag(), Dumper=Dumper))

The error message is:

Traceback (most recent call last):
  File "tag_not_specified.py", line 20, in <module>
    print(yaml.dump(FooTag(), Dumper=Dumper))
  File "(bogus file name)", line 175, in dump
  File "(bogus file name)", line 165, in dump_all
  File "yaml/representer.py", line 34, in represent
  File "yaml/serializer.py", line 54, in serialize
  File "yaml/serializer.py", line 109, in serialize_node
  File "yaml/emitter.py", line 110, in emit
  File "yaml/emitter.py", line 224, in expect_document_root
  File "yaml/emitter.py", line 238, in expect_node
  File "yaml/emitter.py", line 483, in process_tag
yaml.emitter.EmitterError: tag is not specified

(For some reason the file name in lines two and three of the trace is wrong, I've removed it here.)

The above does work when using libyaml (try substituting CDumper). For what it's worth it will also work when to_yaml emits a scalar instead of a mapping.

I've found that the following patch fixes the issue for me, but I don't understand the code well enough to know all implications of doing so.

diff -ru PyYAML-3.08/lib/yaml/emitter.py PyYAML-3.08-patched/lib/yaml/emitter.py
--- PyYAML-3.08/lib/yaml/emitter.py	2008-12-31 05:24:15.000000000 +1030
+++ PyYAML-3.08-patched/lib/yaml/emitter.py	2009-07-03 13:58:11.000000000 +0930
@@ -480,7 +480,7 @@

                 self.prepared_tag = None
                 return
         if tag is None:
-            raise EmitterError(&quot;tag is not specified&quot;)
+            return
         if self.prepared_tag is None:
             self.prepared_tag = self.prepare_tag(tag)
         if self.prepared_tag:
Note: See TracQuery for help on using queries.