# HG changeset patch
# User André Apitzsch <andre.apitzsch@st.ovgu.de>
# Date 1323037826 -3600
# Node ID 3de287228365089e414592000d6561efe48b6590
# Parent  ab81fd06a0d8022ca316f851c4cb283820337552
trac 12119: replace deprecated getslice (part 3)

diff --git a/sage/databases/stein_watkins.py b/sage/databases/stein_watkins.py
--- a/sage/databases/stein_watkins.py
+++ b/sage/databases/stein_watkins.py
@@ -220,15 +220,26 @@
     def __getitem__(self, N):
         """ 
         Return the curves of conductor N in this table. (Very slow!)
+        Return all data about curves between the given levels in this
+        database file.
         """
         X = []
-        for C in self:
-            M = C.conductor
-            if M == N:
-                X.append(C)
-            elif M > N:
-                return X
-        return X
+        if isinstance(N, slice):
+            min_level, max_level, step = N.indices(len(list(self)))
+            for C in self:
+                M = C.conductor
+                if M >= min_level and M <= max_level:
+                    X.append(C)
+                elif M > max_level:
+                    return X
+        else:
+            for C in self:
+                M = C.conductor
+                if M == N:
+                    X.append(C)
+                elif M > N:
+                    return X
+            return X
 
     def iter_levels(self):
         """
@@ -254,19 +265,6 @@
                 C.append(E)
         yield C
 
-    def __getslice__(self, min_level, max_level):
-        """
-        Return all data about curves between the given levels in this
-        database file.
-        """
-        X = []
-        for C in self:
-            M = C.conductor
-            if M >= min_level and M <= max_level:
-                X.append(C)
-            elif M > max_level:
-                return X
-            
 
 class SteinWatkinsPrimeData(SteinWatkinsAllData):
     def __init__(self, num):
diff --git a/sage/media/wav.py b/sage/media/wav.py
--- a/sage/media/wav.py
+++ b/sage/media/wav.py
@@ -312,10 +312,18 @@
 
         return list_plot(points, plotjoined=plotjoined, **kwds)
 
-    # returns the ith frame of data in the wave, in the form of a string
     def __getitem__(self, i):
-        n = i*self._width
-        return self._bytes[n:n+self._width]
+        """
+        Returns the `i`-th frame of data in the wave, in the form of a string,
+        if `i` is an integer.
+        Returns a slice of self if `i` is a slice.
+        """
+        if isinstance(i, slice):
+            start, stop, step = i.indices(self._nframes)
+            return self._copy(start, stop)
+        else:
+            n = i*self._width
+            return self._bytes[n:n+self._width]
 
     def slice_seconds(self, start, stop):
         """
@@ -332,10 +340,7 @@
         start = int(start*self.getframerate())
         stop = int(stop*self.getframerate())
         return self[start:stop]
-    
-    def __getslice__(self, start, stop):
-        return self._copy(start, stop)
-    
+
     # start and stop are frame numbers
     def _copy(self, start, stop):
         start = start * self._width
diff --git a/sage/modular/abvar/abvar.py b/sage/modular/abvar/abvar.py
--- a/sage/modular/abvar/abvar.py
+++ b/sage/modular/abvar/abvar.py
@@ -3471,10 +3471,11 @@
 
     def __getitem__(self, i):
         """
-        Return the `i^{th}` decomposition factor of self.
-        
+        Returns the `i^{th}` decomposition factor of self
+        or returns the slice `i` of decompositions of self.
+
         EXAMPLES::
-        
+
             sage: J = J0(389)
             sage: J.decomposition()
             [
@@ -3488,15 +3489,6 @@
             Simple abelian subvariety 389c(1,389) of dimension 3 of J0(389)
             sage: J[-1]
             Simple abelian subvariety 389e(1,389) of dimension 20 of J0(389)
-        """
-        return self.decomposition()[i]
-
-    def __getslice__(self, i, j):
-        """
-        The slice i:j of decompositions of self.
-        
-        EXAMPLES::
-        
             sage: J = J0(125); J.decomposition()
             [
             Simple abelian subvariety 125a(1,125) of dimension 2 of J0(125),
@@ -3509,8 +3501,7 @@
             Simple abelian subvariety 125b(1,125) of dimension 2 of J0(125)
             ]
         """
-        return self.decomposition()[i:j]
-
+        return self.decomposition()[i]
 
 
 class ModularAbelianVariety(ModularAbelianVariety_abstract):
diff --git a/sage/modular/modform/element.py b/sage/modular/modform/element.py
--- a/sage/modular/modform/element.py
+++ b/sage/modular/modform/element.py
@@ -323,40 +323,31 @@
 
     def __getitem__(self, n):
         """
-        Return the `q^n` coefficient of the `q`-expansion of self.
+        Returns the `q^n` coefficient of the `q`-expansion of self or
+        returns a list containing the `q^i` coefficients of self
+        where `i` is in slice `n`.
 
         EXAMPLES::
-        
+
             sage: f = ModularForms(DirichletGroup(17).0^2,2).2
             sage: f.__getitem__(10)
             zeta8^3 - 5*zeta8^2 - 2*zeta8 + 10
             sage: f[30]
             -2*zeta8^3 - 17*zeta8^2 + 4*zeta8 + 29
-        """
-        return self.q_expansion(n+1)[int(n)]
-    
-    def __getslice__(self, i, j):
-        """
-        Return a list containing the `q^i` through `q^j` coefficients of self.
-
-        EXAMPLES::
-        
-            sage: f = ModularForms(DirichletGroup(17).0^2,2).2
             sage: f[10:15]
             [zeta8^3 - 5*zeta8^2 - 2*zeta8 + 10,
             -zeta8^3 + 11,
             -2*zeta8^3 - 6*zeta8^2 + 3*zeta8 + 9,
             12,
             2*zeta8^3 - 7*zeta8^2 + zeta8 + 14]
-
-            sage: f.__getslice__(10,15)
-            [zeta8^3 - 5*zeta8^2 - 2*zeta8 + 10,
-            -zeta8^3 + 11,
-            -2*zeta8^3 - 6*zeta8^2 + 3*zeta8 + 9,
-            12,
-            2*zeta8^3 - 7*zeta8^2 + zeta8 + 14]
         """
-        return self.q_expansion(j+1).list()[int(i):int(j)]
+        if isinstance(n, slice):
+            if n.stop is None:
+                return self.q_expansion().list()[n]
+            else:
+                return self.q_expansion(n.stop+1).list()[n]
+        else:
+            return self.q_expansion(n+1)[int(n)]
 
     def padded_list(self, n):
         """
diff --git a/sage/plot/animate.py b/sage/plot/animate.py
--- a/sage/plot/animate.py
+++ b/sage/plot/animate.py
@@ -138,21 +138,13 @@
 
     def __getitem__(self, i):
         """
-        Get a frame from an animation.
-        
+        Get a frame from an animation or
+        slice this animation returning a subanimation.
+
         EXAMPLES::
-        
+
             sage: a = animate([x, x^2, x^3, x^4])
             sage: a[2].show()       # optional -- ImageMagick
-        """
-        return self.__frames[i]
-
-    def __getslice__(self, *args):
-        """
-        Slice this animation returning a subanimation.
-        
-        EXAMPLES::
-        
             sage: a = animate([circle((i,-i), 1-1/(i+1), hue=i/10) for i in srange(0,2,0.2)], 
             ...               xmin=0,ymin=-2,xmax=2,ymax=0,figsize=[2,2])
             sage: a
@@ -162,7 +154,10 @@
             Animation with 4 frames
             sage: a[3:7].show() # optional -- ImageMagick
         """
-        return Animation(self.__frames.__getslice__(*args), **self.__kwds)
+        if isinstance(i, slice):
+            return Animation(self.__frames[i], **self.__kwds)
+        else:
+            return self.__frames[i]
 
     def _repr_(self):
         """
diff --git a/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py b/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py
--- a/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py
+++ b/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py
@@ -396,44 +396,50 @@
 
     def __getitem__(self, n):
         """
-        Returns the coefficient of x^n
+        Returns the coefficient of x^n if `n` is an integer,
+        returns the monomials of self of degree in slice `n` if `n` is a slice.
 
-        EXAMPLES:
+        EXAMPLES::
+
         sage: K = Qp(13,7)
-        sage: R.<t> = K[]       
+        sage: R.<t> = K[]
         sage: a = 13^7*t^3 + K(169,4)*t - 13^4
         sage: a[1]
         13^2 + O(13^4)
-        """
-        if n >= len(self._relprecs):
-            return self.base_ring()(0)
-        if not self._list is None:
-            return self._list[n]
-        return self.base_ring()(self.base_ring().prime_pow(self._valbase) * self._poly[n], absprec = self._valbase + self._relprecs[n])
-
-    def __getslice__(self, i, j):
-        """
-        EXAMPLES:
-        sage: K = Qp(13,7)
-        sage: R.<t> = K[]       
-        sage: a = 13^7*t^3 + K(169,4)*t - 13^4
         sage: a[1:2]
         (13^2 + O(13^4))*t
         """
-        if i < 0:
-            i = len(self._relprecs) + i
-            if i < 0:
-                raise IndexError, "list index out of range"
-        if j > len(self._relprecs):
-            j = len(self._relprecs)
-        elif j < 0:
-            j = len(self._relprecs) + j
-            if j < 0:
-                raise IndexError, "list index out of range"
-        if i >= j:
-            return Polynomial_padic_capped_relative_dense(self.parent(), [])
+        if isinstance(n, slice):
+            start, stop = n.start, n.stop
+            if start is None:
+                start = 0
+            elif start < 0:
+                start = len(self._relprecs) + start
+                if start < 0:
+                    raise IndexError("list index out of range")
+            if stop > len(self._relprecs) or stop is None:
+                stop = len(self._relprecs)
+            elif stop < 0:
+                stop = len(self._relprecs) + stop
+                if stop < 0:
+                    raise IndexError("list index out of range")
+            if start >= stop:
+                return Polynomial_padic_capped_relative_dense(self.parent(), [])
+            else:
+                return Polynomial_padic_capped_relative_dense(self.parent(),
+                    (self._poly[start:stop], self._valbase,
+                    [infinity]*start + self._relprecs[start:stop], False,
+                    None if self._valaddeds is None else [infinity]*start
+                    + self._valaddeds[start:stop],
+                    None if self._list is None else [self.base_ring()(0)]
+                    * start + self._list[start:stop]), construct = True)
         else:
-            return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly[i:j], self._valbase, [infinity]*i + self._relprecs[i:j], False, None if self._valaddeds is None else [infinity]*i + self._valaddeds[i:j], None if self._list is None else [self.base_ring()(0)] * i + self._list[i:j]), construct = True)
+            if n >= len(self._relprecs):
+                return self.base_ring()(0)
+            if not self._list is None:
+                return self._list[n]
+            return self.base_ring()(self.base_ring().prime_pow(self._valbase)
+                * self._poly[n], absprec = self._valbase + self._relprecs[n])
 
     def _add_(self, right):
         """
diff --git a/sage/rings/polynomial/polynomial_element_generic.py b/sage/rings/polynomial/polynomial_element_generic.py
--- a/sage/rings/polynomial/polynomial_element_generic.py
+++ b/sage/rings/polynomial/polynomial_element_generic.py
@@ -291,7 +291,8 @@
         
     def __getitem__(self,n):
         """
-        Return the n-th coefficient of this polynomial.
+        Return the `n`-th coefficient of this polynomial if `n` is an integer,
+        returns the monomials of self of degree in slice `n` if `n` is a slice.
 
         Negative indexes are allowed and always return 0 (so you can
         view the polynomial as embedding Laurent series).
@@ -307,16 +308,7 @@
             sage: f[5]
             0.0
             sage: f[-1]
-            0.0            
-        """
-        if not self.__coeffs.has_key(n):
-            return self.base_ring()(0)
-        return self.__coeffs[n]
-
-    def __getslice__(self, i, j):
-        """
-        EXAMPLES::
-
+            0.0
             sage: R.<x> = PolynomialRing(RealField(19), sparse=True)
             sage: f = (2-3.5*x)^3; f
             -42.875*x^3 + 73.500*x^2 - 42.000*x + 8.0000
@@ -325,17 +317,25 @@
             sage: f[:2]
             -42.000*x + 8.0000
             sage: f[2:]
-            -42.875*x^3 + 73.500*x^2        
+            -42.875*x^3 + 73.500*x^2
         """
-        if i < 0:
-            i = 0
-        v = {}
-        x = self.__coeffs
-        for k in x.keys():
-            if i <= k and k < j:
-                v[k] = x[k]
-        P = self.parent()
-        return P(v)
+        if isinstance(n, slice):
+            start, stop = n.start, n.stop
+            if start < 0:
+                start = 0
+            if stop is None:
+                stop = len(self.__coeffs) + 1
+            v = {}
+            x = self.__coeffs
+            for k in x.keys():
+                if start <= k and k < stop:
+                    v[k] = x[k]
+            P = self.parent()
+            return P(v)
+        else:
+            if not self.__coeffs.has_key(n):
+                return self.base_ring()(0)
+            return self.__coeffs[n]
 
     def _unsafe_mutate(self, n, value):
         r"""
diff --git a/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx b/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx
--- a/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx
+++ b/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx
@@ -281,9 +281,10 @@
         return Polynomial_integer_dense_ntl, \
                (self.parent(), self.list(), False, self.is_gen())
 
-    def __getitem__(self, long n):
+    def __getitem__(self, n):
         r"""
-        Returns coefficient of `x^n`, or zero if n is negative.
+        Returns coefficient of the monomial of degree `n` if `n` is an integer,
+        returns the monomials of self of degree in slice `n` if `n` is a slice.
 
         EXAMPLES::
 
@@ -299,21 +300,6 @@
             0
             sage: f[-1]
             0
-        """
-        cdef Integer z = PY_NEW(Integer)
-        if n < 0 or n > ZZX_deg(self.__poly):
-            return z
-        else:
-            # Note that the NTL documentation blesses this direct access of the "rep" member in ZZX.txt.
-            #  Check the "Miscellany" section.
-            ZZ_to_mpz(&z.value, &self.__poly.rep.elts()[n])
-            return z
-
-    def __getslice__(self, long i, long j):
-        r"""
-        EXAMPLES::
-
-            sage: R.<x> = PolynomialRing(ZZ, implementation='NTL')
             sage: f = 1 + x + 2*x^2 + 3*x^3 + 4*x^4 + 5*x^5
             sage: f[2:4]
             3*x^3 + 2*x^2
@@ -322,12 +308,24 @@
             sage: f[4:100]
             5*x^5 + 4*x^4
         """
+        cdef Integer z = PY_NEW(Integer)
         cdef long k
