Fetch astrometric information from the Simbad web service.

    Given the name of a source as known to the CDS Simbad service, this
    function looks up its positional information and returns it in a
    dictionary. In most cases you should use an :class:`AstrometryInfo` object
    and its :meth:`~AstrometryInfo.fill_from_simbad` method instead of this
    function.

    Arguments:

    ident
      The Simbad name of the source to look up.
    items
      An iterable of data items to look up. The default fetches position,
      proper motion, parallax, and radial velocity information. Each item name
      resembles the string ``COO(d;A)`` or ``PLX(E)``. The allowed formats are
      defined `on this CDS page
      <http://simbad.u-strasbg.fr/Pages/guide/sim-fscript.htx>`_.
    debug
      If true, the response from the webserver will be printed.

    The return value is a dictionary with a key corresponding to the textual
    result returned for each requested item.

def get_simbad_astrometry_info (ident, items=_simbaditems, debug=False):
    """Fetch astrometric information from the Simbad web service.

    Given the name of a source as known to the CDS Simbad service, this
    function looks up its positional information and returns it in a
    dictionary. In most cases you should use an :class:`AstrometryInfo` object
    and its :meth:`~AstrometryInfo.fill_from_simbad` method instead of this
    function.

    Arguments:

    ident
      The Simbad name of the source to look up.
    items
      An iterable of data items to look up. The default fetches position,
      proper motion, parallax, and radial velocity information. Each item name
      resembles the string ``COO(d;A)`` or ``PLX(E)``. The allowed formats are
      defined `on this CDS page
      <http://simbad.u-strasbg.fr/Pages/guide/sim-fscript.htx>`_.
    debug
      If true, the response from the webserver will be printed.

    The return value is a dictionary with a key corresponding to the textual
    result returned for each requested item.

    """
    import codecs
    try:
        from urllib.parse import quote
    except ImportError:
        from urllib import quote
    try:
        from urllib.request import urlopen
    except ImportError:
        from urllib2 import urlopen

    s = '\\n'.join ('%s %%%s' % (i, i) for i in items)
    s = '''output console=off script=off
format object "%s"
query id %s''' % (s, ident)
    url = _simbadbase + quote (s)
    results = {}
    errtext = None

    for line in codecs.getreader('utf-8')(urlopen (url)):
        line = line.strip ()
        if debug:
            print_ ('D: SA >>', line)

        if errtext is not None:
            errtext += line
        elif line.startswith ('::error'):
            errtext = ''
        elif len (line):
            k, v = line.split (' ', 1)
            results[k] = v

    if errtext is not None:
        raise Exception ('SIMBAD query error: ' + errtext)
    return results