'Retrieves the given URL, and returns a unicode string,
trying to guess the encoding of the data (assuming latin_1
by default)'

def retrieve_unicode(self, url, size=(-1)):

    encode = None
    try:
        if (size != (-1)):
            self.set_header('Range', ('bytes=0-%d' % size))
        uopener = self.open(url)
        kwds = {}
        if ((PY_VERSION > (2, 3)) and (not IN_GAE)):
            kwds['size'] = size
        content = uopener.read(**kwds)
        self._last_url = uopener.url
        server_encode = uopener.info().getparam('charset')
        if ((server_encode is None) and content):
            begin_h = content.find('text/html;    charset=')
            if (begin_h != (-1)):
                end_h = content[(19 + begin_h):].find('"')
                if (end_h != (-1)):
                    server_encode = content[(19 + begin_h):((19 + begin_h) + end_h)]
        if server_encode:
            try:
                if lookup(server_encode):
                    encode = server_encode
            except (LookupError, ValueError, TypeError):
                pass
        uopener.close()
        if (size != (-1)):
            self.del_header('Range')
        self.close()
    except IOError as e:
        if (size != (-1)):
            self.del_header('Range')
        raise IMDbDataAccessError({'errcode': e.errno, 'errmsg': str(e.strerror), 'url': url, 'proxy': self.get_proxy(), 'exception    type': 'IOError', 'original    exception': e})
    if (encode is None):
        encode = 'latin_1'
        self._logger.warn('Unable    to    detect    the    encoding    of    the    retrieved    page    [%s];    falling    back    to    default    latin1.', encode)
    return unicode(content, encode, 'replace')
