Make Mediawiki, RESTBase, and Wikidata requests for page data
        some sequence of:
        - get_parse()
        - get_query()
        - get_restbase()
        - get_wikidata()
420984
def get(self, show=True, proxy=None, timeout=0):
        
        wikibase = self.params.get('wikibase')

        if wikibase:

            self.flags['defer_imageinfo'] = True

            self.get_wikidata(False, proxy, timeout)
            self.get_query(False, proxy, timeout)
            self.get_parse(False, proxy, timeout)

            self.flags['defer_imageinfo'] = False

            self.get_restbase('/page/summary/', False, proxy, timeout)

            if show and not self.flags.get('silent'):
                self.show()

        else:

            self.flags['defer_imageinfo'] = True

            self.get_query(False, proxy, timeout)
            self.get_parse(False, proxy, timeout)

            if not self.data.get('wikibase'):
                self.skip_action('wikidata')

            self.get_wikidata(False, proxy, timeout)

            self.flags['defer_imageinfo'] = False

            wiki = self.params.get('wiki')
            if wiki and 'wikipedia.org' not in wiki:
                self.skip_action('restbase')

            self.get_restbase('/page/summary/', False, proxy, timeout)

            if show and not self.flags.get('silent'):
                self.show()

        return self
624643
def _parse_parameters(self, resource, params):
        '''
        '''
        # remove params from resource URI (needed for paginated stuff)
        parsed_uri = urlparse(resource)
        qs = parsed_uri.query
        resource = urlunparse(parsed_uri._replace(query=''))
        prms = {}
        for tup in parse_qsl(qs):
            prms[tup[0]] = tup[1]

        # params supplied to self.get() override parsed params
        for key in params:
            prms[key] = params[key]
        return resource, prms
387125
def _set_wikidata(self):
        
        self.data['labels'] = {}
        self.data['wikidata'] = {}

        data = self._load_response('wikidata')
        entities = data.get('entities')
        item = entities.get(next(iter(entities)))

        self.data['wikidata_pageid'] = item.get('pageid')

        aliases = item.get('aliases')
        if aliases:
            aliases = [x['value'] for x in aliases[self.params['lang']]]
            self.data['aliases'] = aliases

        modified = item.get('modified')
        try:
            self.data['modified'].update({'wikidata': modified})
        except KeyError:
            self.data['modified'] = {'wikidata': modified}

        wikibase = item.get('id')
        if wikibase:
            self.data['wikibase'] = wikibase
            self.data['wikidata_url'] = utils.wikidata_url(wikibase)

        self.data['description'] = self._get_entity_prop(item, 'descriptions')
        self.data['label'] = self._get_entity_prop(item, 'labels')

        self._marshal_claims(item.get('claims'))
        self._set_title(item)
918545
def _get(self, *args, **kwargs):
        """"""
        prev_data = kwargs.pop('prev_data', [])
        resp = self._request('get', *args, **kwargs)
        resp_content = resp._content
        if not resp_content:
            # No content so its obviously not paginated
            return resp

        # if resp._content is a bytes object, decode it so we can loads it as json
        if isinstance(resp_content, bytes):
            resp_content = resp_content.decode('utf-8')

        # Load the json so we can use the data as python objects
        content = json.loads(resp_content)
        if 'pagination' not in content:
            # Result is not paginated
            return resp

        page_info = content['pagination']
        if not page_info['next_uri']:
            # next_uri is None when the cursor has been iterated to the last element
            content['data'].extend(prev_data)
            # If resp._content was is a bytes object, only set it as a bytes object
            if isinstance(resp_content, bytes):
                resp._content = json.dumps(content).decode('utf-8')
            else:
                resp._content = json.dumps(content)
            return resp

        prev_data.extend(content['data'])
        next_page_id = page_info['next_uri'].split('=')[-1]
        kwargs.update({
            'prev_data': prev_data,
            'params': {'starting_after': next_page_id}
        })
        return self._get(*args, **kwargs)
985315
def rest(url, req="GET", data=None):
    
    load_variables()

    return _rest(base_url + url, req, data)
452222
def requests_url(self, ptype, **data):
        
        options = {
            'type': ptype,
            'pt': '3.1',
            'channel': self._channel_id,
            'pb': '320',
            'from': 'mainsite',
            'r': '',
            'kbps': '320',
            'app_name': 'radio_website',
            'client': 's:mainsite|y:3.0',
            'version': '100'
        }
        if 'sid' in data:
            options['sid'] = data['sid']
        url = 'https://douban.fm/j/v2/playlist'
        while True:
            try:
                s = requests.get(url, params=options,
                                 cookies=self._cookies, headers=HEADERS)
                req_json = s.json()
                if req_json['r'] == 0:
                    if 'song' not in req_json or not req_json['song']:
                        break
                    return req_json['song'][0]
            except Exception as err:
                raise APIError(err)
                break
        return None
