def test_valid_unicode_preserved(self):
        q = '/?q=%E6%9F%A5%E8%AF%A2'
        new_key = 'page'
        new_value = 2
        value = '%E6%9F%A5%E8%AF%A2'

        assert new_key in replace_query_param(q, new_key, new_value)
        assert value in replace_query_param(q, new_key, new_value)
    def test_valid_unicode_replaced(self):
        q = '/?page=1'
        value = '1'
        new_key = 'q'
        new_value = '%E6%9F%A5%E8%AF%A2'

        assert new_key in replace_query_param(q, new_key, new_value)
        assert value in replace_query_param(q, new_key, new_value)
    def get_next_link(self):
        if self.offset + self.limit >= self.count:
            return None

        url = self.request.build_absolute_uri()
        url = replace_query_param(url, self.limit_query_param, self.limit)

        offset = self.offset + self.limit
        return replace_query_param(url, self.offset_query_param, offset)
    def get_previous_link(self):
        if self.offset <= 0:
            return None

        url = self.request.build_absolute_uri()
        url = replace_query_param(url, self.limit_query_param, self.limit)

        if self.offset - self.limit <= 0:
            return remove_query_param(url, self.offset_query_param)

        offset = self.offset - self.limit
        return replace_query_param(url, self.offset_query_param, offset)
 def page_number_to_url(page_number):
     if page_number == 1:
         return remove_query_param(base_url, self.offset_query_param)
     else:
         offset = self.offset + ((page_number - current) * self.limit)
         return replace_query_param(base_url, self.offset_query_param,
                                    offset)
    def test_invalid_unicode(self):
        # Encoded string: '��<script>alert(313)</script>=1'
        q = '/e/?%FF%FE%3C%73%63%72%69%70%74%3E%61%6C%65%72%74%28%33%31%33%29%3C%2F%73%63%72%69%70%74%3E=1'
        key = 'from'
        value = 'login'

        assert key in replace_query_param(q, key, value)
def add_query_param(request, key, val):
    """
    Add a query parameter to the current request url, and return the new url.
    """
    iri = request.get_full_path()
    uri = iri_to_uri(iri)
    return escape(replace_query_param(uri, key, val))
 def get_previous_link(self):
     if not self.page.has_previous():
         return None
     url = self.request.build_absolute_uri()
     page_number = self.page.previous_page_number()
     if page_number == 1:
         return remove_query_param(url, self.page_query_param)
     return replace_query_param(url, self.page_query_param, page_number)
    def encode_cursor(self, cursor):
        """
        Given a Cursor instance, return an url with encoded cursor.
        """
        tokens = {}
        if cursor.offset != 0:
            tokens['o'] = str(cursor.offset)
        if cursor.reverse:
            tokens['r'] = '1'
        if cursor.position is not None:
            tokens['p'] = cursor.position

        querystring = urlparse.urlencode(tokens, doseq=True)
        encoded = b64encode(querystring.encode('ascii')).decode('ascii')
        return replace_query_param(self.base_url, self.cursor_query_param,
                                   encoded)
Example #10
0
def preserve_builtin_query_params(url, request=None):
    """
    Given an incoming request, and an outgoing URL representation,
    append the value of any built-in query parameters.
    """
    if request is None:
        return url

    overrides = [
        api_settings.URL_FORMAT_OVERRIDE,
    ]

    for param in overrides:
        if param and (param in request.GET):
            value = request.GET[param]
            url = replace_query_param(url, param, value)

    return url
 def page_number_to_url(page_number):
     if page_number == 1:
         return remove_query_param(base_url, self.page_query_param)
     else:
         return replace_query_param(base_url, self.page_query_param,
                                    page_number)
 def get_next_link(self):
     if not self.page.has_next():
         return None
     url = self.request.build_absolute_uri()
     page_number = self.page.next_page_number()
     return replace_query_param(url, self.page_query_param, page_number)