Ticket #96 (new defect)

Opened 2 years ago

Last modified 1 year ago

Added note about UnicodeError instead of the tuple of multiple classes. Also, bumping this ;-)

Reported by: mike@digsby.com Assigned to: xi
Priority: normal Component: pysyck
Severity: normal Keywords:
Cc:

Description

>>> import syck
>>> syck.dump({'blah' : '\xea\xd3'})
Traceback (most recent call last):
  File "C:\workspace\Digsby\syck_test.py", line 2, in <module>
    syck.dump({'blah' : '\xea\xd3'})
  File "C:\workspace\dpython\lib\site-packages\syck\dumpers.py", line 295, in dump
    dumper.dump(object)
  File "C:\workspace\dpython\lib\site-packages\syck\dumpers.py", line 23, in dump
    self.emit(self._convert(object, {}))
  File "C:\workspace\dpython\lib\site-packages\syck\dumpers.py", line 40, in _convert
    self._convert(value, object_to_node)
  File "C:\workspace\dpython\lib\site-packages\syck\dumpers.py", line 28, in _convert
    node = self.represent(object)
  File "C:\workspace\dpython\lib\site-packages\syck\dumpers.py", line 97, in represent
    return representer(object)
  File "C:\workspace\dpython\lib\site-packages\syck\dumpers.py", line 112, in represent_str
    return _syck.Scalar(object.encode('ascii'), tag="tag:yaml.org,2002:str")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

This can be fixed by changing line 115 of dumpers.py from

        except UnicodeDecodeError:

to

        except (UnicodeDecodeError, UnicodeEncodeError):

I left the UnicodeDecodeError? in the except clause, but I don't think catching it is necessary unless _syck.Scalar(...) can raise a UnicodeDecodeError? (I wasn't certain of this, nor am I sure how to find out).

Feel free to contact me for more info.

Attachments

Change History

08/02/09 11:14:27 changed by anonymous

  • summary changed from Encoding error when dumping binary data to Added note about UnicodeError instead of the tuple of multiple classes. Also, bumping this ;-).

Alternatively instead of

 except (UnicodeDecodeError, UnicodeEncodeError):

the equivalent

 except UnicodeError:

can be used.


Add/Change #96 (Added note about UnicodeError instead of the tuple of multiple classes. Also, bumping this ;-))




Change Properties
Action