Perhaps this is more specifically related to Sage. Anyone have any
suggestions or comments?  Has the issue of sending unicode to external
programs been discussed before?

Is there a better way to implement this without having to modify a
common python site package?

Is there a good way to make this specific to just those interfaces
that can support unicode?


---------- Forwarded message ----------
From: Bill Page <bill.p...@newsynthesis.org>
Date: 5 May 2015 at 23:02
Subject: Re: Unicode in Sage Worksheets
To: sage-cl...@googlegroups.com


As suggested here:

  http://sourceforge.net/p/pexpect/bugs/28/

the following patch to the sage python site package pexpect.py

~$ diff -au 
/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/pexpect.py
pexpectu.py
--- /usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/pexpect.py
      2015-02-23 23:01:50.000000000 +0000
+++ pexpectu.py 2015-05-06 02:26:19.798935537 +0000
@@ -666,7 +666,7 @@
         if self.logfile != None:
             self.logfile.write (str)
             self.logfile.flush()
-        c = os.write(self.child_fd, str)
+        c = os.write(self.child_fd, str.encode("utf-8"))
         return c

     def sendline(self, str=''):

--

and calling it from sage 'expect.py' like this:

~$ diff -au expect.py.orig expect.py
--- expect.py.orig      2015-05-06 02:53:17.150953375 +0000
+++ expect.py   2015-05-06 02:50:25.410955076 +0000
@@ -55,8 +55,8 @@
 # For reasons I don't understand, pexpect2.1 is much
 # worse than pexpect 2.0 for everything Sage does.
 ########################################################
-import pexpect
-from pexpect import ExceptionPexpect
+import pexpectu as pexpect
+from pexpectu import ExceptionPexpect
 from sage.interfaces.interface import Interface, InterfaceElement,
InterfaceFunction, InterfaceFunctionElement, AsciiArtString

 from sage.structure.element import RingElement

--

enables sending unicode characters to FriCAS from a Sage worksheet as
shown here:

https://cloud.sagemath.com/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/files/fricas-CR%20Examples.sagews

Does anyone have a suggestion for how to package this for Sage and or
Sage Math Cloud?  Is

  str.encode("utf-8")

likely to cause errors in interfaces to other programs?

Bill Page.


On 5 May 2015 at 17:40, Bill Page <bill.p...@newsynthesis.org> wrote:
> I tried to use a unicode character in the following worksheet:
>
> https://cloud.sagemath.com/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/files/fricas-CR%20Examples.sagews
>
> The cell input is
>
>   axialratio(expr,z)==(1-Abs(μ(expr,z)))/(1+Abs(μ(expr,z)))
>
> i.e. containing the Greek letter \mu
>
> This is being sent to FriCAS to execute. FriCAS support the use of
> unicode like this and in fact I can use it in a SMC terminal with
> FriCAS.  But in a Sage Worksheet in SMC I get the following error:
>
> Error in lines 1-1
> Traceback (most recent call last):
>   File 
> "/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/.sagemathcloud/sage_server.py",
> line 879, in execute
>     exec compile(block+'\n', '', 'single') in namespace, locals
>   File "", line 1, in <module>
>   File 
> "/projects/4bc39013-7b65-4a65-9d3d-bec4a4ce4d5a/.sagemathcloud/sage_server.py",
> line 920, in execute_with_code_decorators
>     code = code_decorator(code)
>   File "", line 3, in fricas_md
>   File "./expect.py", line 1224, in eval
>     for L in code.split('\n') if L != ''])
>   File "./axiom.py", line 440, in _eval_line
>     E.sendline(line)
>   File 
> "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/pexpect.py",
> line 676, in sendline
>     n = self.send(str)
>   File 
> "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/pexpect.py",
> line 669, in send
>     c = os.write(self.child_fd, str)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bc' in
> position 27: ordinal not in range(128)
>
> --
>
> Is this a limitation of the pexpect interface? Is there some way around this?
>
> Bill.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to