Ticket #2 (reopened defect)

Opened 3 years ago

Last modified 2 years ago

Does PySyck support python pickling

Reported by: tom.denniston@gmail.com Assigned to: xi
Priority: normal Component: pysyck
Severity: normal Keywords: syntax error
Cc:

Description

PySyck looks very cool.

However, it would be ideal if you could pickle an object in YAML format. In other words if a load of the yaml restored the object as an object not a dictionary. Not sure if this functionality exists but I cannot get it to work.

--Tom

Attachments

Change History

04/01/06 02:22:45 changed by xi

  • status changed from new to closed.
  • resolution set to worksforme.

Do you use the latest version of PySyck from pyyaml.org? Note that Python bindings distributed with syck are broken and do not support pickling.

Otherwise you can replace pickle calls with syck:

pickle.dump(object, file) -> syck.dump(object, file)

object = pickle.load(file) -> object = syck.load(file)

data = pickle.dumps(object) -> data = syck.dump(object)

object = pickle.loads(data) -> object = syck.load(data)

Two notes:

I'm closing the ticket. Feel free to reopen it though or add more comments here.

04/01/06 02:23:11 changed by xi

  • component changed from pyyaml to pysyck.

01/13/07 12:19:22 changed by boris

  • keywords set to syntax error.
  • status changed from closed to reopened.
  • resolution deleted.
  • type changed from enhancement to defect.

Hi,

When i built it from source (tried using both the official version or the customized patched version above), it passed all the syck tests but it failed some of the tests in /ext/python/tests. (see test log below)

Indeed - even if i run a simple line of code like:

data = syck.load(syck.dump(datetime.date(2006,12,12)))

It will complain syntax error:

File "./test-syntax.py", line 22, in <module>

data = syck.load(syck.dump(datetime.date(2006,12,12)))

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 408, in load

return loader.load()

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 47, in load

node = self.parse()

_syck.error: ('syntax error', 4, -2)

What is going on? from the test failure it seems that the parser is handling something wrong. I am using PySyck with my other machine which has only python 2.4 installed and it is working beautifully. Many thanks.

Thanks for the help - any more information i can provide?

boris


attached test log:

$ python basic.py .F...F...................F..EE. ====================================================================== ERROR: testTypeFloat (main.BasicTests?)


Traceback (most recent call last):

File "basic.py", line 264, in testTypeFloat

"""

File "basic.py", line 6, in parseOnly

self.assertEqual(obj, syck.load(yaml))

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 408, in load

return loader.load()

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 50, in load

return self._convert(node, {})

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 67, in _convert

node_to_object)

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 84, in _convert

object = self.construct(node)

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 174, in construct

return constructor(node)

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 221, in construct_float

return float(node.value)

ValueError?: invalid literal for float(): 1,230.15

====================================================================== ERROR: testTypeInt (main.BasicTests?)


Traceback (most recent call last):

File "basic.py", line 255, in testTypeInt

"""

File "basic.py", line 6, in parseOnly

self.assertEqual(obj, syck.load(yaml))

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 408, in load

return loader.load()

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 50, in load

return self._convert(node, {})

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 67, in _convert

node_to_object)

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 84, in _convert

object = self.construct(node)

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 174, in construct

return constructor(node)

File "/usr/local/lib/python2.5/site-packages/syck/loaders.py", line 209, in construct_int

return int(node.value)

ValueError?: invalid literal for int() with base 10: '+12,345'

====================================================================== FAIL: testBasicMap (main.BasicTests?)


Traceback (most recent call last):

File "basic.py", line 18, in testBasicMap

"""

File "basic.py", line 8, in roundTrip

self.assertEqual(obj, syck.load(syck.dump(yaml)))

AssertionError?: {'three': 'baz', 'two': 'bar', 'one': 'foo'} != '\none: foo\ntwo: bar\nthree: baz\n'

====================================================================== FAIL: testExampleInvoice (main.BasicTests?)


Traceback (most recent call last):

File "basic.py", line 350, in testExampleInvoice

"""

File "basic.py", line 6, in parseOnly

self.assertEqual(obj, syck.load(yaml))

AssertionError?: {'product': [{'sku': 'BL394D', 'price': 450.0, 'description': 'Basketball', 'quantity': 4}, {'sku': 'BL4438H', 'price': 2392.0, 'description': 'Super Hoop', 'quantity': 1}], 'total': 4443.5200000000004, 'tax': 251.41999999999999, 'comments': 'Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n', 'bill-to': {'given': 'Chris', 'family': 'Dumars', 'address': {'city': 'Royal Oak', 'state': 'MI', 'postal': 48046, 'lines': '458 Walkman Dr.\nSuite #292\n'}}, 'invoice': 34843, 'date': '2001-01-23', 'ship-to': {'given': 'Chris', 'family': 'Dumars', 'address': {'city': 'Royal Oak', 'state': 'MI', 'postal': 48046, 'lines': '458 Walkman Dr.\nSuite #292\n'}}} != {'product': [{'sku': 'BL394D', 'price': 450.0, 'description': 'Basketball', 'quantity': 4}, {'sku': 'BL4438H', 'price': 2392.0, 'description': 'Super Hoop', 'quantity': 1}], 'total': 4443.5200000000004, 'tax': 251.41999999999999, 'comments': 'Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n', 'bill-to': {'given': 'Chris', 'family': 'Dumars', 'address': {'city': 'Royal Oak', 'state': 'MI', 'postal': 48046, 'lines': '458 Walkman Dr.\nSuite #292\n'}}, 'invoice': 34843, 'date': datetime.datetime(2001, 1, 23, 0, 0), 'ship-to': {'given': 'Chris', 'family': 'Dumars', 'address': {'city': 'Royal Oak', 'state': 'MI', 'postal': 48046, 'lines': '458 Walkman Dr.\nSuite #292\n'}}}

====================================================================== FAIL: testSpecSequenceKeyShortcut (main.BasicTests?)


Traceback (most recent call last):

File "basic.py", line 167, in testSpecSequenceKeyShortcut

"""

File "basic.py", line 6, in parseOnly

self.assertEqual(obj, syck.load(yaml))

AssertionError?: {'date': '2001-01-23', 'product': [{'item': 'Super Hoop', 'quantity': 1}, {'item': 'Basketball', 'quantity': 4}, {'item': 'Big Shoes', 'quantity': 1}], 'bill-to': 'Chris Dumars', 'invoice': 34843} != {'date': datetime.datetime(2001, 1, 23, 0, 0), 'product': [{'item': 'Super Hoop', 'quantity': 1}, {'item': 'Basketball', 'quantity': 4}, {'item': 'Big Shoes', 'quantity': 1}], 'bill-to': 'Chris Dumars', 'invoice': 34843}


Ran 31 tests in 0.219s

FAILED (failures=3, errors=2)


Add/Change #2 (Does PySyck support python pickling)




Change Properties
Action