Ticket #10499: trac_10499_fix_magma_free.patch

File trac_10499_fix_magma_free.patch, 2.2 KB (added by goodok.alex, 11 years ago)
  • sage/interfaces/magma_free.py

    # HG changeset patch
    # User Alexey U. Gudchenko <proga@goodok.ru>
    # Date 1294355453 -10800
    # Node ID dbf18b4f9625b94d6cc420bf19db4fbadd385fb8
    # Parent  120c07be6358d93bcff503363d379c26b8342f2b
    10499: fix broken magma_free interface
    
    diff -r 120c07be6358 -r dbf18b4f9625 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")
    4360    class MagmaExpr(str):
    4461       def __repr__(self):
    4562          return str(self)
    46     return MagmaExpr(results[i:j])
     63    return MagmaExpr(res)
    4764
    4865class MagmaFree:
    4966    """