def _fetch_http(self, url, params, force_get=False):
        """
        Standard HTTP request handler for this class with gzip and cookie
        support. This was separated out of :py:func:`MediaWiki.call` to make
        :py:func:`MediaWiki.normalize_api_url` useful.

        .. note::
           This function should not be used. Use :py:func:`MediaWiki.call`
           instead.

        :param url: URL to send POST request to
        :param params: dictionary of query string parameters
        :param force_get: force a GET request instead of POST
        """
        params['format'] = 'json'
        if sys.version_info[0] == 3:
            fixed = urllib.urlencode(tuple(params.items()))
        # urllib.urlencode (in Python 2) expects str objects, not unicode
        elif sys.version_info[0] == 2:
            fixed = urllib.urlencode(
                tuple((to_bytes(k), to_bytes(v)) for k, v in
                      params.items())).encode('utf-8')
        if force_get:
            request = urllib2.Request(url + '?' + fixed)
        else:
            if sys.version_info[0] == 3:
                fixed = bytearray(fixed, 'utf-8')
            request = urllib2.Request(url, fixed)
        if self._http_user is not None:
            auth_str = '%s:%s' % (self._http_user, self._http_password)
            if sys.version_info[0] == 3:
                auth_str = bytearray(auth_str, 'utf-8')
            base64string = base64.encodestring(auth_str).replace('\n', '')
            request.add_header("Authorization", "Basic %s" % base64string)
        request.add_header('Accept-encoding', 'gzip')
        response = self._opener.open(request)
        if isinstance(self._cj, cookielib.FileCookieJar):
            self._cj.save()
        if response.headers.get('Content-Encoding') == 'gzip':
            compressed = StringIO(response.read())
            gzipper = gzip.GzipFile(fileobj=compressed)
            data = gzipper.read()
        else:
            data = response.read()
        if sys.version_info[0] == 3:
            encoding = response.info().get_content_charset() or "utf-8"
            data = data.decode(encoding)
        return data
def _fetch_http ( self , url , params , force_get = False ) : params [ 'format' ] = 'json' if sys . version_info [ 0 ] == 3 : fixed = urllib . urlencode ( tuple ( params . items ( ) ) ) elif sys . version_info [ 0 ] == 2 : fixed = urllib . urlencode ( tuple ( ( to_bytes ( k ) , to_bytes ( v ) ) for k , v in params . items ( ) ) ) . encode ( 'utf-8' ) if force_get : request = urllib2 . Request ( url + '?' + fixed ) else : if sys . version_info [ 0 ] == 3 : fixed = bytearray ( fixed , 'utf-8' ) request = urllib2 . Request ( url , fixed ) if self . _http_user is not None : auth_str = '%s:%s' % ( self . _http_user , self . _http_password ) if sys . version_info [ 0 ] == 3 : auth_str = bytearray ( auth_str , 'utf-8' ) base64string = base64 . encodestring ( auth_str ) . replace ( '\n' , '' ) request . add_header ( "Authorization" , "Basic %s" % base64string ) request . add_header ( 'Accept-encoding' , 'gzip' ) response = self . _opener . open ( request ) if isinstance ( self . _cj , cookielib . FileCookieJar ) : self . _cj . save ( ) if response . headers . get ( 'Content-Encoding' ) == 'gzip' : compressed = StringIO ( response . read ( ) ) gzipper = gzip . GzipFile ( fileobj = compressed ) data = gzipper . read ( ) else : data = response . read ( ) if sys . version_info [ 0 ] == 3 : encoding = response . info ( ) . get_content_charset ( ) or "utf-8" data = data . decode ( encoding ) return data
Standard HTTP request handler for this class with gzip and cookie
        support. This was separated out of :py:func:`MediaWiki.call` to make
        :py:func:`MediaWiki.normalize_api_url` useful.

        .. note::
           This function should not be used. Use :py:func:`MediaWiki.call`
           instead.

        :param url: URL to send POST request to
        :param params: dictionary of query string parameters
        :param force_get: force a GET request instead of POST