Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Merge 76cec7f into cb8261d
Browse files Browse the repository at this point in the history
  • Loading branch information
thefourtheye committed Jan 28, 2014
2 parents cb8261d + 76cec7f commit ee06d7f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions paypalrestsdk/util.py
@@ -1,26 +1,34 @@
import re

try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode


# Join given url
# == Example
# api.join_url("example.com", "index.html") # Return "example.com/index.html"
def join_url(url, *paths):
"""
Joins individual URL strings together, and returns a single string.
>>> util.join_url("example.com", "index.html")
'example.com/index.html'
"""
for path in paths:
url = re.sub(r'/?$', re.sub(r'^/?', '/', path), url)
return url


def join_url_params(url, params):
return url + "?" + urlencode(params)


# Merge dict
def merge_dict(data, *override):
dict_list = list(data.items())
for value in override:
dict_list = dict_list + list(value.items())
return dict(dict_list)
"""
Merges any number of dictionaries together, and returns a single dictionary
>>> util.merge_dict ({"foo": "bar"}, {1: 2}, {"Pay": "Pal"})
{1: 2, 'foo': 'bar', 'Pay': 'Pal'}
>>>
"""
result = {}
for current_dict in (data,) + override:
result.update(current_dict)
return result

0 comments on commit ee06d7f

Please sign in to comment.