'Return the square root of self.'

def sqrt(self, context=None):

    if (context is None):
        context = getcontext()
    if self._is_special:
        ans = self._check_nans(context=context)
        if ans:
            return ans
        if (self._isinfinity() and (self._sign == 0)):
            return Decimal(self)
    if (not self):
        ans = _dec_from_triple(self._sign, '0', (self._exp // 2))
        return ans._fix(context)
    if (self._sign == 1):
        return context._raise_error(InvalidOperation, 'sqrt(-x),    x    >    0')
    prec = (context.prec + 1)
    op = _WorkRep(self)
    e = (op.exp >> 1)
    if (op.exp & 1):
        c = (op.int * 10)
        l = ((len(self._int) >> 1) + 1)
    else:
        c = op.int
        l = ((len(self._int) + 1) >> 1)
    shift = (prec - l)
    if (shift >= 0):
        c *= (100 ** shift)
        exact = True
    else:
        (c, remainder) = divmod(c, (100 ** (- shift)))
        exact = (not remainder)
    e -= shift
    n = (10 ** prec)
    while True:
        q = (c // n)
        if (n <= q):
            break
        else:
            n = ((n + q) >> 1)
    exact = (exact and ((n * n) == c))
    if exact:
        if (shift >= 0):
            n //= (10 ** shift)
        else:
            n *= (10 ** (- shift))
        e += shift
    elif ((n % 5) == 0):
        n += 1
    ans = _dec_from_triple(0, str(n), e)
    context = context._shallow_copy()
    rounding = context._set_rounding(ROUND_HALF_EVEN)
    ans = ans._fix(context)
    context.rounding = rounding
    return ans
