Comment 1 for bug 1040913

Revision history for this message
Curtis Hovey (sinzui) wrote :

This is the hack in my script to allow me to use this method:
# Every normal man must be tempted at times to spit on his hands,
# hoist the black flag, and begin to slit throats.
def safe_build_url(self, param_values=None, **kw_param_values):
    """Return the request URL to use to invoke this method.

    The unsafe method raises an error for
    lp.load('/+services/sharing')
    because the wadl resource.uri it gets a URI instead of a str.
    """
    try:
        from urllib.parse import urlencode
        urlencode
    except ImportError:
        from urllib import urlencode
    validated_values = self.validate_param_values(
        self.query_params, param_values, **kw_param_values)
    url = str(self.resource.url)
    if len(validated_values) > 0:
        if '?' in url:
            append = '&'
        else:
            append = '?'
        url += append + urlencode(validated_values)
    return url