Modify

Ticket #96 (new defect)

Opened 5 years ago

Last modified 5 years ago

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

Reported by: mike@… Owned by: 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

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

View

Add a comment

Modify Ticket

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


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

 
Note: See TracTickets for help on using tickets.