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