rem
stringlengths
1
322k
add
stringlengths
0
2.05M
context
stringlengths
4
228k
meta
stringlengths
156
215
if context is None: context = getcontext() ans = self._check_nans(context=context) if ans: return ans
if self._is_special: ans = self._check_nans(context=context) if ans: return ans
def __abs__(self, round=1, context=None): """Returns the absolute value of self.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
other = self._convert_other(other) ans = self._check_nans(other, context) if ans: return ans if self._isinfinity(): if self._sign != other._sign and other._isinfinity(): return context._raise_error(InvalidOperation, '-INF + INF') return Decimal(self) if other._isinfinity(): return Decimal(other)
if self._is_special or other._is_special: ans = self._check_nans(other, context) if ans: return ans if self._isinfinity(): if self._sign != other._sign and other._isinfinity(): return context._raise_error(InvalidOperation, '-INF + INF') return Decimal(self) if other._isinfinity(): return Decimal(other)
def __add__(self, other, context=None): """Returns self + other.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
op1.int.reverse() op2.int.reverse()
def __add__(self, other, context=None): """Returns self + other.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
result.int = resultint = map(operator.add, op1.int, op2.int) carry = 0 for i in xrange(len(op1.int)): tmp = resultint[i] + carry carry = 0 if tmp > 9: carry = 1 tmp -= 10 resultint[i] = tmp if carry: resultint.append(1)
result.int = op1.int + op2.int
def __add__(self, other, context=None): """Returns self + other.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
result.int = resultint = map(operator.sub, op1.int, op2.int) loan = 0 for i in xrange(len(op1.int)): tmp = resultint[i] - loan loan = 0 if tmp < 0: loan = 1 tmp += 10 resultint[i] = tmp assert not loan while resultint[-1] == 0: resultint.pop() resultint.reverse()
result.int = op1.int - op2.int
def __add__(self, other, context=None): """Returns self + other.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if context is None: context = getcontext() other = self._convert_other(other) ans = self._check_nans(other, context=context) if ans: return ans
other = _convert_other(other) if self._is_special or other._is_special: ans = self._check_nans(other, context=context) if ans: return ans
def __sub__(self, other, context=None): """Return self + (-other)""" if context is None: context = getcontext() other = self._convert_other(other)
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if context is None: context = getcontext() other = self._convert_other(other)
other = _convert_other(other)
def __rsub__(self, other, context=None): """Return other + (-self)""" if context is None: context = getcontext() other = self._convert_other(other)
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if context is None: context = getcontext() ans = self._check_nans(context=context) if ans: return ans
if self._is_special: ans = self._check_nans(context=context) if ans: return ans return Decimal(self)
def _increment(self, round=1, context=None): """Special case of add, adding 1eExponent
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
other = self._convert_other(other) ans = self._check_nans(other, context) if ans: return ans
def __mul__(self, other, context=None): """Return self * other.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') return Infsign[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') return Infsign[resultsign]
if self._is_special or other._is_special: ans = self._check_nans(other, context) if ans: return ans if self._isinfinity(): if not other: return context._raise_error(InvalidOperation, '(+-)INF * 0') return Infsign[resultsign] if other._isinfinity(): if not self: return context._raise_error(InvalidOperation, '0 * (+-)INF') return Infsign[resultsign]
def __mul__(self, other, context=None): """Return self * other.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
op1 = list(self._int) op2 = list(other._int) op1.reverse() op2.reverse() if len(op2) > len(op1): op1, op2 = op2, op1 _divmod = divmod accumulator = [0]*(len(self._int) + len(other._int)) for i in xrange(len(op2)): if op2[i] == 0: continue mult = op2[i] carry = 0 for j in xrange(len(op1)): carry, accumulator[i+j] = _divmod( mult * op1[j] + carry + accumulator[i+j], 10) if carry: accumulator[i + j + 1] += carry while not accumulator[-1]: accumulator.pop() accumulator.reverse() ans = Decimal( (resultsign, accumulator, resultexp))
op1 = _WorkRep(self) op2 = _WorkRep(other) ans = Decimal( (resultsign, map(int, str(op1.int * op2.int)), resultexp))
def __mul__(self, other, context=None): """Return self * other.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
other = self._convert_other(other) ans = self._check_nans(other, context) if ans: if divmod: return (ans, ans) else:
sign = self._sign ^ other._sign if self._is_special or other._is_special: ans = self._check_nans(other, context) if ans: if divmod: return (ans, ans)
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
sign = self._sign ^ other._sign if not self and not other: if divmod: return context._raise_error(DivisionUndefined, '0 / 0', 1) return context._raise_error(DivisionUndefined, '0 / 0') if self._isinfinity() and other._isinfinity(): if not divmod:
if self._isinfinity() and other._isinfinity(): if divmod: return (context._raise_error(InvalidOperation, '(+-)INF // (+-)INF'), context._raise_error(InvalidOperation, '(+-)INF % (+-)INF'))
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
else: return (context._raise_error(InvalidOperation, '(+-)INF // (+-)INF'), context._raise_error(InvalidOperation, '(+-)INF % (+-)INF')) if not divmod: if other._isinfinity(): context._raise_error(Clamped, 'Division by infinity') return Decimal((sign, (0,), context.Etiny())) if self._isinfinity(): return Infsign[sign] if not self: exp = self._exp - other._exp if exp < context.Etiny(): exp = context.Etiny() context._raise_error(Clamped, '0e-x / y') if exp > context.Emax: exp = context.Emax context._raise_error(Clamped, '0e+x / y') return Decimal( (sign, (0,), exp) ) if not other: return context._raise_error(DivisionByZero, 'x / 0', sign) if divmod: if other._isinfinity(): return (Decimal((sign, (0,), 0)), Decimal(self))
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if not self:
return Infsign[sign] if other._isinfinity(): if divmod: return (Decimal((sign, (0,), 0)), Decimal(self)) context._raise_error(Clamped, 'Division by infinity') return Decimal((sign, (0,), context.Etiny())) if not self and not other: if divmod: return context._raise_error(DivisionUndefined, '0 / 0', 1) return context._raise_error(DivisionUndefined, '0 / 0') if not self: if divmod:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if not other:
exp = self._exp - other._exp if exp < context.Etiny(): exp = context.Etiny() context._raise_error(Clamped, '0e-x / y') if exp > context.Emax: exp = context.Emax context._raise_error(Clamped, '0e+x / y') return Decimal( (sign, (0,), exp) ) if not other: if divmod:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
return context._raise_error(DivisionByZero, 'x / 0', sign)
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
res = _WorkRep( (sign, [0], (op1.exp - op2.exp)) )
res = _WorkRep( (sign, 0, (op1.exp - op2.exp)) )
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
while( (len(op2.int) < len(op1.int) and op1.int[0]) or (len(op2.int) == len(op1.int) and op2.int <= op1.int)): res._increment() op1.subtract(op2.int)
while op2.int <= op1.int: res.int += 1 op1.int -= op2.int
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if len(res.int) > context.prec and shouldround:
if res.int >= prec_limit and shouldround:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if op1.int == [0]*len(op1.int) and adjust >= 0 and not divmod:
if op1.int == 0 and adjust >= 0 and not divmod:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if (len(res.int) > context.prec) and shouldround:
if res.int >= prec_limit and shouldround:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if op1.int != [0]*len(op1.int): res.int.append(1)
if op1.int != 0: res.int *= 10 res.int += 1
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
res.int.append(0) op1.int.append(0)
op1.int *= 10
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if res.exp == 0 and divmod and (len(op2.int) > len(op1.int) or (len(op2.int) == len(op1.int) and op2.int > op1.int)):
if res.exp == 0 and divmod and op2.int > op1.int:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if len(res.int) > context.prec and shouldround:
if res.int >= prec_limit and shouldround:
def _divide(self, other, divmod = 0, context=None): """Return a / b, to context.prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
other = self._convert_other(other)
other = _convert_other(other)
def __rdiv__(self, other, context=None): """Swaps self/other and returns __div__.""" other = self._convert_other(other) return other.__div__(self, context=context)
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
other = self._convert_other(other)
other = _convert_other(other)
def __rdivmod__(self, other, context=None): """Swaps self/other and returns __divmod__.""" other = self._convert_other(other) return other.__divmod__(self, context=context)
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
other = self._convert_other(other) ans = self._check_nans(other, context) if ans: return ans if self and not other: return context._raise_error(InvalidOperation, 'x % 0') return self._divide(other, 3, context)[1] def __rmod__(self, other, context=None): """Swaps self/other and returns __mod__.""" other = self._convert_other(other) return other.__mod__(self, context=context) def remainder_near(self, other, context=None): """ Remainder nearest to 0- abs(remainder-near) <= other/2 """ if context is None: context = getcontext() other = self._convert_other(other) ans = self._check_nans(other, context) if ans: return ans if self and not other: return context._raise_error(InvalidOperation, 'x % 0')
def __mod__(self, other, context=None): """ self % other """ if context is None: context = getcontext() other = self._convert_other(other)
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
other = self._convert_other(other)
other = _convert_other(other)
def __rfloordiv__(self, other, context=None): """Swaps self/other and returns __floordiv__.""" other = self._convert_other(other) return other.__floordiv__(self, context=context)
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if self._isnan(): context = getcontext() return context._raise_error(InvalidContext) elif self._isinfinity(): raise OverflowError, "Cannot convert infinity to long"
if self._is_special: if self._isnan(): context = getcontext() return context._raise_error(InvalidContext) elif self._isinfinity(): raise OverflowError, "Cannot convert infinity to long"
def __int__(self): """Converts self to a int, truncating if necessary.""" if self._isnan(): context = getcontext() return context._raise_error(InvalidContext) elif self._isinfinity(): raise OverflowError, "Cannot convert infinity to long" if not self: return 0 sign = '-'*self._sign if self._exp >= 0: s = sign + ''.join(map(str, self._int)) + '0'*self._exp return int(s) s = sign + ''.join(map(str, self._int))[:self._exp] return int(s) tmp = list(self._int) tmp.reverse() val = 0 while tmp: val *= 10 val += tmp.pop() return int(((-1) ** self._sign) * val * 10.**int(self._exp))
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
tmp = list(self._int) tmp.reverse() val = 0 while tmp: val *= 10 val += tmp.pop() return int(((-1) ** self._sign) * val * 10.**int(self._exp))
def __int__(self): """Converts self to a int, truncating if necessary.""" if self._isnan(): context = getcontext() return context._raise_error(InvalidContext) elif self._isinfinity(): raise OverflowError, "Cannot convert infinity to long" if not self: return 0 sign = '-'*self._sign if self._exp >= 0: s = sign + ''.join(map(str, self._int)) + '0'*self._exp return int(s) s = sign + ''.join(map(str, self._int))[:self._exp] return int(s) tmp = list(self._int) tmp.reverse() val = 0 while tmp: val *= 10 val += tmp.pop() return int(((-1) ** self._sign) * val * 10.**int(self._exp))
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if self._isinfinity() or self._isnan():
if self._is_special:
def _fix(self, prec=None, rounding=None, folddown=None, context=None): """Round if it is necessary to keep self within prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
ans = ans._fixexponents(prec, rounding, folddown=folddown, context=context)
ans = ans._fixexponents(prec, rounding, folddown=folddown, context=context)
def _fix(self, prec=None, rounding=None, folddown=None, context=None): """Round if it is necessary to keep self within prec precision.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if self._isinfinity():
if self._is_special:
def _fixexponents(self, prec=None, rounding=None, folddown=None, context=None): """Fix the exponents and return a copy with the exponent in bounds.""" if self._isinfinity(): return self if context is None: context = getcontext() if prec is None: prec = context.prec if folddown is None: folddown = context._clamp Emin, Emax = context.Emin, context.Emax Etop = context.Etop() ans = Decimal(self) if ans.adjusted() < Emin: Etiny = context.Etiny() if ans._exp < Etiny: if not ans: ans._exp = Etiny context._raise_error(Clamped) return ans ans = ans._rescale(Etiny, context=context) #It isn't zero, and exp < Emin => subnormal context._raise_error(Subnormal) if context.flags[Inexact]: context._raise_error(Underflow) else: if ans: #Only raise subnormal if non-zero. context._raise_error(Subnormal) elif folddown and ans._exp > Etop: context._raise_error(Clamped) ans = ans._rescale(Etop, context=context) elif ans.adjusted() > Emax: if not ans: ans._exp = Emax context._raise_error(Clamped) return ans context._raise_error(Inexact) context._raise_error(Rounded) return context._raise_error(Overflow, 'above Emax', ans._sign) return ans
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
Emin, Emax = context.Emin, context.Emax Etop = context.Etop()
Emin = context.Emin
def _fixexponents(self, prec=None, rounding=None, folddown=None, context=None): """Fix the exponents and return a copy with the exponent in bounds.""" if self._isinfinity(): return self if context is None: context = getcontext() if prec is None: prec = context.prec if folddown is None: folddown = context._clamp Emin, Emax = context.Emin, context.Emax Etop = context.Etop() ans = Decimal(self) if ans.adjusted() < Emin: Etiny = context.Etiny() if ans._exp < Etiny: if not ans: ans._exp = Etiny context._raise_error(Clamped) return ans ans = ans._rescale(Etiny, context=context) #It isn't zero, and exp < Emin => subnormal context._raise_error(Subnormal) if context.flags[Inexact]: context._raise_error(Underflow) else: if ans: #Only raise subnormal if non-zero. context._raise_error(Subnormal) elif folddown and ans._exp > Etop: context._raise_error(Clamped) ans = ans._rescale(Etop, context=context) elif ans.adjusted() > Emax: if not ans: ans._exp = Emax context._raise_error(Clamped) return ans context._raise_error(Inexact) context._raise_error(Rounded) return context._raise_error(Overflow, 'above Emax', ans._sign) return ans
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if ans.adjusted() < Emin:
ans_adjusted = ans.adjusted() if ans_adjusted < Emin:
def _fixexponents(self, prec=None, rounding=None, folddown=None, context=None): """Fix the exponents and return a copy with the exponent in bounds.""" if self._isinfinity(): return self if context is None: context = getcontext() if prec is None: prec = context.prec if folddown is None: folddown = context._clamp Emin, Emax = context.Emin, context.Emax Etop = context.Etop() ans = Decimal(self) if ans.adjusted() < Emin: Etiny = context.Etiny() if ans._exp < Etiny: if not ans: ans._exp = Etiny context._raise_error(Clamped) return ans ans = ans._rescale(Etiny, context=context) #It isn't zero, and exp < Emin => subnormal context._raise_error(Subnormal) if context.flags[Inexact]: context._raise_error(Underflow) else: if ans: #Only raise subnormal if non-zero. context._raise_error(Subnormal) elif folddown and ans._exp > Etop: context._raise_error(Clamped) ans = ans._rescale(Etop, context=context) elif ans.adjusted() > Emax: if not ans: ans._exp = Emax context._raise_error(Clamped) return ans context._raise_error(Inexact) context._raise_error(Rounded) return context._raise_error(Overflow, 'above Emax', ans._sign) return ans
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
elif folddown and ans._exp > Etop: context._raise_error(Clamped) ans = ans._rescale(Etop, context=context) elif ans.adjusted() > Emax: if not ans: ans._exp = Emax
else: Etop = context.Etop() if folddown and ans._exp > Etop:
def _fixexponents(self, prec=None, rounding=None, folddown=None, context=None): """Fix the exponents and return a copy with the exponent in bounds.""" if self._isinfinity(): return self if context is None: context = getcontext() if prec is None: prec = context.prec if folddown is None: folddown = context._clamp Emin, Emax = context.Emin, context.Emax Etop = context.Etop() ans = Decimal(self) if ans.adjusted() < Emin: Etiny = context.Etiny() if ans._exp < Etiny: if not ans: ans._exp = Etiny context._raise_error(Clamped) return ans ans = ans._rescale(Etiny, context=context) #It isn't zero, and exp < Emin => subnormal context._raise_error(Subnormal) if context.flags[Inexact]: context._raise_error(Underflow) else: if ans: #Only raise subnormal if non-zero. context._raise_error(Subnormal) elif folddown and ans._exp > Etop: context._raise_error(Clamped) ans = ans._rescale(Etop, context=context) elif ans.adjusted() > Emax: if not ans: ans._exp = Emax context._raise_error(Clamped) return ans context._raise_error(Inexact) context._raise_error(Rounded) return context._raise_error(Overflow, 'above Emax', ans._sign) return ans
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
return ans context._raise_error(Inexact) context._raise_error(Rounded) return context._raise_error(Overflow, 'above Emax', ans._sign)
ans = ans._rescale(Etop, context=context) else: Emax = context.Emax if ans_adjusted > Emax: if not ans: ans._exp = Emax context._raise_error(Clamped) return ans context._raise_error(Inexact) context._raise_error(Rounded) return context._raise_error(Overflow, 'above Emax', ans._sign)
def _fixexponents(self, prec=None, rounding=None, folddown=None, context=None): """Fix the exponents and return a copy with the exponent in bounds.""" if self._isinfinity(): return self if context is None: context = getcontext() if prec is None: prec = context.prec if folddown is None: folddown = context._clamp Emin, Emax = context.Emin, context.Emax Etop = context.Etop() ans = Decimal(self) if ans.adjusted() < Emin: Etiny = context.Etiny() if ans._exp < Etiny: if not ans: ans._exp = Etiny context._raise_error(Clamped) return ans ans = ans._rescale(Etiny, context=context) #It isn't zero, and exp < Emin => subnormal context._raise_error(Subnormal) if context.flags[Inexact]: context._raise_error(Underflow) else: if ans: #Only raise subnormal if non-zero. context._raise_error(Subnormal) elif folddown and ans._exp > Etop: context._raise_error(Clamped) ans = ans._rescale(Etop, context=context) elif ans.adjusted() > Emax: if not ans: ans._exp = Emax context._raise_error(Clamped) return ans context._raise_error(Inexact) context._raise_error(Rounded) return context._raise_error(Overflow, 'above Emax', ans._sign) return ans
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
ans = self._check_nans(context=context) if ans: return ans if self._isinfinity(): return Decimal(self)
def _round(self, prec=None, rounding=None, context=None): """Returns a rounded version of self.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
n = self._convert_other(n) if n._isinfinity() or n.adjusted() > 8: return context._raise_error(InvalidOperation, 'x ** INF') ans = self._check_nans(n, context) if ans: return ans if not n._isinfinity() and not n._isinteger():
if self._is_special or n._is_special or n.adjusted() > 8: if n._isinfinity() or n.adjusted() > 8: return context._raise_error(InvalidOperation, 'x ** INF') ans = self._check_nans(n, context) if ans: return ans if not n._isinteger():
def __pow__(self, n, modulo = None, context=None): """Return self ** n (mod modulo)
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
other = self._convert_other(other)
other = _convert_other(other)
def __rpow__(self, other, context=None): """Swaps self/other and returns __pow__.""" other = self._convert_other(other) return other.__pow__(self, context=context)
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if context is None: context = getcontext() ans = self._check_nans(context=context) if ans: return ans
if self._is_special: ans = self._check_nans(context=context) if ans: return ans
def normalize(self, context=None): """Normalize- strip trailing 0s, change anything equal to 0 to 0e0""" if context is None: context = getcontext()
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if context is None: context = getcontext() ans = self._check_nans(exp, context) if ans: return ans if exp._isinfinity() or self._isinfinity(): if exp._isinfinity() and self._isinfinity(): return self return context._raise_error(InvalidOperation, 'quantize with one INF')
if self._is_special or exp._is_special: ans = self._check_nans(exp, context) if ans: return ans if exp._isinfinity() or self._isinfinity(): if exp._isinfinity() and self._isinfinity(): return self if context is None: context = getcontext() return context._raise_error(InvalidOperation, 'quantize with one INF')
def quantize(self, exp, rounding = None, context=None, watchexp = 1): """Quantize self so its exponent is the same as that of exp.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if self._isnan() or other._isnan(): return self._isnan() and other._isnan() and True if self._isinfinity() or other._isinfinity(): return self._isinfinity() and other._isinfinity() and True
if self._is_special or other._is_special: if self._isnan() or other._isnan(): return self._isnan() and other._isnan() and True if self._isinfinity() or other._isinfinity(): return self._isinfinity() and other._isinfinity() and True
def same_quantum(self, other): """Test whether self and other have the same exponent.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if self._isinfinity(): return context._raise_error(InvalidOperation, 'rescale with an INF') ans = self._check_nans(context=context) if ans: return ans
if self._is_special: if self._isinfinity(): return context._raise_error(InvalidOperation, 'rescale with an INF') ans = self._check_nans(context=context) if ans: return ans
def _rescale(self, exp, rounding = None, context=None, watchexp = 1): """Rescales so that the exponent is exp.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if tmp and tmp.adjusted() < context.Emin:
tmp_adjusted = tmp.adjusted() if tmp and tmp_adjusted < context.Emin:
def _rescale(self, exp, rounding = None, context=None, watchexp = 1): """Rescales so that the exponent is exp.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
elif tmp and tmp.adjusted() > context.Emax:
elif tmp and tmp_adjusted > context.Emax:
def _rescale(self, exp, rounding = None, context=None, watchexp = 1): """Rescales so that the exponent is exp.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
ans = self._check_nans(context=context) if ans: return ans if self._exp >= 0: return self
def to_integral(self, rounding = None, context=None): """Rounds to the nearest integer, without raising inexact, rounded.""" if context is None: context = getcontext() ans = self._check_nans(context=context) if ans: return ans if self._exp >= 0: return self flags = context._ignore_flags(Rounded, Inexact) ans = self._rescale(0, rounding, context=context) context._regard_flags(flags) return ans
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if context is None: context = getcontext() ans = self._check_nans(context=context) if ans: return ans
if self._is_special: ans = self._check_nans(context=context) if ans: return ans if self._isinfinity() and self._sign == 0: return Decimal(self)
def sqrt(self, context=None): """Return the square root of self.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if self._isinfinity(): return Decimal(self)
def sqrt(self, context=None): """Return the square root of self.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if context is None: context = getcontext() other = self._convert_other(other) sn = self._isnan() on = other._isnan() if sn or on: if on == 1 and sn != 2: return self if sn == 1 and on != 2: return other return self._check_nans(other, context)
other = _convert_other(other) if self._is_special or other._is_special: sn = self._isnan() on = other._isnan() if sn or on: if on == 1 and sn != 2: return self if sn == 1 and on != 2: return other return self._check_nans(other, context)
def max(self, other, context=None): """Returns the larger value.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if context is None: context = getcontext() other = self._convert_other(other) sn = self._isnan() on = other._isnan() if sn or on: if on == 1 and sn != 2: return self if sn == 1 and on != 2: return other return self._check_nans(other, context)
other = _convert_other(other) if self._is_special or other._is_special: sn = self._isnan() on = other._isnan() if sn or on: if on == 1 and sn != 2: return self if sn == 1 and on != 2: return other return self._check_nans(other, context)
def min(self, other, context=None): """Returns the smaller value.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
def to_integral(self, a): """Rounds to an integer.
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
self.int = []
self.int = 0
def __init__(self, value=None): if value is None: self.sign = None self.int = [] self.exp = None if isinstance(value, Decimal): if value._sign: self.sign = -1 else: self.sign = 1 self.int = list(value._int) self.exp = value._exp if isinstance(value, tuple): self.sign = value[0] self.int = value[1] self.exp = value[2]
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
self.int = list(value._int)
cum = 0 for digit in value._int: cum = cum * 10 + digit self.int = cum
def __init__(self, value=None): if value is None: self.sign = None self.int = [] self.exp = None if isinstance(value, Decimal): if value._sign: self.sign = -1 else: self.sign = 1 self.int = list(value._int) self.exp = value._exp if isinstance(value, tuple): self.sign = value[0] self.int = value[1] self.exp = value[2]
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if len(int1) > len(int2):
if int1 > int2:
def __cmp__(self, other): if self.exp != other.exp: raise ValueError("Operands not normalized: %r, %r" % (self, other)) if self.sign != other.sign: if self.sign == -1: return -1 else: return 1 if self.sign == -1: direction = -1 else: direction = 1 int1 = self.int int2 = other.int if len(int1) > len(int2): return direction * 1 if len(int1) < len(int2): return direction * -1 for i in xrange(len(int1)): if int1[i] > int2[i]: return direction * 1 if int1[i] < int2[i]: return direction * -1 return 0
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if len(int1) < len(int2):
if int1 < int2:
def __cmp__(self, other): if self.exp != other.exp: raise ValueError("Operands not normalized: %r, %r" % (self, other)) if self.sign != other.sign: if self.sign == -1: return -1 else: return 1 if self.sign == -1: direction = -1 else: direction = 1 int1 = self.int int2 = other.int if len(int1) > len(int2): return direction * 1 if len(int1) < len(int2): return direction * -1 for i in xrange(len(int1)): if int1[i] > int2[i]: return direction * 1 if int1[i] < int2[i]: return direction * -1 return 0
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
for i in xrange(len(int1)): if int1[i] > int2[i]: return direction * 1 if int1[i] < int2[i]: return direction * -1
def __cmp__(self, other): if self.exp != other.exp: raise ValueError("Operands not normalized: %r, %r" % (self, other)) if self.sign != other.sign: if self.sign == -1: return -1 else: return 1 if self.sign == -1: direction = -1 else: direction = 1 int1 = self.int int2 = other.int if len(int1) > len(int2): return direction * 1 if len(int1) < len(int2): return direction * -1 for i in xrange(len(int1)): if int1[i] > int2[i]: return direction * 1 if int1[i] < int2[i]: return direction * -1 return 0
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
def _increment(self): curspot = len(self.int) - 1 self.int[curspot]+= 1 while (self.int[curspot] >= 10): self.int[curspot] -= 10 if curspot == 0: self.int[0:0] = [1] break self.int[curspot-1] += 1 curspot -= 1 def subtract(self, alist): """Subtract a list from the current int (in place). It is assured that (len(list) = len(self.int) and list < self.int) or len(list) = len(self.int)-1 (i.e. that int(join(list)) < int(join(self.int))) """ selfint = self.int selfint.reverse() alist.reverse() carry = 0 for x in xrange(len(alist)): selfint[x] -= alist[x] + carry if selfint[x] < 0: carry = 1 selfint[x] += 10 else: carry = 0 if carry: selfint[x+1] -= 1 last = len(selfint)-1 while len(selfint) > 1 and selfint[last] == 0: last -= 1 if last == 0: break selfint[last+1:]=[] selfint.reverse() alist.reverse() return
def _increment(self): curspot = len(self.int) - 1 self.int[curspot]+= 1 while (self.int[curspot] >= 10): self.int[curspot] -= 10 if curspot == 0: self.int[0:0] = [1] break self.int[curspot-1] += 1 curspot -= 1
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if shouldround and numdigits > len(other.int) + prec + 1 -len(tmp.int): extend = prec + 2 -len(tmp.int) if extend <= 0: extend = 1 tmp.int.extend([0]*extend) tmp.exp -= extend other.int[:] = [0]*(len(tmp.int)-1)+[1] other.exp = tmp.exp return op1, op2 tmp.int.extend([0] * numdigits) tmp.exp = tmp.exp - numdigits numdigits = len(op1.int) - len(op2.int) if numdigits < 0: numdigits = -numdigits tmp = op1 else: tmp = op2 tmp.int[0:0] = [0] * numdigits
if shouldround and numdigits > prec + 1: tmp_len = len(str(tmp.int)) other_len = len(str(other.int)) if numdigits > (other_len + prec + 1 - tmp_len): extend = prec + 2 - tmp_len if extend <= 0: extend = 1 tmp.int *= 10 ** extend tmp.exp -= extend other.int = 1 other.exp = tmp.exp return op1, op2 tmp.int *= 10 ** numdigits tmp.exp -= numdigits
def _normalize(op1, op2, shouldround = 0, prec = 0): """Normalizes op1, op2 to have the same exp and length of coefficient. Done during addition. """ # Yes, the exponent is a long, but the difference between exponents # must be an int-- otherwise you'd get a big memory problem. numdigits = int(op1.exp - op2.exp) if numdigits < 0: numdigits = -numdigits tmp = op2 other = op1 else: tmp = op1 other = op2 if shouldround and numdigits > len(other.int) + prec + 1 -len(tmp.int): # If the difference in adjusted exps is > prec+1, we know # other is insignificant, so might as well put a 1 after the precision. # (since this is only for addition.) Also stops MemoryErrors. extend = prec + 2 -len(tmp.int) if extend <= 0: extend = 1 tmp.int.extend([0]*extend) tmp.exp -= extend other.int[:] = [0]*(len(tmp.int)-1)+[1] other.exp = tmp.exp return op1, op2 tmp.int.extend([0] * numdigits) tmp.exp = tmp.exp - numdigits numdigits = len(op1.int) - len(op2.int) # numdigits != 0 => They have the same exponent, but not the same length # of the coefficient. if numdigits < 0: numdigits = -numdigits tmp = op1 else: tmp = op2 tmp.int[0:0] = [0] * numdigits return op1, op2
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
"""Adjust op1, op2 so that op2.int+[0] > op1.int >= op2.int.
"""Adjust op1, op2 so that op2.int * 10 > op1.int >= op2.int.
def _adjust_coefficients(op1, op2): """Adjust op1, op2 so that op2.int+[0] > op1.int >= op2.int. Returns the adjusted op1, op2 as well as the change in op1.exp-op2.exp. Used on _WorkRep instances during division. """ adjust = 0 #If op1 is smaller, get it to same size if len(op2.int) > len(op1.int): diff = len(op2.int) - len(op1.int) op1.int.extend([0]*diff) op1.exp -= diff adjust = diff #Same length, wrong order if len(op1.int) == len(op2.int) and op1.int < op2.int: op1.int.append(0) op1.exp -= 1 adjust+= 1 return op1, op2, adjust if len(op1.int) > len(op2.int) + 1: diff = len(op1.int) - len(op2.int) - 1 op2.int.extend([0]*diff) op2.exp -= diff adjust -= diff if len(op1.int) == len(op2.int)+1 and op1.int > op2.int: op2.int.append(0) op2.exp -= 1 adjust -= 1 return op1, op2, adjust
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
if len(op2.int) > len(op1.int): diff = len(op2.int) - len(op1.int) op1.int.extend([0]*diff) op1.exp -= diff adjust = diff if len(op1.int) == len(op2.int) and op1.int < op2.int: op1.int.append(0)
while op2.int > op1.int: op1.int *= 10
def _adjust_coefficients(op1, op2): """Adjust op1, op2 so that op2.int+[0] > op1.int >= op2.int. Returns the adjusted op1, op2 as well as the change in op1.exp-op2.exp. Used on _WorkRep instances during division. """ adjust = 0 #If op1 is smaller, get it to same size if len(op2.int) > len(op1.int): diff = len(op2.int) - len(op1.int) op1.int.extend([0]*diff) op1.exp -= diff adjust = diff #Same length, wrong order if len(op1.int) == len(op2.int) and op1.int < op2.int: op1.int.append(0) op1.exp -= 1 adjust+= 1 return op1, op2, adjust if len(op1.int) > len(op2.int) + 1: diff = len(op1.int) - len(op2.int) - 1 op2.int.extend([0]*diff) op2.exp -= diff adjust -= diff if len(op1.int) == len(op2.int)+1 and op1.int > op2.int: op2.int.append(0) op2.exp -= 1 adjust -= 1 return op1, op2, adjust
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
adjust+= 1 return op1, op2, adjust if len(op1.int) > len(op2.int) + 1: diff = len(op1.int) - len(op2.int) - 1 op2.int.extend([0]*diff) op2.exp -= diff adjust -= diff if len(op1.int) == len(op2.int)+1 and op1.int > op2.int: op2.int.append(0)
adjust += 1 while op1.int >= (10 * op2.int): op2.int *= 10
def _adjust_coefficients(op1, op2): """Adjust op1, op2 so that op2.int+[0] > op1.int >= op2.int. Returns the adjusted op1, op2 as well as the change in op1.exp-op2.exp. Used on _WorkRep instances during division. """ adjust = 0 #If op1 is smaller, get it to same size if len(op2.int) > len(op1.int): diff = len(op2.int) - len(op1.int) op1.int.extend([0]*diff) op1.exp -= diff adjust = diff #Same length, wrong order if len(op1.int) == len(op2.int) and op1.int < op2.int: op1.int.append(0) op1.exp -= 1 adjust+= 1 return op1, op2, adjust if len(op1.int) > len(op2.int) + 1: diff = len(op1.int) - len(op2.int) - 1 op2.int.extend([0]*diff) op2.exp -= diff adjust -= diff if len(op1.int) == len(op2.int)+1 and op1.int > op2.int: op2.int.append(0) op2.exp -= 1 adjust -= 1 return op1, op2, adjust
636a6b100fe6083388bc5315758326078abe65b4 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/636a6b100fe6083388bc5315758326078abe65b4/decimal.py
expect(gc.collect(), 0, "boom")
expect(gc.collect(), 4, "boom")
def test_boom(): a = Boom() b = Boom() a.attr = b b.attr = a gc.collect() garbagelen = len(gc.garbage) del a, b # a<->b are in a trash cycle now. Collection will invoke Boom.__getattr__ # (to see whether a and b have __del__ methods), and __getattr__ deletes # the internal "attr" attributes as a side effect. That causes the # trash cycle to get reclaimed via refcounts falling to 0, thus mutating # the trash graph as a side effect of merely asking whether __del__ # exists. This used to (before 2.3b1) crash Python. expect(gc.collect(), 0, "boom") expect(len(gc.garbage), garbagelen, "boom")
f6b8045ca5262f0d83eea3a279828a3f136f167f /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/f6b8045ca5262f0d83eea3a279828a3f136f167f/test_gc.py
if neg_opt.has_key(option):
is_string = type(value) is StringType if neg_opt.has_key(option) and is_string:
def _set_command_options (self, command_obj, option_dict=None): """Set the options for 'command_obj' from 'option_dict'. Basically this means copying elements of a dictionary ('option_dict') to attributes of an instance ('command').
2c08cf0ffacdd450e24eeca1f58dfca571538449 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/2c08cf0ffacdd450e24eeca1f58dfca571538449/dist.py
elif option in bool_opts:
elif option in bool_opts and is_string:
def _set_command_options (self, command_obj, option_dict=None): """Set the options for 'command_obj' from 'option_dict'. Basically this means copying elements of a dictionary ('option_dict') to attributes of an instance ('command').
2c08cf0ffacdd450e24eeca1f58dfca571538449 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/2c08cf0ffacdd450e24eeca1f58dfca571538449/dist.py
If the population has repeated elements, then each occurence is
If the population has repeated elements, then each occurrence is
def sample(self, population, k, random=None, int=int): """Chooses k unique random elements from a population sequence.
ea002a1affff34ae89b691394acc5e67b55069fd /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/ea002a1affff34ae89b691394acc5e67b55069fd/random.py
def rewrite_desc_entries(doc, argname_gi): argnodes = doc.getElementsByTagName(argname_gi) for node in argnodes:
def handle_args(doc): for node in find_all_elements(doc, "args"):
def rewrite_desc_entries(doc, argname_gi): argnodes = doc.getElementsByTagName(argname_gi) for node in argnodes: parent = node.parentNode nodes = [] for n in parent.childNodes: if n.nodeType != xml.dom.core.ELEMENT or n.tagName != argname_gi: nodes.append(n) desc = doc.createElement("description") for n in nodes: parent.removeChild(n) desc.appendChild(n) if node.childNodes: # keep the <args>...</args>, newline & indent parent.insertBefore(doc.createText("\n "), node) else: # no arguments, remove the <args/> node parent.removeChild(node) parent.appendChild(doc.createText("\n ")) parent.appendChild(desc) parent.appendChild(doc.createText("\n"))
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
if n.nodeType != xml.dom.core.ELEMENT or n.tagName != argname_gi:
if n.nodeType != xml.dom.core.ELEMENT or n.tagName != "args":
def rewrite_desc_entries(doc, argname_gi): argnodes = doc.getElementsByTagName(argname_gi) for node in argnodes: parent = node.parentNode nodes = [] for n in parent.childNodes: if n.nodeType != xml.dom.core.ELEMENT or n.tagName != argname_gi: nodes.append(n) desc = doc.createElement("description") for n in nodes: parent.removeChild(n) desc.appendChild(n) if node.childNodes: # keep the <args>...</args>, newline & indent parent.insertBefore(doc.createText("\n "), node) else: # no arguments, remove the <args/> node parent.removeChild(node) parent.appendChild(doc.createText("\n ")) parent.appendChild(desc) parent.appendChild(doc.createText("\n"))
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
parent.insertBefore(doc.createText("\n "), node) else: parent.removeChild(node)
signature.appendChild(doc.createTextNode("\n ")) signature.appendChild(node)
def rewrite_desc_entries(doc, argname_gi): argnodes = doc.getElementsByTagName(argname_gi) for node in argnodes: parent = node.parentNode nodes = [] for n in parent.childNodes: if n.nodeType != xml.dom.core.ELEMENT or n.tagName != argname_gi: nodes.append(n) desc = doc.createElement("description") for n in nodes: parent.removeChild(n) desc.appendChild(n) if node.childNodes: # keep the <args>...</args>, newline & indent parent.insertBefore(doc.createText("\n "), node) else: # no arguments, remove the <args/> node parent.removeChild(node) parent.appendChild(doc.createText("\n ")) parent.appendChild(desc) parent.appendChild(doc.createText("\n"))
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
def handle_args(doc): rewrite_desc_entries(doc, "args") rewrite_desc_entries(doc, "constructor-args")
signature.appendChild(doc.createTextNode("\n ")) def methodline_to_signature(doc, methodline): signature = doc.createElement("signature") signature.appendChild(doc.createTextNode("\n ")) name = doc.createElement("name") name.appendChild(doc.createTextNode(methodline.getAttribute("name"))) signature.appendChild(name) methodline.parentNode.removeChild(methodline) if len(methodline.childNodes): methodline._node.name = "args" methodline.removeAttribute("name") signature.appendChild(doc.createTextNode("\n ")) signature.appendChild(methodline) signature.appendChild(doc.createTextNode("\n ")) return signature
def rewrite_desc_entries(doc, argname_gi): argnodes = doc.getElementsByTagName(argname_gi) for node in argnodes: parent = node.parentNode nodes = [] for n in parent.childNodes: if n.nodeType != xml.dom.core.ELEMENT or n.tagName != argname_gi: nodes.append(n) desc = doc.createElement("description") for n in nodes: parent.removeChild(n) desc.appendChild(n) if node.childNodes: # keep the <args>...</args>, newline & indent parent.insertBefore(doc.createText("\n "), node) else: # no arguments, remove the <args/> node parent.removeChild(node) parent.appendChild(doc.createText("\n ")) parent.appendChild(desc) parent.appendChild(doc.createText("\n"))
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
for node in doc.childNodes: if node.nodeType == xml.dom.core.ELEMENT: labels = node.getElementsByTagName("label") for label in labels: id = label.getAttribute("id") if not id: continue parent = label.parentNode if parent.tagName == "title": parent.parentNode.setAttribute("id", id) else: parent.setAttribute("id", id) parent.removeChild(label)
for label in find_all_elements(doc, "label"): id = label.getAttribute("id") if not id: continue parent = label.parentNode if parent.tagName == "title": parent.parentNode.setAttribute("id", id) else: parent.setAttribute("id", id) parent.removeChild(label)
def handle_labels(doc): for node in doc.childNodes: if node.nodeType == xml.dom.core.ELEMENT: labels = node.getElementsByTagName("label") for label in labels: id = label.getAttribute("id") if not id: continue parent = label.parentNode if parent.tagName == "title": parent.parentNode.setAttribute("id", id) else: parent.setAttribute("id", id) # now, remove <label id="..."/> from parent: parent.removeChild(label)
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
if children[-1].data[-1:] == ".":
if children[-1].nodeType == xml.dom.core.TEXT \ and children[-1].data[-1:] == ".":
def create_module_info(doc, section): # Heavy. node = extract_first_element(section, "modulesynopsis") if node is None: return node._node.name = "synopsis" lastchild = node.childNodes[-1] if lastchild.nodeType == xml.dom.core.TEXT \ and lastchild.data[-1:] == ".": lastchild.data = lastchild.data[:-1] modauthor = extract_first_element(section, "moduleauthor") if modauthor: modauthor._node.name = "author" modauthor.appendChild(doc.createTextNode( modauthor.getAttribute("name"))) modauthor.removeAttribute("name") if section.tagName == "section": modinfo_pos = 2 modinfo = doc.createElement("moduleinfo") moddecl = extract_first_element(section, "declaremodule") name = None if moddecl: modinfo.appendChild(doc.createTextNode("\n ")) name = moddecl.attributes["name"].value namenode = doc.createElement("name") namenode.appendChild(doc.createTextNode(name)) modinfo.appendChild(namenode) type = moddecl.attributes.get("type") if type: type = type.value modinfo.appendChild(doc.createTextNode("\n ")) typenode = doc.createElement("type") typenode.appendChild(doc.createTextNode(type)) modinfo.appendChild(typenode) title = get_first_element(section, "title") if title: children = title.childNodes if len(children) >= 2 \ and children[0].nodeType == xml.dom.core.ELEMENT \ and children[0].tagName == "module" \ and children[0].childNodes[0].data == name: # this is it; morph the <title> into <short-synopsis> first_data = children[1] if first_data.data[:4] == " ---": first_data.data = string.lstrip(first_data.data[4:]) title._node.name = "short-synopsis" if children[-1].data[-1:] == ".": children[-1].data = children[-1].data[:-1] section.removeChild(title) section.removeChild(section.childNodes[0]) title.removeChild(children[0]) modinfo_pos = 0 else: sys.stderr.write( "module name in title doesn't match" " <declaremodule>; no <short-synopsis>\n") else: sys.stderr.write( "Unexpected condition: <section> without <title>\n") modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(node) if title and not contents_match(title, node): # The short synopsis is actually different, # and needs to be stored: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(title) if modauthor: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(modauthor) modinfo.appendChild(doc.createTextNode("\n ")) section.insertBefore(modinfo, section.childNodes[modinfo_pos]) section.insertBefore(doc.createTextNode("\n "), modinfo)
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
for node in doc.childNodes: if node.nodeType == xml.dom.core.ELEMENT \ and node.tagName == "section": create_module_info(doc, node)
for node in find_all_elements(doc, "section"): create_module_info(doc, node)
def cleanup_synopses(doc): for node in doc.childNodes: if node.nodeType == xml.dom.core.ELEMENT \ and node.tagName == "section": create_module_info(doc, node)
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
for child in doc.childNodes: if child.nodeType == xml.dom.core.ELEMENT: tables = child.getElementsByTagName("table") for table in tables: fixup_table(doc, table)
for table in find_all_elements(doc, "table"): fixup_table(doc, table)
def fixup_table_structures(doc): # must be done after remap_element_names(), or the tables won't be found for child in doc.childNodes: if child.nodeType == xml.dom.core.ELEMENT: tables = child.getElementsByTagName("table") for table in tables: fixup_table(doc, table)
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
"paragraph", "subparagraph", "description", "opcodedesc", "classdesc", "funcdesc", "methoddesc", "excdesc", "datadesc", "funcdescni", "methoddescni", "excdescni", "datadescni",
"paragraph", "subparagraph", "excdesc", "datadesc", "excdescni", "datadescni", ) RECURSE_INTO_PARA_CONTAINERS = ( "chapter", "section", "subsection", "subsubsection", "paragraph", "subparagraph", "abstract", "memberdesc", "memberdescni", "datadesc", "datadescni",
def move_elements_by_name(doc, source, dest, name, sep=None): nodes = [] for child in source.childNodes: if child.nodeType == xml.dom.core.ELEMENT and child.tagName == name: nodes.append(child) for node in nodes: source.removeChild(node) dest.appendChild(node) if sep: dest.appendChild(doc.createTextNode(sep))
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
"funcdesc", "methoddesc", "excdesc", "datadesc", "funcdescni", "methoddescni", "excdescni", "datadescni",
"funcdesc", "methoddesc", "excdesc", "funcdescni", "methoddescni", "excdescni",
def move_elements_by_name(doc, source, dest, name, sep=None): nodes = [] for child in source.childNodes: if child.nodeType == xml.dom.core.ELEMENT and child.tagName == name: nodes.append(child) for node in nodes: source.removeChild(node) dest.appendChild(node) if sep: dest.appendChild(doc.createTextNode(sep))
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
"sectionauthor",
"sectionauthor", "seealso",
def move_elements_by_name(doc, source, dest, name, sep=None): nodes = [] for child in source.childNodes: if child.nodeType == xml.dom.core.ELEMENT and child.tagName == name: nodes.append(child) for node in nodes: source.removeChild(node) dest.appendChild(node) if sep: dest.appendChild(doc.createTextNode(sep))
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
"stindex", "obindex", "COMMENT", "label",
"stindex", "obindex", "COMMENT", "label", "input", "memberline", "memberlineni", "methodline", "methodlineni",
def move_elements_by_name(doc, source, dest, name, sep=None): nodes = [] for child in source.childNodes: if child.nodeType == xml.dom.core.ELEMENT and child.tagName == name: nodes.append(child) for node in nodes: source.removeChild(node) dest.appendChild(node) if sep: dest.appendChild(doc.createTextNode(sep))
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
and child.tagName in FIXUP_PARA_ELEMENTS:
and child.tagName in RECURSE_INTO_PARA_CONTAINERS:
def fixup_paras(doc): for child in doc.childNodes: if child.nodeType == xml.dom.core.ELEMENT \ and child.tagName in FIXUP_PARA_ELEMENTS: fixup_paras_helper(doc, child) descriptions = child.getElementsByTagName("description") for description in descriptions: if DEBUG_PARA_FIXER: sys.stderr.write("-- Fixing up <description> element...\n") fixup_paras_helper(doc, description)
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
if DEBUG_PARA_FIXER: sys.stderr.write("-- Fixing up <description> element...\n")
def fixup_paras(doc): for child in doc.childNodes: if child.nodeType == xml.dom.core.ELEMENT \ and child.tagName in FIXUP_PARA_ELEMENTS: fixup_paras_helper(doc, child) descriptions = child.getElementsByTagName("description") for description in descriptions: if DEBUG_PARA_FIXER: sys.stderr.write("-- Fixing up <description> element...\n") fixup_paras_helper(doc, description)
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
def fixup_paras_helper(doc, container):
def fixup_paras_helper(doc, container, depth=0):
def fixup_paras_helper(doc, container): # document is already normalized children = container.childNodes start = 0 start_fixed = 0 i = len(children) SKIP_ELEMENTS = PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS if DEBUG_PARA_FIXER: sys.stderr.write("fixup_paras_helper() called on <%s>; %d, %d\n" % (container.tagName, start, i)) if i > start: # the first [start:i] children shoudl be rewritten as <para> elements # start by breaking text nodes that contain \n\n+ into multiple nodes nstart, i = skip_leading_nodes(container.childNodes, start, i) if i > nstart: build_para(doc, container, nstart, i) fixup_paras_helper(doc, container)
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
start_fixed = 0 i = len(children) SKIP_ELEMENTS = PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS if DEBUG_PARA_FIXER: sys.stderr.write("fixup_paras_helper() called on <%s>; %d, %d\n" % (container.tagName, start, i)) if i > start: nstart, i = skip_leading_nodes(container.childNodes, start, i) if i > nstart: build_para(doc, container, nstart, i) fixup_paras_helper(doc, container)
while len(children) > start: start = skip_leading_nodes(children, start) if start >= len(children): break if (children[start].nodeType == xml.dom.core.ELEMENT) \ and (children[start].tagName in RECURSE_INTO_PARA_CONTAINERS): fixup_paras_helper(doc, children[start]) start = skip_leading_nodes(children, start + 1) continue build_para(doc, container, start, len(children)) if DEBUG_PARA_FIXER and depth == 10: sys.exit(1) start = start + 1
def fixup_paras_helper(doc, container): # document is already normalized children = container.childNodes start = 0 start_fixed = 0 i = len(children) SKIP_ELEMENTS = PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS if DEBUG_PARA_FIXER: sys.stderr.write("fixup_paras_helper() called on <%s>; %d, %d\n" % (container.tagName, start, i)) if i > start: # the first [start:i] children shoudl be rewritten as <para> elements # start by breaking text nodes that contain \n\n+ into multiple nodes nstart, i = skip_leading_nodes(container.childNodes, start, i) if i > nstart: build_para(doc, container, nstart, i) fixup_paras_helper(doc, container)
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
def build_para(doc, parent, start, i): children = parent.childNodes # collect all children until \n\n+ is found in a text node or a # PARA_LEVEL_ELEMENT is found. after = start + 1 have_last = 0 BREAK_ELEMENTS = PARA_LEVEL_ELEMENTS + FIXUP_PARA_ELEMENTS for j in range(start, i): after = j + 1 child = children[j] nodeType = child.nodeType if nodeType == xml.dom.core.ELEMENT: if child.tagName in BREAK_ELEMENTS: after = j break elif nodeType == xml.dom.core.TEXT: pos = string.find(child.data, "\n\n") if pos == 0: after = j break if pos >= 1: child.splitText(pos) break else: have_last = 1 if children[after - 1].nodeType == xml.dom.core.TEXT: # we may need to split off trailing white space: child = children[after - 1] data = child.data if string.rstrip(data) != data: have_last = 0 child.splitText(len(string.rstrip(data))) children = parent.childNodes para = doc.createElement("para") prev = None indexes = range(start, after) indexes.reverse() for j in indexes: node = children[j] parent.removeChild(node) para.insertBefore(node, prev) prev = node if have_last: parent.appendChild(para) else: parent.insertBefore(para, parent.childNodes[start])
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
children = parent.childNodes
def build_para(doc, parent, start, i): children = parent.childNodes # collect all children until \n\n+ is found in a text node or a # PARA_LEVEL_ELEMENT is found. after = start + 1 have_last = 0 BREAK_ELEMENTS = PARA_LEVEL_ELEMENTS + FIXUP_PARA_ELEMENTS for j in range(start, i): after = j + 1 child = children[j] nodeType = child.nodeType if nodeType == xml.dom.core.ELEMENT: if child.tagName in BREAK_ELEMENTS: after = j break elif nodeType == xml.dom.core.TEXT: pos = string.find(child.data, "\n\n") if pos == 0: after = j break if pos >= 1: child.splitText(pos) break else: have_last = 1 if children[after - 1].nodeType == xml.dom.core.TEXT: # we may need to split off trailing white space: child = children[after - 1] data = child.data if string.rstrip(data) != data: have_last = 0 child.splitText(len(string.rstrip(data))) children = parent.childNodes para = doc.createElement("para") prev = None indexes = range(start, after) indexes.reverse() for j in indexes: node = children[j] parent.removeChild(node) para.insertBefore(node, prev) prev = node if have_last: parent.appendChild(para) else: parent.insertBefore(para, parent.childNodes[start])
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
node = children[j]
node = parent.childNodes[j]
def build_para(doc, parent, start, i): children = parent.childNodes # collect all children until \n\n+ is found in a text node or a # PARA_LEVEL_ELEMENT is found. after = start + 1 have_last = 0 BREAK_ELEMENTS = PARA_LEVEL_ELEMENTS + FIXUP_PARA_ELEMENTS for j in range(start, i): after = j + 1 child = children[j] nodeType = child.nodeType if nodeType == xml.dom.core.ELEMENT: if child.tagName in BREAK_ELEMENTS: after = j break elif nodeType == xml.dom.core.TEXT: pos = string.find(child.data, "\n\n") if pos == 0: after = j break if pos >= 1: child.splitText(pos) break else: have_last = 1 if children[after - 1].nodeType == xml.dom.core.TEXT: # we may need to split off trailing white space: child = children[after - 1] data = child.data if string.rstrip(data) != data: have_last = 0 child.splitText(len(string.rstrip(data))) children = parent.childNodes para = doc.createElement("para") prev = None indexes = range(start, after) indexes.reverse() for j in indexes: node = children[j] parent.removeChild(node) para.insertBefore(node, prev) prev = node if have_last: parent.appendChild(para) else: parent.insertBefore(para, parent.childNodes[start])
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
def skip_leading_nodes(children, start, i): i = min(i, len(children))
return start + 1 def skip_leading_nodes(children, start): """Return index into children of a node at which paragraph building should begin or a recursive call to fixup_paras_helper() should be made (for subsections, etc.). When the return value >= len(children), we've built all the paras we can from this list of children. """ i = len(children)
def build_para(doc, parent, start, i): children = parent.childNodes # collect all children until \n\n+ is found in a text node or a # PARA_LEVEL_ELEMENT is found. after = start + 1 have_last = 0 BREAK_ELEMENTS = PARA_LEVEL_ELEMENTS + FIXUP_PARA_ELEMENTS for j in range(start, i): after = j + 1 child = children[j] nodeType = child.nodeType if nodeType == xml.dom.core.ELEMENT: if child.tagName in BREAK_ELEMENTS: after = j break elif nodeType == xml.dom.core.TEXT: pos = string.find(child.data, "\n\n") if pos == 0: after = j break if pos >= 1: child.splitText(pos) break else: have_last = 1 if children[after - 1].nodeType == xml.dom.core.TEXT: # we may need to split off trailing white space: child = children[after - 1] data = child.data if string.rstrip(data) != data: have_last = 0 child.splitText(len(string.rstrip(data))) children = parent.childNodes para = doc.createElement("para") prev = None indexes = range(start, after) indexes.reverse() for j in indexes: node = children[j] parent.removeChild(node) para.insertBefore(node, prev) prev = node if have_last: parent.appendChild(para) else: parent.insertBefore(para, parent.childNodes[start])
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
try: child = children[start] except IndexError: sys.stderr.write( "skip_leading_nodes() failed at index %d\n" % start) raise
child = children[start]
def skip_leading_nodes(children, start, i): i = min(i, len(children)) while i > start: # skip over leading comments and whitespace: try: child = children[start] except IndexError: sys.stderr.write( "skip_leading_nodes() failed at index %d\n" % start) raise nodeType = child.nodeType if nodeType == xml.dom.core.COMMENT: start = start + 1 elif nodeType == xml.dom.core.TEXT: data = child.data shortened = string.lstrip(data) if shortened: if data != shortened: # break into two nodes: whitespace and non-whitespace child.splitText(len(data) - len(shortened)) return start + 1, i + 1 break # all whitespace, just skip start = start + 1 elif nodeType == xml.dom.core.ELEMENT: if child.tagName in PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS: start = start + 1 else: break else: break return start, i
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
if nodeType == xml.dom.core.COMMENT: start = start + 1 elif nodeType == xml.dom.core.TEXT:
if nodeType == xml.dom.core.TEXT:
def skip_leading_nodes(children, start, i): i = min(i, len(children)) while i > start: # skip over leading comments and whitespace: try: child = children[start] except IndexError: sys.stderr.write( "skip_leading_nodes() failed at index %d\n" % start) raise nodeType = child.nodeType if nodeType == xml.dom.core.COMMENT: start = start + 1 elif nodeType == xml.dom.core.TEXT: data = child.data shortened = string.lstrip(data) if shortened: if data != shortened: # break into two nodes: whitespace and non-whitespace child.splitText(len(data) - len(shortened)) return start + 1, i + 1 break # all whitespace, just skip start = start + 1 elif nodeType == xml.dom.core.ELEMENT: if child.tagName in PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS: start = start + 1 else: break else: break return start, i
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
return start + 1, i + 1 break
return start + 1 return start
def skip_leading_nodes(children, start, i): i = min(i, len(children)) while i > start: # skip over leading comments and whitespace: try: child = children[start] except IndexError: sys.stderr.write( "skip_leading_nodes() failed at index %d\n" % start) raise nodeType = child.nodeType if nodeType == xml.dom.core.COMMENT: start = start + 1 elif nodeType == xml.dom.core.TEXT: data = child.data shortened = string.lstrip(data) if shortened: if data != shortened: # break into two nodes: whitespace and non-whitespace child.splitText(len(data) - len(shortened)) return start + 1, i + 1 break # all whitespace, just skip start = start + 1 elif nodeType == xml.dom.core.ELEMENT: if child.tagName in PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS: start = start + 1 else: break else: break return start, i
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
start = start + 1
def skip_leading_nodes(children, start, i): i = min(i, len(children)) while i > start: # skip over leading comments and whitespace: try: child = children[start] except IndexError: sys.stderr.write( "skip_leading_nodes() failed at index %d\n" % start) raise nodeType = child.nodeType if nodeType == xml.dom.core.COMMENT: start = start + 1 elif nodeType == xml.dom.core.TEXT: data = child.data shortened = string.lstrip(data) if shortened: if data != shortened: # break into two nodes: whitespace and non-whitespace child.splitText(len(data) - len(shortened)) return start + 1, i + 1 break # all whitespace, just skip start = start + 1 elif nodeType == xml.dom.core.ELEMENT: if child.tagName in PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS: start = start + 1 else: break else: break return start, i
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
if child.tagName in PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS: start = start + 1 else: break else: break return start, i
tagName = child.tagName if tagName in RECURSE_INTO_PARA_CONTAINERS: return start if tagName not in PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS: return start start = start + 1 return start
def skip_leading_nodes(children, start, i): i = min(i, len(children)) while i > start: # skip over leading comments and whitespace: try: child = children[start] except IndexError: sys.stderr.write( "skip_leading_nodes() failed at index %d\n" % start) raise nodeType = child.nodeType if nodeType == xml.dom.core.COMMENT: start = start + 1 elif nodeType == xml.dom.core.TEXT: data = child.data shortened = string.lstrip(data) if shortened: if data != shortened: # break into two nodes: whitespace and non-whitespace child.splitText(len(data) - len(shortened)) return start + 1, i + 1 break # all whitespace, just skip start = start + 1 elif nodeType == xml.dom.core.ELEMENT: if child.tagName in PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS: start = start + 1 else: break else: break return start, i
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
rfc_nodes = [] for child in doc.childNodes: if child.nodeType == xml.dom.core.ELEMENT: kids = child.getElementsByTagName("rfc") for k in kids: rfc_nodes.append(k) for rfc_node in rfc_nodes: rfc_node.appendChild(doc.createTextNode( "RFC " + rfc_node.getAttribute("num")))
for rfcnode in find_all_elements(doc, "rfc"): rfcnode.appendChild(doc.createTextNode( "RFC " + rfcnode.getAttribute("num")))
def fixup_rfc_references(doc): rfc_nodes = [] for child in doc.childNodes: if child.nodeType == xml.dom.core.ELEMENT: kids = child.getElementsByTagName("rfc") for k in kids: rfc_nodes.append(k) for rfc_node in rfc_nodes: rfc_node.appendChild(doc.createTextNode( "RFC " + rfc_node.getAttribute("num")))
7dab6affba271fd9784c15fa0e867a8e91a45e83 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/7dab6affba271fd9784c15fa0e867a8e91a45e83/docfixer.py
self.formatter.end_paragraph(0)
self.formatter.end_paragraph(1)
def end_blockquote(self): self.formatter.end_paragraph(0) self.formatter.pop_margin()
aa7634476f84e1591ea3b1bb945095e23931a0f2 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/aa7634476f84e1591ea3b1bb945095e23931a0f2/htmllib.py
self.formatter.end_paragraph(0)
self.formatter.end_paragraph(1)
def start_dl(self, attrs): self.formatter.end_paragraph(0) self.list_stack.append(['dl', '', 0])
aa7634476f84e1591ea3b1bb945095e23931a0f2 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/aa7634476f84e1591ea3b1bb945095e23931a0f2/htmllib.py
self.ddpop()
self.ddpop(1)
def end_dl(self): self.ddpop() if self.list_stack: del self.list_stack[-1]
aa7634476f84e1591ea3b1bb945095e23931a0f2 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/aa7634476f84e1591ea3b1bb945095e23931a0f2/htmllib.py
def ddpop(self): self.formatter.end_paragraph(0)
def ddpop(self, bl=0): self.formatter.end_paragraph(bl)
def ddpop(self): self.formatter.end_paragraph(0) if self.list_stack: if self.list_stack[-1][0] == 'dd':
aa7634476f84e1591ea3b1bb945095e23931a0f2 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/aa7634476f84e1591ea3b1bb945095e23931a0f2/htmllib.py
def start_string(self, attrs): self.start_b(attrs) def end_b(self): self.end_b()
def start_strong(self, attrs): self.start_b(attrs) def end_strong(self): self.end_b()
def start_string(self, attrs): self.start_b(attrs)
aa7634476f84e1591ea3b1bb945095e23931a0f2 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/aa7634476f84e1591ea3b1bb945095e23931a0f2/htmllib.py
def end_var(self): self.end_var()
def end_var(self): self.end_i()
def end_var(self): self.end_var()
aa7634476f84e1591ea3b1bb945095e23931a0f2 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/8546/aa7634476f84e1591ea3b1bb945095e23931a0f2/htmllib.py