-        i = max(0, i)
-        j = min(j, self.degree()+1)
-        v = [self[k] for k from i <= k < j]
-        P = self.parent()
-        return P([0] * int(i) + v)
+        if isinstance(n, slice):
+            start, stop = n.start, n.stop
+            if stop > self.degree() + 1 or stop is None:
+                stop = self.degree() + 1
+            start = max(0, start)
+            v = [self[k] for k from start <= k < stop]
+            P = self.parent()
+            return P([0] * int(start) + v)
+        else:
+            if n < 0 or n > ZZX_deg(self.__poly):
+                return z
+            else:
+                # Note that the NTL documentation blesses this direct access of the "rep" member in ZZX.txt.
+                #  Check the "Miscellany" section.
+                ZZ_to_mpz(&z.value, &self.__poly.rep.elts()[n])
+            return z
 
     def _repr(self, name=None, bint latex=False):
         """
diff --git a/sage/rings/polynomial/polynomial_rational_flint.pyx b/sage/rings/polynomial/polynomial_rational_flint.pyx
--- a/sage/rings/polynomial/polynomial_rational_flint.pyx
+++ b/sage/rings/polynomial/polynomial_rational_flint.pyx
@@ -358,51 +358,38 @@
         mpz_set_si(deg.value, fmpq_poly_degree(self.__poly))
         return deg
 
-    def __getitem__(self, long n):
+    def __getitem__(self, n):
         """
-        Returns the `n`th coefficient of self.
-        
+        Returns coefficient of the monomial of degree `n` if `n` is an integer,
+        returns the monomials of self of degree in slice `n` if `n` is a slice.
+
         INPUT:
-        
+
         - ``n`` - Degree of the monomial whose coefficient is to be returned
-        
+                  or a slice.
+
         EXAMPLES::
-            
+
             sage: R.<t> = QQ[]
             sage: f = 1 + t + t^2/2 + t^3/3 + t^4/4
             sage: f[-1], f[0], f[3], f[5]            # indirect doctest
             (0, 1, 1/3, 0)
-        """
-        cdef Rational z = PY_NEW(Rational)
-        if 0 <= n and n < fmpq_poly_length(self.__poly):
-            fmpq_poly_get_coeff_mpq(z.value, self.__poly, n)
-        return z
-
-    def __getslice__(self, long i, long j):
-        """
-        Returns the subpolynomial of self from the `i`th to the `j`th 
-        coefficient, where the lower bound is inclusive and the upper bound 
-        is exclusive.
-        
-        INPUT:
-        
-        - ``i`` - Lower index for the slice
-        - ``j`` - Upper index for the slice
-        
-        EXAMPLES::
-        
-            sage: R.<t> = QQ[]
-            sage: f = 1 + t + t^2/2 + t^3/3 + t^4/4
             sage: f[1:3]                             # indirect doctest
             1/2*t^2 + t
         """
+        cdef Rational z = PY_NEW(Rational)
         cdef Polynomial_rational_flint res = self._new()
         cdef bint do_sig = _do_sig(self.__poly)
-        
-        if do_sig: sig_on()
-        fmpq_poly_getslice(res.__poly, self.__poly, i, j)
-        if do_sig: sig_off()
-        return res
+        if isinstance(n, slice):
+            start, stop, step = n.indices(len(list(self)))
+            if do_sig: sig_on()
+            fmpq_poly_getslice(res.__poly, self.__poly, start, stop)
+            if do_sig: sig_off()
+            return res
+        else:
+            if 0 <= n and n < fmpq_poly_length(self.__poly):
+                fmpq_poly_get_coeff_mpq(z.value, self.__poly, n)
+            return z
 
     cpdef _unsafe_mutate(self, unsigned long n, value):
         """
diff --git a/sage/rings/power_series_poly.pyx b/sage/rings/power_series_poly.pyx
--- a/sage/rings/power_series_poly.pyx
+++ b/sage/rings/power_series_poly.pyx
@@ -328,12 +328,8 @@
         elif n > self.__f.degree():
             if self._prec > n:
                 return self.base_ring()(0)
-            #elif isinstance(n, slice):
-                # It makes no sense that this is needed and that
-                # __getslice__ isn't just called by default...
-            #    return self.__getslice__(slice[0],slice[1])
             else:
-                raise IndexError, "coefficient not known"
+                raise IndexError("coefficient not known")
         return self.__f[n]
 
     def __iter__(self):
