django-cas-server/cas_server/utils.py

22 lines
854 B
Python
Raw Normal View History

2015-05-27 20:10:06 +00:00
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
# more details.
#
# You should have received a copy of the GNU General Public License version 3
# along with this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# (c) 2015 Valentin Samir
2015-05-27 19:56:39 +00:00
"""Some util function for the app"""
2015-05-16 21:43:46 +00:00
import urlparse
import urllib
def update_url(url, params):
2015-05-27 19:56:39 +00:00
"""update params in the `url` query string"""
2015-05-16 21:48:04 +00:00
url_parts = list(urlparse.urlparse(url))
2015-05-16 21:43:46 +00:00
query = dict(urlparse.parse_qsl(url_parts[4]))
query.update(params)
url_parts[4] = urllib.urlencode(query)
return urlparse.urlunparse(url_parts)