Changed behviour in 0.9.x from unicode to str #51
Comments
The 0.8.1c upload on pypi is broken and 0.9.x is currently not
functional see
eventable/vobject#51
The 0.8.1c upload on pypi is broken and 0.9.x is currently not
functional see
eventable/vobject#51
The 0.8.1c upload on pypi is broken and 0.9.x is currently not
functional see
eventable/vobject#51
|
Run a quick bisect with the testcase, the offending commit is b3f9bbc |
The 0.8.1c upload on pypi is broken and 0.9.x is currently not
functional see
eventable/vobject#51
|
@agx I'm not sure this is actually a regression. After looking through this for the last couple of days, it seems like this is an intentional change to follow a more pythonic standard. |
|
I am using @tobixen calendar-cli mainly to add new events in my calendar. Recently, I realised that .ics files with Greek characters in the summary field raised an exception which might relates to this issue. The problem is identified in base.py and particularly in function defaultSerialize(). I used a workaround to solve this problem. |
|
@ymitsos can you provide the traceback? |
|
sure this is the complete traceback:
and the diff of my workaround:
|
|
Hi all!
I get the error: In [22]: calendar
Out[22]: ---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
/home/ccc/.virtualenvs/p2/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
670 type_pprinters=self.type_printers,
671 deferred_pprinters=self.deferred_printers)
--> 672 printer.pretty(obj)
673 printer.flush()
674 return stream.getvalue()
/home/ccc/.virtualenvs/p2/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
366 if cls in self.type_pprinters:
367 # printer registered in self.type_pprinters
--> 368 return self.type_pprinters[cls](obj, self, cycle)
369 else:
370 # deferred printer
/home/ccc/.virtualenvs/p2/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _repr_pprint(obj, p, cycle)
699 """A pprint that just redirects to the normal repr function."""
700 # Find newlines and replace them with p.break_()
--> 701 output = repr(obj)
702 for idx,output_line in enumerate(output.splitlines()):
703 if idx:
/home/ccc/.virtualenvs/p2/lib/python2.7/site-packages/vobject/base.pyc in __repr__(self)
681
682 def __repr__(self):
--> 683 return self.__str__()
684
685 def prettyPrint(self, level = 0, tabwidth=3):
/home/ccc/.virtualenvs/p2/lib/python2.7/site-packages/vobject/base.pyc in __str__(self)
676 def __str__(self):
677 if self.name:
--> 678 return "<{0}| {1}>".format(self.name, self.getSortedChildren())
679 else:
680 return u'<*unnamed*| {0}>'.format(self.getSortedChildren())
/home/ccc/.virtualenvs/p2/lib/python2.7/site-packages/vobject/base.pyc in __repr__(self)
681
682 def __repr__(self):
--> 683 return self.__str__()
684
685 def prettyPrint(self, level = 0, tabwidth=3):
/home/ccc/.virtualenvs/p2/lib/python2.7/site-packages/vobject/base.pyc in __str__(self)
676 def __str__(self):
677 if self.name:
--> 678 return "<{0}| {1}>".format(self.name, self.getSortedChildren())
679 else:
680 return u'<*unnamed*| {0}>'.format(self.getSortedChildren())
/home/ccc/.virtualenvs/p2/lib/python2.7/site-packages/vobject/base.pyc in __repr__(self)
427
428 def __repr__(self):
--> 429 return self.__str__()
430
431 def prettyPrint(self, level = 0, tabwidth=3):
/home/ccc/.virtualenvs/p2/lib/python2.7/site-packages/vobject/base.pyc in __str__(self)
424
425 def __str__(self):
--> 426 return "<{0}{1}{2}>".format(self.name, self.params, self.valueRepr())
427
428 def __repr__(self):
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 11: ordinal not in range(128) |
|
I think I got something about this issue: >>> vobject.readOne(u"BEGIN VCALENDAR é")
[...]
vobject.base.ParseError: At line 1: Failed to parse line: BEGIN VCALENDAR é(as expected) but >>> vobject.readOne(io.StringIO(u"BEGIN VCALENDAR é"))
[...]
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 16: ordinal not in range(128)(which is not expected) The bug seems to be when dealing with a stream, such as a EDIT: Actually, I read the previous post too fast and missed @ymitsos already spotted it. @ymitsos could you provide more infos on the diff please? I cannot match it with actual code :/ I am affected with Python 2.7.13 (but not in Python 3.6). Also, it should be noted this bug affects Also this case seems to be out of unittests. |
|
This is the diff result on the vobject/base.py file
|
|
Got it!. Sorry, Github search was not really efficient :/ |
|
Just came to think, at some point in the python caldav library I had to remove a call to StringIO as newer versions of vobject seemed to require an ordinary string instead of a stream object. This patch is out in version 0.5, which is available from the mercurial repo hosted at bitbucket since yesterday, but not published at pypi yet. |
|
Get the same error, I think, with The code:
works and returns an object, but I can't run
This on current pip version - vobject (0.9.4.1). Seeing the discussion above, I'm not sure if I'm just using vobject incorrectly some how? |
|
@wpercy but if this was intentional shouldn't the python3 version return
returns
with your argument I would expect it to return a bytestring not a unicode string as it currently does. So the Python2 and Python3 behave differently now (while they behaved consistently before (both giving back unicode objects). It would be nice if the current maintainers would say how it should work so we can go and fix from there. |
|
@agx I'll be digging into this during the week and hope to have a solution and a fix pushed up sometime this weekend or early next week. EDIT: after just one day of digging, I believe you to be right. We should be passing in unicode, encoding it to bytestrings for internal manipulations and then outputting unicode (which, in the case of python 3, should be |
|
I have a workaround posted for calypso
but it would be great to have this fixed in vobject. And yeah, if the python2 and python3 version aim to be consistent python3 needs to return 'str' while python2 needs to return 'unicode' I think. |
|
Any update on this? I have the same problem with Greek as @ymitsos in Odoo while generating calendars, but don't want to change the module if this is to be fixed upstream. |
|
Yeah, this will be fixed in hopefully in the next 2 weeks. |
|
@agx at long last, I think I have this working. Will merge into master and then if you could pull it down and see if it fixes your issues (I tested against the vcard you provided in both Python 2 and 3 and got desired output) that would be awesome. |


While looking into this calypso issue in Debian:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=841247
I noticed that 0.9.x returns str where 0.8 used unicode:
0.8.x:
0.9.x:
This is python 2.7. Code:
ics file used:
Is this a known regression or a desired change in behaviour?
The text was updated successfully, but these errors were encountered: