@classmethod
def preprocess(cls, domain):
    if isinstance(domain, sympy.polys.domains.Domain):
        return domain
    elif hasattr(domain, 'to_domain'):
        return domain.to_domain()
    elif isinstance(domain, string_types):
        if (domain in ['Z', 'ZZ']):
            return sympy.polys.domains.ZZ
        if (domain in ['Q', 'QQ']):
            return sympy.polys.domains.QQ
        if (domain == 'EX'):
            return sympy.polys.domains.EX
        r = cls._re_realfield.match(domain)
        if (r is not None):
            (_, _, prec) = r.groups()
            if (prec is None):
                return sympy.polys.domains.RR
            else:
                return sympy.polys.domains.RealField(int(prec))
        r = cls._re_complexfield.match(domain)
        if (r is not None):
            (_, _, prec) = r.groups()
            if (prec is None):
                return sympy.polys.domains.CC
            else:
                return sympy.polys.domains.ComplexField(int(prec))
        r = cls._re_finitefield.match(domain)
        if (r is not None):
            return sympy.polys.domains.FF(int(r.groups()[1]))
        r = cls._re_polynomial.match(domain)
        if (r is not None):
            (ground, gens) = r.groups()
            gens = list(map(sympify, gens.split(',')))
            if (ground in ['Z', 'ZZ']):
                return sympy.polys.domains.ZZ.poly_ring(*gens)
            else:
                return sympy.polys.domains.QQ.poly_ring(*gens)
        r = cls._re_fraction.match(domain)
        if (r is not None):
            (ground, gens) = r.groups()
            gens = list(map(sympify, gens.split(',')))
            if (ground in ['Z', 'ZZ']):
                return sympy.polys.domains.ZZ.frac_field(*gens)
            else:
                return sympy.polys.domains.QQ.frac_field(*gens)
        r = cls._re_algebraic.match(domain)
        if (r is not None):
            gens = list(map(sympify, r.groups()[1].split(',')))
            return sympy.polys.domains.QQ.algebraic_field(*gens)
    raise OptionError(('expected a valid domain specification, got %s' % domain))
@classmethod
def preprocess(cls, domain):
    if isinstance(domain, sympy.polys.domains.Domain):
        return domain
    elif hasattr(domain, 'to_domain'):
        return domain.to_domain()
    elif isinstance(domain, string_types):
        if (domain in ['Z', 'ZZ']):
            return sympy.polys.domains.ZZ
        if (domain in ['Q', 'QQ']):
            return sympy.polys.domains.QQ
        if (domain == 'EX'):
            return sympy.polys.domains.EX
        r = cls._re_realfield.match(domain)
        if (r is not None):
            (_, _, prec) = r.groups()
            if (prec is None):
                return sympy.polys.domains.RR
            else:
                return sympy.polys.domains.RealField(int(prec))
        r = cls._re_complexfield.match(domain)
        if (r is not None):
            (_, _, prec) = r.groups()
            if (prec is None):
                return sympy.polys.domains.CC
            else:
                return sympy.polys.domains.ComplexField(int(prec))
        r = cls._re_finitefield.match(domain)
        if (r is not None):
            return sympy.polys.domains.FF(int(r.groups()[1]))
        r = cls._re_polynomial.match(domain)
        if (r is not None):
            (ground, gens) = r.groups()
            gens = list(map(sympify, gens.split(',')))
            if (ground in ['Z', 'ZZ']):
                return sympy.polys.domains.ZZ.poly_ring(*gens)
            else:
                return sympy.polys.domains.QQ.poly_ring(*gens)
        r = cls._re_fraction.match(domain)
        if (r is not None):
            (ground, gens) = r.groups()
            gens = list(map(sympify, gens.split(',')))
            if (ground in ['Z', 'ZZ']):
                return sympy.polys.domains.ZZ.frac_field(*gens)
            else:
                return sympy.polys.domains.QQ.frac_field(*gens)
        r = cls._re_algebraic.match(domain)
        if (r is not None):
            gens = list(map(sympify, r.groups()[1].split(',')))
            return sympy.polys.domains.QQ.algebraic_field(*gens)
    raise OptionError(('expected a valid domain specification, got %s' % domain))