1190851
def query(self, query, **kwargs):
        
        params = {'q': query}
        response = requests.get(self._get_norm_query_url(),
                                headers=self._get_rest_headers(),
                                params=params,
                                **kwargs)
        if response.status_code != requests.codes.ok:
            raise Exception(response.content)

        return response.json()
485209
protected function parseRequest()
    {
        if ($this->customParams === false) {
            // pull various supported inputs from post
            $request = $this->di->get('request');

            // only process if it is a get
            if ($request->isGet() == false) {
                return;
            }
        } else {
            $_REQUEST = $_GET = $this->customParams;
            $request = $this->di->get('request');
        }

        // simple stuff first
        $with = $request->get('with', "string", null);
        $include = $request->get('include', "string", null);
        if (!is_null($with)) {
            $this->suppliedWith = $with;
        } elseif (!is_null($include)) {
            $this->suppliedWith = $include;
        }

        // load possible sort values in the following order
        // be sure to mark this as a paginated result set
        if ($request->get('sort', "string", null) != null) {
            $this->suppliedSort = $request->get('sort', "string", null);
            $this->isPager = true;
        } elseif ($request->get('sort_field', "string", null) != null) {
            $this->suppliedSort = $request->get('sort_field', "string", null);
            $this->isPager = true;
        } elseif ($request->get('sortField', "string", null) != null) {
            $this->suppliedSort = $request->get('sortField', "string", null);
            $this->isPager = true;
        }

        // prep for the harder stuff
        // ?page=1&perPage=25&orderAscending=false

        // load possible limit values in the following order
        // be sure to mark this as a paginated result set
        if ($request->get('limit', "string", null) != null) {
            $this->suppliedLimit = $request->get('limit', "string", null);
            $this->isPager = true;
        } elseif ($request->get('per_page', "string", null) != null) {
            $this->suppliedLimit = $request->get('per_page', "string", null);
            $this->isPager = true;
        } elseif ($request->get('perPage', "string", null) != null) {
            $this->suppliedLimit = $request->get('perPage', "string", null);
            $this->isPager = true;
        }

        // look for string that means to show all records
        if ($this->isPager) {
            if ($this->suppliedLimit == 'all') {
                $this->suppliedLimit = 9999999999;
            }
        }

        // load offset values in the following order
        // Notice that a page is treated differently than offset
        // $this->offset = ($offset != null) ? $offset : $this->offset;
        if ($request->get('offset', "int", null) != null) {
            $this->suppliedOffset = $request->get('offset', "int", null);
            $this->isPager = true;
        } elseif ($request->get('page', "int", null) != null) {
            $this->suppliedOffset = ($request->get('page', "int", null) - 1) * $this->suppliedLimit;
            $this->isPager = true;
        }

        // Check if we pass the count parameter with whatever value
        if ($request->has('count')) {
            $this->isCount = true;
        }

        // http://jsonapi.org/format/#fetching
        $this->parseSearchParameters($request);
    }
704400
def getQueryParams(url):
    """"""
    query = urlsplit(url)[3]
    out.debug(u'Extracting query parameters from %r (%r)...' % (url, query))
    return cgi.parse_qs(query)
144601
def _paged_api_call(self, func, kwargs, item_type='photo'):
        
        page = 1
        while True:
            LOG.info("Fetching page %s" % page)
            kwargs['page'] = page
            rsp = self._load_rsp(func(**kwargs))
            if rsp["stat"] == "ok":
                plural = item_type + 's'
                if plural in rsp:
                    items = rsp[plural]
                    if int(items["page"]) < page:
                        LOG.info("End of Flickr pages (%s pages with %s per page)" % (items["pages"], items["perpage"]))
                        break
                    for i in items[item_type]:
                        yield self._prep(i)
                else:
                    yield rsp
                page += 1
            else:
                yield [rsp]
                break
716712
def parse(self, title, pageid=None):
        
        qry = self.PARSE.substitute(
            WIKI=self.uri,
            ENDPOINT=self.endpoint,
            PAGE=safequote(title) or pageid)

        if pageid and not title:
            qry = qry.replace('&page=', '&pageid=').replace('&redirects', '')

        if self.variant:
            qry += '&variant=' + self.variant

        self.set_status('parse', pageid or title)

        return qry
