(value, safe="%&=-_", convall=False, limit=False, spaceplus=False)
return result
URL encodes given value

    >>> urlencode('AND 1>(2+3)#')
    'AND%201%3E%282%2B3%29%23'
URL encodes given value
URL encodes given value
def urlencode(value, safe="%&=-_", convall=False, limit=False, spaceplus=False):
    """
    URL encodes given value

    >>> urlencode('AND 1>(2+3)#')
    'AND%201%3E%282%2B3%29%23'
    """

    if conf.get("direct"):
        return value

    count = 0
    result = None if value is None else ""

    if value:
        if Backend.isDbms(DBMS.MSSQL) and not kb.tamperFunctions and any(ord(_) > 255 for _ in value):
            warnMsg = "if you experience problems with "
            warnMsg += "non-ASCII identifier names "
            warnMsg += "you are advised to rerun with '--tamper=charunicodeencode'"
            singleTimeWarnMessage(warnMsg)

        if convall or safe is None:
            safe = ""

        # corner case when character % really needs to be
        # encoded (when not representing URL encoded char)
        # except in cases when tampering scripts are used
        if all(map(lambda x: '%' in x, [safe, value])) and not kb.tamperFunctions:
            value = re.sub("%(?![0-9a-fA-F]{2})", "%25", value)

        while True:
            result = urllib.quote(utf8encode(value), safe)

            if limit and len(result) > URLENCODE_CHAR_LIMIT:
                if count >= len(URLENCODE_FAILSAFE_CHARS):
                    break

                while count < len(URLENCODE_FAILSAFE_CHARS):
                    safe += URLENCODE_FAILSAFE_CHARS[count]
                    count += 1
                    if safe[-1] in value:
                        break
            else:
                break

        if spaceplus:
            result = result.replace(urllib.quote(' '), '+')

    return result
def urlencode ( value , safe = "%&=-_" , convall = False , limit = False , spaceplus = False ) : if conf . get ( "direct" ) : return value count = 0 result = None if value is None else "" if value : if Backend . isDbms ( DBMS . MSSQL ) and not kb . tamperFunctions and any ( ord ( _ ) > 255 for _ in value ) : warnMsg = "if you experience problems with " warnMsg += "non-ASCII identifier names " warnMsg += "you are advised to rerun with '--tamper=charunicodeencode'" singleTimeWarnMessage ( warnMsg ) if convall or safe is None : safe = "" # corner case when character % really needs to be # encoded (when not representing URL encoded char) # except in cases when tampering scripts are used if all ( map ( lambda x : '%' in x , [ safe , value ] ) ) and not kb . tamperFunctions : value = re . sub ( "%(?![0-9a-fA-F]{2})" , "%25" , value ) while True : result = urllib . quote ( utf8encode ( value ) , safe ) if limit and len ( result ) > URLENCODE_CHAR_LIMIT : if count >= len ( URLENCODE_FAILSAFE_CHARS ) : break while count < len ( URLENCODE_FAILSAFE_CHARS ) : safe += URLENCODE_FAILSAFE_CHARS [ count ] count += 1 if safe [ - 1 ] in value : break else : break if spaceplus : result = result . replace ( urllib . quote ( ' ' ) , '+' ) return result