Custom Query (121 matches)
Results (13 - 15 of 121)
| Ticket | Resolution | Summary | Owner | Reporter |
|---|---|---|---|---|
| #14 | fixed | Inf and NaN handling needs re-vamp | xi | Scott David Daniels <Scott.Daniels@…> |
| Description |
Trying to import YAML fails in Python 2.5. Even simple patches fail, because the root cause is that NaNs and INFs cannot be marshalled/unmarshalled. Marshalling is used to save and restore compiled python modules, so a tested module can work initially, but later fail to load (when not from source). When handling INFs and NaNs, you need to be careful. 1e300000 is not a safe way to represent infinity, and fails to pickle/unpickle safely from manifest constants. Different C runtimes represent the text for INFs and NaNs differently. Since Python 2.5 folds constants, a simple expression won't solve the problem. The following changes should allow yaml to work on python 2.5a2 on Win2000 (and I think for 64-bit machines as well): =============== constructor.py: =============== *** 231,239 ****
else:
return sign*int(value)
- inf_value = 1e300000
- nan_value = inf_value/inf_value
-
def construct_yaml_float(self, node):
value = str(self.construct_scalar(node))
value = value.replace('_', '')
--- 231,236 ----
***************
***************
*** 242,251 ****
sign = -1
if value[0] in '+-':
value = value[1:]
! if value.lower() == '.inf':
! return sign*self.inf_value
! elif value.lower() == '.nan':
! return self.nan_value
elif ':' in value:
digits = [float(part) for part in value.split(':')]
digits.reverse()
--- 239,253 ----
sign = -1
if value[0] in '+-':
value = value[1:]
! if value.lower() in ('.inf', '.nan'):
! big = 1e300
! bigger = big * big
! while bigger > big and bigger == bigger:
! big = bigger
! bigger = big * big
! if value.lower() == '.nan':
! return bigger / bigger
! return sign * bigger
elif ':' in value:
digits = [float(part) for part in value.split(':')]
digits.reverse()
=============== representer.py: =============== *** 192,200 ****
def represent_long(self, data):
return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(data))
! repr_pos_inf = repr(1e300000)
! repr_neg_inf = repr(-1e300000)
! repr_nan = repr(1e300000/1e300000)
def represent_float(self, data):
repr_data = repr(data)
--- 192,206 ----
def represent_long(self, data):
return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(data))
! big = 1e300
! bigger = big * big
! while bigger > big and bigger == bigger:
! big = bigger
! bigger = big * big
! repr_pos_inf = repr(bigger)
! repr_neg_inf = repr(-bigger)
! repr_nan = repr(bigger / bigger)
! del big, bigger
def represent_float(self, data):
repr_data = repr(data)
|
|||
| #15 | fixed | pyyaml discards '-' sign on negative floats | xi | alex_(a)_alexmole_(o)_co_(o)_uk |
| Description |
yaml.load( 'foo: -3.1' ) returns {'foo': 3.10000} The same technique preserves the sign of integers though, so I presume it must be a bug rather than a yaml feature. |
|||
| #17 | fixed | Single quote character can break emitter output | xi | apopheniac.reply.pyyaml@… |
| Description |
If a string contains a space followed by a single quote character, PyYaml?'s emitter fails to duplicate the single quote. The resulting YAML output yields a parse error: >>> map = {'key': " 'single quoted text'"} >>> yaml.dump(map) "{key: ' 'single quoted text'''}\n" >>> yaml.load(yaml.dump(map)) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/home/apopheniac/lib/python/yaml/__init__.py", line 61, in load return loader.get_data() File "/home/apopheniac/lib/python/yaml/constructor.py", line 41, in get_data return self.construct_document(self.get_node()) File "/home/apopheniac/lib/python/yaml/composer.py", line 23, in get_node return self.compose_document() File "/home/apopheniac/lib/python/yaml/composer.py", line 40, in compose_document node = self.compose_node(None, None) File "/home/apopheniac/lib/python/yaml/composer.py", line 69, in compose_node node = self.compose_mapping_node(anchor) File "/home/apopheniac/lib/python/yaml/composer.py", line 112, in compose_mapping_node while not self.check_event(MappingEndEvent): File "/home/apopheniac/lib/python/yaml/parser.py", line 78, in check_event self.current_event = self.event_generator.next() File "/home/apopheniac/lib/python/yaml/parser.py", line 129, in parse_stream for event in self.parse_block_node(): File "/home/apopheniac/lib/python/yaml/parser.py", line 323, in parse_node for event in collection_events: File "/home/apopheniac/lib/python/yaml/parser.py", line 472, in parse_flow_mapping "expected ',' or '}', but got %r" % token.id, token.start_mark) yaml.parser.ParserError: while scanning a flow mapping in "<string>", line 1, column 1: {key: ' 'single quoted text'''} ^ expected ',' or '}', but got '<scalar>' in "<string>", line 1, column 10: {key: ' 'single quoted text'''} ^ If each single quote is preceded by a non-space character, then the error disappears: >>> map = {"key": " foo'single quoted text'"} >>> yaml.dump(map) "{key: ' foo''single quoted text'''}\n" >>> yaml.load(yaml.dump(map)) {'key': " foo'single quoted text'"} The error seems to lie in the write_single_quoted function of module emitter.py. I've only encountered this problem with scalars represented in single quoted style. |
|||
