Ticket #10499: trac_10499_fix_broken_magma_free_interface.patch

File trac_10499_fix_broken_magma_free_interface.patch, 2.3 KB (added by goodok.alex, 11 years ago)

relative to sage-4.6.1.rc0

  • sage/interfaces/magma_free.py

    # HG changeset patch
    # User Alexey U. Gudchenko <proga@goodok.ru>
    # Date 1294521218 -10800
    # Node ID ec1cc27418c37201a9ca2e0e247738b1aaa83714
    # Parent  777e700394384024109c7f3114b68d1e6d810554
    10499: fix magma_free interface
    
    diff -r 777e70039438 -r ec1cc27418c3 sage/interfaces/magma_free.py
    a b  
    2929        sage: magma_free("Factorization(9290348092384)")  # optional - internet
    3030        [ <2, 5>, <290323377887, 1> ]
    3131    """
    32     import urllib
    33     url = "http://magma.maths.usyd.edu.au/calc/"
     32    import urllib, httplib
     33    from xml.dom.minidom import parseString
     34    from string import join
     35   
     36    server = "magma.maths.usyd.edu.au"
     37    processPath = "/xml/calculator.xml"
     38    refererPath = "/calc/"
     39    refererUrl = "http://%s%s" % ( server, refererPath)
    3440    code = "SetColumns(%s);\n"%columns + code
    35     urldata = urllib.urlencode({'commands':code})
    36     results = urllib.urlopen(url, urldata).read()
    37     if strip:
    38         i = results.find('-----\n\n') + 7
    39         j = results.rfind('\n\nTotal time')
    40     else:
    41         i = results.find('Magma V')
    42         j = results.rfind('</textarea>')
     41    params = urllib.urlencode({'input':code})
     42    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept":"Accept: text/html, application/xml, application/xhtml+xml", "Referer": refererUrl}
     43    conn = httplib.HTTPConnection(server)
     44    conn.request("POST", processPath, params, headers)
     45    response = conn.getresponse()
     46    results = response.read()
     47    conn.close()
     48   
     49    xmlDoc = parseString(results)
     50    res = []
     51    reslutsNodeList = xmlDoc.getElementsByTagName('results')
     52    if len(reslutsNodeList) > 0:
     53        reslutsNode = reslutsNodeList[0]
     54        lines = reslutsNode.getElementsByTagName('line')
     55        if len(reslutsNodeList) > 0:
     56            for line in lines:
     57                textNode = line.childNodes[0]
     58                res.append(textNode.data)
     59    res = join(res, "\n")
     60   
    4361    class MagmaExpr(str):
    44        def __repr__(self):
    45           return str(self)
    46     return MagmaExpr(results[i:j])
     62        def __repr__(self):
     63            return str(self)
     64    return MagmaExpr(res)
    4765
    4866class MagmaFree:
    4967    """