Ticket #2347: 2347-2.patch

File 2347-2.patch, 9.3 KB (added by robertwb, 14 years ago)
  • sage/coding/code_bounds.py

    # HG changeset patch
    # User Robert Bradshaw <robertwb@math.washington.edu>
    # Date 1207873519 25200
    # Node ID 4b6c28d7c99deb91a099b94165b1c60140cb6c62
    # Parent  ae6372527ef35309edf6227ffd849a2d7025f3bf
    Removed several unsafe calls to eval()
    
    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/coding/code_bounds.py
    a b def codesize_upper_bound(n,d,q): 
    155155        sage: codesize_upper_bound(10,3,2)
    156156        85
    157157    """
    158     return eval(gap.eval("UpperBound(%s,%s,%s)"%( n, d, q )))
     158    return int(gap.eval("UpperBound(%s,%s,%s)"%( n, d, q )))
    159159
    160160def dimension_upper_bound(n,d,q):
    161161    r"""
  • sage/coding/guava.py

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/coding/guava.py
    a b def BinaryReedMullerCode(r,k): 
    7777    F = GF(2)
    7878    gap.eval("C:=ReedMullerCode("+str(r)+", "+str(k)+")")
    7979    gap.eval("G:=GeneratorMat(C)")
    80     k = eval(gap.eval("Length(G)"))
    81     n = eval(gap.eval("Length(G[1])"))
     80    k = int(gap.eval("Length(G)"))
     81    n = int(gap.eval("Length(G[1])"))
    8282    G = [[gfq_gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
    8383    MS = MatrixSpace(F,k,n)
    8484    return LinearCode(MS(G))
    def QuasiQuadraticResidueCode(p): 
    115115    F = GF(2)
    116116    gap.eval("C:=QQRCode("+str(p)+")")
    117117    gap.eval("G:=GeneratorMat(C)")
    118     k = eval(gap.eval("Length(G)"))
    119     n = eval(gap.eval("Length(G[1])"))
    120     G = [[gfq_gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
     118    k = int(gap.eval("Length(G)"))
     119    n = int(gap.eval("Length(G[1])"))
     120    G = [[gfq_gap_to_sage(gap.eval("G[%s][%s]" % (i,j)),F) for j in range(1,n+1)] for i in range(1,k+1)]
    121121    MS = MatrixSpace(F,k,n)
    122122    return LinearCode(MS(G))
    123123
    def RandomLinearCodeGuava(n,k,F): 
    149149    q = F.order()
    150150    gap.eval("C:=RandomLinearCode("+str(n)+","+str(k)+", GF("+str(q)+"))")
    151151    gap.eval("G:=GeneratorMat(C)")
    152     k = eval(gap.eval("Length(G)"))
    153     n = eval(gap.eval("Length(G[1])"))
    154     G = [[gfq_gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
     152    k = int(gap.eval("Length(G)"))
     153    n = int(gap.eval("Length(G[1])"))
     154    G = [[gfq_gap_to_sage(gap.eval("G[%s][%s]" % (i,j)),F) for j in range(1,n+1)] for i in range(1,k+1)]
    155155    MS = MatrixSpace(F,k,n)
    156156    return LinearCode(MS(G))
    157157
  • sage/combinat/combinat.py

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/combinat/combinat.py
    a b def bell_number(n): 
    256256        TypeError: no coercion of this rational to integer
    257257    """
    258258    ans=gap.eval("Bell(%s)"%ZZ(n))
    259     return ZZ(eval(ans))
     259    return ZZ(ans)
    260260
    261261## def bernoulli_number(n):
    262262##     r"""
  • sage/combinat/dynkin_diagram.py

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/combinat/dynkin_diagram.py
    a b def dynkin_diagram(t): 
    270270    if len(t) == 3:
    271271        affine = "_affine"
    272272
    273     function = eval(f+letter+affine)
     273    function = globals()[f+letter+affine]
    274274    try:
    275275        return function(t)
    276     except RuntimeError:
     276    except KeyError:
    277277        raise TypeError, "Dynkin diagram data not yet hardcoded for type %s"%t
    278278
    279279   
  • sage/combinat/partition.py

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/combinat/partition.py
    a b def Partition(l=None, exp=None, core_and 
    7373    """
    7474    number_of_arguments = 0
    7575    for arg in ['l', 'exp', 'core_and_quotient']:
    76         if eval(arg) is not None:
     76        if locals()[arg] is not None:
    7777            number_of_arguments += 1
    7878
    7979    if number_of_arguments != 1:
  • sage/combinat/partition_algebra.py

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/combinat/partition_algebra.py
    a b def create_set_partitions_function(lette 
    3535        """
    3636        if isinstance(k, (int, Integer)):
    3737            if k > 0:
    38                 return eval('SetPartitions' + letter + 'k_k(k)')
     38                return globals()['SetPartitions' + letter + 'k_k'](k)
    3939        elif is_RealNumber(k):
    4040            if k - floor(k) == 0.5:
    41                 return eval('SetPartitions' + letter + 'khalf_k(floor(k))')
     41                return globals()['SetPartitions' + letter + 'khalf_k'](floor(k))
    4242
    4343        raise ValueError, "k must be an integer or an integer + 1/2"
    4444
  • sage/combinat/skew_partition.py

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/combinat/skew_partition.py
    a b def SkewPartitions(n=None, row_lengths=N 
    589589    """
    590590    number_of_arguments = 0
    591591    for arg in ['n', 'row_lengths']:
    592         if eval(arg) is not None:
     592        if locals()[arg] is not None:
    593593            number_of_arguments += 1
    594594
    595595    if number_of_arguments > 1:
  • sage/functions/transcendental.py

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/functions/transcendental.py
    a b def __prep_num(x): 
    3939
    4040CC = complex_field.ComplexField()
    4141I = CC.gen(0)
    42 def __eval(x):
    43     return eval(x)
    4442
    4543def exponential_integral_1(x, n=0):
    4644    r"""
  • sage/rings/complex_double.pyx

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/rings/complex_double.pyx
    a b cdef class ComplexDoubleField_class(sage 
    271271            elif isinstance(x, tuple):
    272272                return ComplexDoubleElement(x[0], x[1])
    273273            elif isinstance(x, str):
    274                 t = eval(x.replace(' ',''), {"I":self.gen(),"i":self.gen(), 'RealNumber':float})
     274                t = cdf_parser.parse_expression(x)
    275275                if isinstance(t, float):
    276276                    return ComplexDoubleElement(t, 0)
    277277                else:
    def ComplexDoubleField(): 
    17611761    """
    17621762    return _CDF   
    17631763
     1764from sage.calculus.parser import Parser
     1765cdef cdf_parser = Parser(float, float,  {"I" : _CDF.gen(), "i" : _CDF.gen()})
     1766
     1767
     1768
    17641769#####
    17651770#(fset 'wrap
    17661771#   [?\C-s ?F ?u ?n ?c ?\C-a ?\C-s ?g ?s ?l ?_ ?c ?o ?m ?p ?l ?e ?x ?_ ?\C-f ?\C-b ?\C-  ?\C-s ?  ?\C-b ?\M-w ?\C-a return ?\C-p ?  ?  ?  ?  ?d ?e ?f ?  ?\C-y ?( ?s ?e ?l ?f ?) ?: return ?r ?\" ?\" ?\" return ?\" ?\" ?\" return ?r ?e ?t ?u ?r ?n ?  ?n ?e ?w ?_ ?e ?l ?e ?m ?e ?n ?t ?( ?g backspace ?g ?s ?l ?_ ?c ?o ?m ?p ?l ?e ?x ?_ ?\C-y ?( ?s ?e ?l ?f ?. ?_ ?c ?o ?m ?p ?l ?e ?x ?) ?) ?\C-a ?\C-s ?F ?u ?n ?c ?\C-a ?\C-n ?\C-k ?\C-y ?\C-r ?r ?\" ?\" ?\C-f ?\C-f ?\C-f ?\C-f return ?\C-y return ?\C-p ?\M-q ?\C-n ?\C-n ?\C-a backspace ?\C-n ?\C-n ?\C-e return ?\C-n ?\C-n ?\C-n ?\C-n])
  • sage/rings/number_field/number_field.py

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/rings/number_field/number_field.py
    a b class NumberField_generic(number_field_b 
    27612761        except AttributeError:
    27622762            k = self.pari_bnf(proof)
    27632763            s = str(k.getattr('reg'))
    2764             self.__regulator = eval(s)
     2764            self.__regulator = float(s) # sage.rings.real_mpfr.create_RealNumber(s)
    27652765        return self.__regulator
    27662766
    27672767    def residue_field(self, prime, names = None, check = False):
  • sage/rings/polynomial/polynomial_ring.py

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/rings/polynomial/polynomial_ring.py
    a b class PolynomialRing_general(sage.algebr 
    222222                return x.sage_poly(self)
    223223            except:
    224224                raise TypeError, "Unable to coerce singular object"
    225         elif isinstance(x , str) and self._has_singular:
    226             self._singular_().set_ring()
     225        elif isinstance(x , str):
    227226            try:
    228                 return self._singular_().parent(x).sage_poly(self)
    229             except:
     227                from sage.calculus.parser import Parser, LookupNameMaker
     228                R = self.base_ring()
     229                p = Parser(integer.Integer, R, LookupNameMaker({self.variable_name(): self.gen()}, R))
     230                return self(p.parse(x))
     231            except NameError:
    230232                raise TypeError,"Unable to coerce string"
    231233        elif isinstance(x, FractionFieldElement):
    232234            if x.denominator().is_unit():
  • sage/schemes/elliptic_curves/cm.py

    diff -r ae6372527ef3 -r 4b6c28d7c99d sage/schemes/elliptic_curves/cm.py
    a b def hilbert_class_polynomial(D): 
    5858         raise ValueError, "D (=%s) must be a discriminant"%D
    5959    magma.eval("R<x> := PolynomialRing(IntegerRing())")
    6060    f = str(magma.eval("HilbertClassPolynomial(%s)"%D))
    61     x = PolynomialRing(IntegerRing(), name='x').gen()
    62     f = f.replace('^','**')
    63     return eval(f)
     61    return IntegerRing()['x'](f)
    6462
    6563def cm_j_invariants(K):
    6664    r"""