Modify

Ticket #2 (reopened defect)

Opened 8 years ago

Last modified 7 years ago

Does PySyck support python pickling

Reported by: tom.denniston@… Owned by: 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

comment:1 Changed 8 years ago 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.

comment:2 Changed 8 years ago by xi

  • Component changed from pyyaml to pysyck

comment:3 Changed 7 years ago by boris

  • Keywords syntax error added
  • Status changed from closed to reopened
  • Resolution worksforme 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)

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as reopened
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.