Files
mayan-edms/mayan/apps/common/http.py
Roberto Rosario 52ad3e7418 Update the URL class to work with Python 3
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
2019-07-26 23:23:18 -04:00

39 lines
907 B
Python

from __future__ import unicode_literals
from django.http import QueryDict
from django.utils.encoding import force_bytes
from django.utils.six import PY3
class URL(object):
def __init__(self, path=None, query_string=None):
self._path = path
self._query_string = query_string
kwargs = {'mutable': True}
if query_string:
kwargs['query_string'] = query_string.encode('utf-8')
self._args = QueryDict(**kwargs)
@property
def args(self):
return self._args
def to_string(self):
if self._args.keys():
query = '?{}'.format(self._args.urlencode())
else:
query = ''
if self._path:
path = self._path
else:
path = ''
result = '{}{}'.format(path, query)
if PY3:
return result
else:
return force_bytes(result)