Custom Query (171 matches)

Filters
 
Or
 
  
 
Columns

Show under each result:


Results (1 - 3 of 171)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#63 invalid % character cannot start a scalar value token xi sproaticus

Reported by sproaticus, 7 years ago.

Description

A scalar value cannot start with a % (percent sign) character, though the YAML specification only reserves that character at the beginning of a non-indented line for directives and tags (see  http://yaml.org/spec/current.html#id2523453 and  http://yaml.org/spec/current.html#id2524297 ). This character should be legal as the first character of a scalar value, e.g. for Python %s-style string substitution and templates.

>>> yaml.load('yaml: %')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/PIL/__init__.py", line 66, in load
    
  File "build/bdist.linux-i686/egg/yaml/constructor.py", line 38, in get_data
  File "build/bdist.linux-i686/egg/yaml/composer.py", line 27, in get_node
  File "build/bdist.linux-i686/egg/yaml/composer.py", line 34, in compose_document
  File "build/bdist.linux-i686/egg/yaml/composer.py", line 63, in compose_node
  File "build/bdist.linux-i686/egg/yaml/composer.py", line 112, in compose_mapping_node
  File "build/bdist.linux-i686/egg/yaml/composer.py", line 43, in compose_node
  File "build/bdist.linux-i686/egg/yaml/parser.py", line 95, in check_event
  File "build/bdist.linux-i686/egg/yaml/parser.py", line 446, in parse_block_mapping_value
  File "build/bdist.linux-i686/egg/yaml/scanner.py", line 116, in check_token
  File "build/bdist.linux-i686/egg/yaml/scanner.py", line 257, in fetch_more_tokens
yaml.scanner.ScannerError: while scanning for the next token
found character '%' that cannot start any token
  in "<string>", line 1, column 7:
    yaml: %
          ^

Environment:

  • Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
  • PyYAML-3.05-py2.5.egg
#22 fixed Aliases break if there are temporary objects xi tim.hochberg@…

Reported by tim.hochberg@…, 8 years ago.

Description

If an object being passed to represet_data has a shorter lifespan than the representer, the results are unpredictable, but generally bad. In my case, I'm trying to represent a custom omap class. I register a representer like so:

def omap_representer(dumper, data):
    items = [[x, y] for (x, y) in data.iteritems()] 
    return dumper.represent_sequence(u'!omap', items)
    
yaml.add_representer(omap, omap_representer)

If I then dump something that contains multiple omaps, such as [one_omap,another_omap], the representer get's confused because it sees distinct objects that have the same id. Here's an actual example:

>>> a # Note that these are omaps not dictionaries, despite appearances.
[{1: 2, 2: 4}, {1: 99, 2: 88}]

>>> print yaml.dump(a)
- !omap
  - &id001 [1, 2]
  - &id002 [2, 4]
- !omap
  - *id001
  - *id002

Two approaches come to mind to fix this.

  1. Hold onto a reference to the original object as well as to the serialized object in represented_objects. This is what I did as a temporary fix.
  2. Do some sort of weak reference magic to track if an object dies and then delete it from represented_objects. This is more complicated and I'm not entirely sure it would work well. The upside is it's possibly more frugal with memory.

-tim

#53 fixed Allow for immutable subclasses of YAMLObject xi toidinamai

Reported by toidinamai, 7 years ago.

Description

YAMLObject are not directly instantiated so they don't need their own instance attribute (i.e. an own dict). Because of that they should define an empty slots and let subclasses decide whether they want arbitrary instance attributes or not:

--- lib/yaml/__init__.py        (revision 251)
+++ lib/yaml/__init__.py        (working copy)
@@ -272,6 +272,9 @@
     yaml_tag = None
     yaml_flow_style = None
 
+    # no direct instantiation, so allow for immutable subclasses
+    __slots__ = ()
+
     def from_yaml(cls, loader, node):
         """
         Convert a representation node to a Python object.

The same is basically also true for YAMLObjectMetaclass but I doubt there is much use for this in practice.

1 2 3 4 5 6 7 8 9 10 11
Note: See TracQuery for help on using queries.