Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/slimkrazy/python-goo…
Browse files Browse the repository at this point in the history
…gle-places into development
  • Loading branch information
slimkrazy committed Jan 8, 2017
2 parents 85442cb + 80bcb0d commit 0771b87
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions googleplaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def __get__(self, instance, cls=None):
return result


def _fetch_remote(service_url, params={}, use_http_post=False):
def _fetch_remote(service_url, params=None, use_http_post=False):
if not params:
params = {}

encoded_data = {}
for k, v in params.items():
if isinstance(v, six.string_types):
Expand All @@ -67,19 +70,25 @@ def _fetch_remote(service_url, params={}, use_http_post=False):
request = urllib.request.Request(service_url, data=encoded_data)
return (request_url, urllib.request.urlopen(request))

def _fetch_remote_json(service_url, params={}, use_http_post=False):
def _fetch_remote_json(service_url, params=None, use_http_post=False):
"""Retrieves a JSON object from a URL."""
if not params:
params = {}

request_url, response = _fetch_remote(service_url, params, use_http_post)
if six.PY3:
str_response = response.read().decode('utf-8')
return (request_url, json.loads(str_response, parse_float=Decimal))
return (request_url, json.load(response, parse_float=Decimal))

def _fetch_remote_file(service_url, params={}, use_http_post=False):
def _fetch_remote_file(service_url, params=None, use_http_post=False):
"""Retrieves a file from a URL.
Returns a tuple (mimetype, filename, data)
"""
if not params:
params = {}

request_url, response = _fetch_remote(service_url, params, use_http_post)
dummy, params = cgi.parse_header(
response.headers.get('Content-Disposition', ''))
Expand Down

0 comments on commit 0771b87

Please sign in to comment.