#13296: unicode default encoding is not utf-8 in command line
---------------------------------------+------------------------------------
       Reporter:  slabbe               |         Owner:  jason, was  
           Type:  defect               |        Status:  needs_review
       Priority:  major                |     Milestone:  sage-5.3    
      Component:  graphics             |    Resolution:              
       Keywords:  unicode, matplotlib  |   Work issues:              
Report Upstream:  N/A                  |     Reviewers:              
        Authors:  John Palmieri        |     Merged in:              
   Dependencies:                       |      Stopgaps:              
---------------------------------------+------------------------------------

Old description:

> Using sage-5.2.rc0, unicode letter é gets replaced by "é" in matplotlib
> plot:
>
> {{{
> sage: text(u'an accent : é', (1,1), color='red')
> }}}
>
> With #13161 the same problem appears for axes labels :
>
> {{{
> sage: t = text(u'an accent : é', (1,1), color='red')
> sage: t.axes_labels([u'an accent : é', 'Y'])       # broken without
> #13161
> sage: t
> }}}
>
> But, as mentionned in ticket #13161, if the same code is written in a
> file (even without encoding declared), then unicode gets printed
> perfectly :
>
> {{{
> # this is file.sage
> t = text(u'an accent : é', (1,1), color='red')
> t.axes_labels([u'an accent : é', 'Y'])       # broken without #13161
> }}}
>
> Is perfect :
>
> {{{
> sage: attach file.sage
> sage: t
> }}}
>
> What makes it work in a file but not for the command line?

New description:

 {{{utf-8}}} seems to be the default encoding in Python 2.7 for unicode
 strings:

 {{{
 #!python
 Python 2.7.2 (default, May 30 2012, 14:00:43)
 [GCC 4.6.3] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> 'é'
 '\xc3\xa9'
 >>> u'é'
 u'\xe9'
 >>> unicode('é', encoding='utf-8')
 u'\xe9'
 }}}

 But, in sage-5.2.rc0, latin1 seems to be the default :

 {{{
 #!python
 sage: 'é'
 '\xc3\xa9'
 sage: u'é'
 u'\xc3\xa9'
 sage: unicode('é', encoding='latin1')
 u'\xc3\xa9'
 sage: unicode('é', encoding='utf-8')
 u'\xe9'
 }}}

 As reported by John Palmieri, the problem seems to be from ipython:

 {{{
 $ sage --ipython
 Python 2.7.2 (default, May 30 2012, 14:00:43)
 Type "copyright", "credits" or "license" for more information.

 IPython 0.10.2 -- An enhanced Interactive Python.
 ?         -> Introduction and overview of IPython's features.
 %quickref -> Quick reference.
 help      -> Python's own help system.
 object?   -> Details about 'object'. ?object also works, ?? prints more.

 In [1]: 'é'
 Out[1]: '\xc3\xa9'

 In [2]: u'é'
 Out[2]: u'\xc3\xa9'

 In [3]: unicode('é', encoding='utf-8')
 Out[3]: u'\xe9'

 In [4]: unicode('é', encoding='latin1')
 Out[4]: u'\xc3\xa9'
 }}}

 This bug was first reported as a problem in matplotlib used from the
 command line as unicode letter é gets replaced by "é" in matplotlib plot:

 {{{
 sage: text(u'an accent : é', (1,1), color='red')
 }}}

 With #13161 the same problem appears for axes labels :

 {{{
 sage: t = text(u'an accent : é', (1,1), color='red')
 sage: t.axes_labels([u'an accent : é', 'Y'])       # broken without #13161
 sage: t
 }}}

 But, as mentionned in ticket #13161, if the same code is written in a file
 (even without encoding declared), then unicode gets printed perfectly :

 {{{
 # this is file.sage
 t = text(u'an accent : é', (1,1), color='red')
 t.axes_labels([u'an accent : é', 'Y'])       # broken without #13161
 }}}

 Is perfect :

 {{{
 sage: attach file.sage
 sage: t
 }}}

 What makes it work in a file but not for the command line?

--

Comment (by slabbe):

 I updated the title of the ticket and the description for what we learned
 so far, i.e. it is not a problem in matplotlib.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13296#comment:18>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to