1188926
function getQueries(req, end) {
  var urlencoded = /^application\/x-www-form-urlencoded/;
  var multipart = /^multipart\/form-data/;
  var contentType = req.headers['content-type'] || '';

  if (multipart.test(contentType)) {
    // Multipart data.
    req.form = req.form || new formidable.IncomingForm();
    req.form.multiples = true;
    req.form.parse(req, function(err, fields, files) {
      req.fields = fields;
      req.files = files;
      // Ensure that files are arrays.
      for (var key in req.files) {
        if (!(req.files[key] instanceof Array)) {
          req.files[key] = [req.files[key]];
        }
      }
      if (err == null) {
        addToQuery(req, req.fields);
        addToQuery(req, req.files);
      }
      end(err);
    });

  } else if (urlencoded.test(contentType)) {
    // URL encoded data.
    var chunks;
    var gotrequest = function (chunk) {
      if (chunk !== undefined) {
        if (chunks === undefined) {
          chunks = chunk;
        } else {
          chunks = Buffer.concat([chunks, chunk]);
        }
      }
    };
    req.on('data', gotrequest);
    req.on('end', function(err) {
      if (req.server.saveRequestChunks) {
        req.savedChunks = chunks;
      }
      var strquery = chunks? chunks.toString(): '';
      jsonFromQuery(strquery, req.query);
      end(err);
    });
  } else {
    // URL query parameters.
    var search = req.uri.search || '';
    jsonFromQuery(search.slice(1), req.query);
    end();
  }
}
516889
def get_encoded_query_params(self):
        """"""
        get_data = encode_items(self.request.GET.lists())
        return urlencode(get_data)
848132
def html(self):
        
        if self._html is False:
            self._html = None
            query_params = {
                "prop": "revisions",
                "rvprop": "content",
                "rvlimit": 1,
                "rvparse": "",
                "titles": self.title,
            }
            request = self.mediawiki.wiki_request(query_params)
            page = request["query"]["pages"][self.pageid]
            self._html = page["revisions"][0]["*"]
        return self._html
142524
def search(query, results=10, suggestion=False):
  '''
  
  '''

  search_params = {
    'list': 'search',
    'srprop': '',
    'srlimit': results,
    'limit': results,
    'srsearch': query
  }
  if suggestion:
    search_params['srinfo'] = 'suggestion'

  raw_results = _wiki_request(search_params)

  if 'error' in raw_results:
    if raw_results['error']['info'] in ('HTTP request timed out.', 'Pool queue is full'):
      raise HTTPTimeoutError(query)
    else:
      raise WikipediaException(raw_results['error']['info'])

  search_results = (d['title'] for d in raw_results['query']['search'])

  if suggestion:
    if raw_results['query'].get('searchinfo'):
      return list(search_results), raw_results['query']['searchinfo']['suggestion']
    else:
      return list(search_results), None

  return list(search_results)
875926
def display_queries(request, stats, queries):
    
    sort = request.REQUEST.get('sort_by', 'time')
    sort_buttons = RadioButtons('sort_by', sort, (
        ('order', 'by order'), ('time', 'time'), ('queries', 'query count')
    ))
    output = render_queries(queries, sort)
    output.reset()
    output = [html.escape(unicode(line)) for line in output.readlines()]
    response = HttpResponse(mimetype='text/html; charset=utf-8')
    response.content = (queries_template % {
        'sort_buttons': sort_buttons,
        'num_queries': len(queries),
        'queries': "".join(output),
        'rawqueries' : b64encode(cPickle.dumps(queries)),
        'rawstats': b64encode(pickle_stats(stats)),
        'url': request.path
    })
    return response
1257455
function() {
		var api_url,
			api_language,
			self = this;

		// Create Dom element
		this._el.content_item	= TL.Dom.create("div", "tl-media-item tl-media-wikipedia", this._el.content);
		this._el.content_container.className = "tl-media-content-container tl-media-content-container-text";

		// Get Media ID
		this.media_id	 = this.data.url.split("wiki\/")[1].split("#")[0].replace("_", " ");
		this.media_id	 = this.media_id.replace(" ", "%20");
		api_language	 = this.data.url.split("//")[1].split(".wikipedia")[0];

		// API URL
		api_url = "https://" + api_language + ".wikipedia.org/w/api.php?action=query&prop=extracts|pageimages&redirects=&titles=" + this.media_id + "&exintro=1&format=json&callback=?";

		// API Call
		TL.ajax({
			type: 'GET',
			url: api_url,
			dataType: 'json', //json data type

			success: function(d){
				self.createMedia(d);
			},
			error:function(xhr, type){
				var error_text = "";
				error_text += self._("wikipedia_load_err") + "<br/>" + self.media_id + "<br/>" + type;
				self.loadErrorDisplay(error_text);
			}
		});

	}