Skip to content
Snippets Groups Projects
Commit 15e4451d authored by Dan Nicholson's avatar Dan Nicholson
Browse files

Use urlencode to construct query parameters

Including the `?` and `&` in the templates is awkward. Instead, use a
dictionary with just the parameter names and use `urlencode` to
construct the query string. This also has the advantage that any values
will be properly HTML encoded.

https://phabricator.endlessm.com/T29306
parent 556e5027
Branches
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import argparse
from collections import namedtuple
from subprocess import Popen, PIPE
from urllib import urlencode
from urllib2 import urlopen
import json
from urlparse import urlparse
......@@ -15,8 +16,9 @@ WHITELIST=[]
BLACKLIST=[]
LISTINGS_PER_PAGE = 100
ACCESS_TOKEN_PARAM = '?access_token=%s'
LISTING_PAGE_PARAM = '&per_page=%d&page=%d'
ACCESS_TOKEN_PARAM = 'access_token'
LISTINGS_PER_PAGE_PARAM = 'per_page'
LISTING_PAGE_PARAM = 'page'
GITHUB_API_HOST = 'https://api.github.com'
GIT_CLONE_CMD = 'git clone %s %s %s'
......@@ -73,7 +75,12 @@ class AttributeDict(dict):
self[attr] = value
def read_api_uri(uri, config, page=1):
uri += ACCESS_TOKEN_PARAM % config.token + LISTING_PAGE_PARAM % (LISTINGS_PER_PAGE, page)
params = {
ACCESS_TOKEN_PARAM: config.token,
LISTINGS_PER_PAGE_PARAM: LISTINGS_PER_PAGE,
LISTING_PAGE_PARAM: page,
}
uri += '?' + urlencode(params)
if config.debug:
print "Trying:", uri
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment