Example #1
0
 def _get_path(self, parsed):
     path = force_str(parsed[2])
     # If there are parameters, add them
     if parsed[3]:
         path += str(";") + force_str(parsed[3])
     path = unquote(path)
     # WSGI requires latin-1 encoded strings. See get_path_info().
     if six.PY3:
         path = path.encode('utf-8').decode('iso-8859-1')
     return path
Example #2
0
def urlencode(query, doseq=0):
    """
    A version of Python's urllib.urlencode() function that can operate on
    unicode strings. The parameters are first cast to UTF-8 encoded strings and
    then encoded as per normal.
    """
    if hasattr(query, 'items'):
        query = query.items()

    return original_urlencode(
        [(force_str(k),
         [force_str(i) for i in v] if isinstance(v, (list,tuple)) else force_str(v))
            for k, v in query],
        doseq)
Example #3
0
 def load(self, rawdata):
     self.bad_cookies = set()
     if six.PY2 and isinstance(rawdata, six.text_type):
         rawdata = force_str(rawdata)
     super(SimpleCookie, self).load(rawdata)
     for key in self.bad_cookies:
         del self[key]
Example #4
0
 def _BaseCookie__set(self, key, real_value, coded_value):
     key = force_str(key)
     try:
         M = self.get(key, Morsel())
         M.set(key, real_value, coded_value)
         dict.__setitem__(self, key, M)
     except http_cookies.CookieError:
         self.bad_cookies.add(key)
         dict.__setitem__(self, key, http_cookies.Morsel())
Example #5
0
    def get(self, path, data={}, **extra):
        "Construct a GET request."

        path = self.__fill_query_string(path)
        parsed = urlparse(path)

        query_string = urlencode(data, doseq=True) or force_str(parsed[4])
        if urlencode(data, doseq=True):
            query_string = force_str(parsed[4]) + '&' +query_string
        if six.PY3:
            query_string = query_string.encode('utf-8').decode('iso-8859-1')

        r = {
            'PATH_INFO':       self._get_path(parsed),
            'QUERY_STRING':    query_string,
            'REQUEST_METHOD':  str('GET'),
        }
        r.update(extra)
        return self.request(**r)
Example #6
0
    def post(self, path, data={}, content_type=MULTIPART_CONTENT, **extra):
        "Construct a POST request."

        path = self.__fill_query_string(path)
        #data['__nocache'] = 1
        post_data = self._encode_data(data, content_type)

        parsed = urlparse(path)
        query_string = force_str(parsed[4])
        if six.PY3:
            query_string = query_string.encode('utf-8').decode('iso-8859-1')

        r = {
            'CONTENT_LENGTH': len(post_data),
            'CONTENT_TYPE': content_type,
            'PATH_INFO': self._get_path(parsed),
            'QUERY_STRING': query_string,
            'REQUEST_METHOD': str('POST'),
            'wsgi.input': FakePayload(post_data),
        }
        r.update(extra)
        return self.request(**r)