Hello.
I use blog and Sagemath. Sagemath Notebook is great, but I want to
write post in my blog with Sagemath code and result(output).
So I add the XMLRPC server code in server/notebook/twisted.py and make
the APIKEY each user a substitute for password. Because XMLRPC doesn’t
have own secure policy.


############################
# XMLRPC
# 20090709, Bak JinYeong(don...@skku.edu)
# reference page
# http://twistedmatrix.com/trac/wiki/Documentation
# http://twistedmatrix.com/projects/web/documentation/howto/xmlrpc.html
# 
http://twistedmatrix.com/projects/web/documentation/howto/using-twistedweb.html
# http://twistedmatrix.com/documents/8.1.0/api/twisted.web2.xmlrpc.XMLRPC.html
# 
http://twistedmatrix.com/documents/8.1.0/api/twisted.internet.defer.html#maybeDeferred
############################
from twisted.web2 import xmlrpc  # Add to use xmlrpc

class XMLRPC_Sage(xmlrpc.XMLRPC):
    def __init__(self, request):
        self.request = request

    # check the username and apikey
    def login(self, username, apikey):
        return apikey == notebook.user(username).apikey()

    def xmlrpc_make_worksheet_txt(self, request, args):
        print "XMLRPC Request, function name : make_worksheet_txt
Start"
        try:
            # set vaule from xml
            worksheet_txt = args['txt']
            username = args['username']
            apikey = args['apikey']
        except KeyError:
            # If xml is not corrected, send error message.
            raise KeyError
        else:
            import worksheet
            # get the worksheet name to find the exist worksheet in
server
            worksheet_name, _ = worksheet.extract_name(worksheet_txt)
            # set default value
            update = False
            # if it is in xml request, replace it.
            if 'update' in args:
                update = args['update']

            # check the username and apikey
            if self.login(username, apikey):
                try:
                    # search the same name worksheet
                    worksheet = notebook.get_worksheet_with_name
(worksheet_name)
                except KeyError:
                    # no one in notebook, so make new worksheet.
                    worksheet =
notebook.new_worksheet_with_title_from_text(worksheet_txt, username)
                    update = True

                if update:
                    # update the worksheet
                    worksheet.edit_save(worksheet_txt)

                    # delete published worksheet because if it is
published it do not evaluate cell.
                    if worksheet.has_published_version():
                        notebook.delete_worksheet
(worksheet.published_version().filename())

                    # get the cells
                    cells = worksheet.cell_list()
                    # evaluate the all cells
                    for cell in cells:
                        cell.evaluate(username = username)
                        # wait until cell is done. There is not error
handle code.
                        cell_id = cell.id()
                        status, _ = worksheet.check_comp(wait=9999)
                        while 'e' != status:
                            status, _ = worksheet.check_comp
(wait=9999)

                    # quit the worksheet
                    worksheet.quit()

                    # worksheet publish
                    P_worksheet = notebook.publish_worksheet
(worksheet, username)

                # return the worksheet with output
                # change imgsrc
                import re
                addr = 'http%s://' % ('' if not notebook.secure else
's')
                addr += notebook.address if not '' == notebook.address
else 'SAGEADDR'
                addr += '%s' % ('' if 80 == notebook.port else (':' +
str(notebook.port)))
                addr += '/home/' + P_worksheet.filename() + "/cells/"
                ReC = re.compile("id=(\d+?)(.*?)'cell://(.+?)'",
re.DOTALL)
                txt_cells = P_worksheet.edit_text().split('{{{')
                txt_cells = map(lambda txt_cell:ReC.sub(r"id=\1\2'" +
addr + r"\1/\3'", txt_cell), txt_cells)
                print "XMLRPC Request, function name :
make_worksheet_txt Finish"
                return '{{{'.join(txt_cells)
            else:
                # I can't handle this error, so just raise (Exception)
hand.^^
                raise ValueError

…

class Toplevel(resource.PostableResource):
    child_login = RedirectLogin()
    child_simple = sage.server.simple.twist.SimpleServer()
    child_xmlrpc = XMLRPC_Sage   # Add to use xmlrpc - 20090709, Bak
JinYeong(don...@skku.edu)


And I make Textcube(it’s blog tool made in Korea) and WordPress
sagemath XMLRPC client plugin. It works well.
It works like latex plugin.

[Sagemath]3*4*5*6[/Sagemath]
=>
Sage: 3*4*5*6
360

http://nosyu.pe.kr/2048
http://nosyu.mireene.kr/wp/wordpress/


Now I have questions. Please reply it.

1. Can this XMLRPC code add into the public Sagemath source?
It adds several codes and function in list_top.html and user.py. So I
think it’s hard.OTL

2. Is it worth?
I make this code for my desire. So I ask to other that is it worth to
public?

3. Is it legal?
I don’t know about GPL exactly. I just know I can see the source,
modify it and open to the public. But is it illegal that I don’t open
this source?

4. I make this on sage 4.0.2. But latest sage version is 4.1 and
Notebook is rapidly changed. Then it will be changed notebook server
module from twisted to something? I make this to use twisted web2
XMLRPC server. However if it is changed, I can’t use it. So I am
worried about it.

------------------------------------------------------------------------

누구나가 다, 자기 옆에서 눈물을 흘리며 신음하는 불행한 사람들에 비해 자기가 훨씬 더 불행하다고 생각하지요. 이게 바로 우리
가련한 인간들의 오만 중 하나입니다.
- 몬테크리스토 백작
it is the infirmity of our nature always to believe ourselves much
more unhappy than those who groan by our sides!
- The Count of Monte Cristo
c'est un des orgueils de notre pauvre humanité, que chaque homme se
croie plus malheureux qu'un autre malheureux qui pleure et qui gémit à
côté de lui
- Le Comte de Monte-Cristo

박진영 - Bak JinYeong
학부재학생 - Undergraduate
컴퓨터공학전공 - Department of Computer Engineering
정보통신공학부 - School of Information & Communication Engineering
성균관대학교 - SungKyunKwan University
블로그 - http://nosyu.pe.kr
이메일 - don...@skku.edu
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to