|
52 | 52 | from lib.core.convert import base64pickle |
53 | 53 | from lib.core.convert import base64unpickle |
54 | 54 | from lib.core.convert import htmlunescape |
| 55 | +from lib.core.convert import stdoutencode |
55 | 56 | from lib.core.convert import unicodeencode |
56 | | -from lib.core.convert import urldecode |
57 | | -from lib.core.convert import urlencode |
| 57 | +from lib.core.convert import utf8encode |
58 | 58 | from lib.core.decorators import cachedmethod |
59 | 59 | from lib.core.enums import CHARSET_TYPE |
60 | 60 | from lib.core.enums import DBMS |
|
125 | 125 | from lib.core.settings import TEXT_TAG_REGEX |
126 | 126 | from lib.core.settings import UNION_UNIQUE_FIFO_LENGTH |
127 | 127 | from lib.core.settings import URI_QUESTION_MARKER |
| 128 | +from lib.core.settings import URLENCODE_CHAR_LIMIT |
| 129 | +from lib.core.settings import URLENCODE_FAILSAFE_CHARS |
128 | 130 | from lib.core.threads import getCurrentThreadData |
129 | 131 | from thirdparty.clientform.clientform import ParseResponse |
130 | 132 | from thirdparty.clientform.clientform import ParseError |
@@ -721,29 +723,10 @@ def dataToStdout(data, forceOutput=False, bold=False): |
721 | 723 |
|
722 | 724 | if not kb.get("threadException"): |
723 | 725 | if forceOutput or not getCurrentThreadData().disableStdOut: |
724 | | - try: |
725 | | - if kb.get("multiThreadMode"): |
726 | | - logging._acquireLock() |
727 | | - # Reference: http://bugs.python.org/issue1602 |
728 | | - if IS_WIN: |
729 | | - output = data.encode('ascii', "replace") |
730 | | - |
731 | | - if output != data: |
732 | | - warnMsg = "cannot properly display Unicode characters " |
733 | | - warnMsg += "inside Windows OS command prompt " |
734 | | - warnMsg += "(http://bugs.python.org/issue1602). All " |
735 | | - warnMsg += "unhandled occurances will result in " |
736 | | - warnMsg += "replacement with '?' character. Please, find " |
737 | | - warnMsg += "proper character representation inside " |
738 | | - warnMsg += "corresponding output files. " |
739 | | - singleTimeWarnMessage(warnMsg) |
740 | | - |
741 | | - message = output |
742 | | - else: |
743 | | - message = data.encode(sys.stdout.encoding) |
744 | | - except: |
745 | | - message = data.encode(UNICODE_ENCODING) |
| 726 | + if kb.get("multiThreadMode"): |
| 727 | + logging._acquireLock() |
746 | 728 |
|
| 729 | + message = stdoutencode(data) |
747 | 730 | sys.stdout.write(setColor(message, bold)) |
748 | 731 | sys.stdout.flush() |
749 | 732 |
|
@@ -2010,6 +1993,57 @@ def extractErrorMessage(page): |
2010 | 1993 |
|
2011 | 1994 | return retVal |
2012 | 1995 |
|
| 1996 | +def urldecode(value, encoding=None): |
| 1997 | + result = None |
| 1998 | + |
| 1999 | + if value: |
| 2000 | + try: |
| 2001 | + # for cases like T%C3%BCrk%C3%A7e |
| 2002 | + value = str(value) |
| 2003 | + except ValueError: |
| 2004 | + pass |
| 2005 | + finally: |
| 2006 | + result = urllib.unquote_plus(value) |
| 2007 | + |
| 2008 | + if isinstance(result, str): |
| 2009 | + result = unicode(result, encoding or UNICODE_ENCODING, "replace") |
| 2010 | + |
| 2011 | + return result |
| 2012 | + |
| 2013 | +def urlencode(value, safe="%&=", convall=False, limit=False): |
| 2014 | + if conf.direct or PLACE.SOAP in conf.paramDict: |
| 2015 | + return value |
| 2016 | + |
| 2017 | + count = 0 |
| 2018 | + result = None if value is None else "" |
| 2019 | + |
| 2020 | + if value: |
| 2021 | + if convall or safe is None: |
| 2022 | + safe = "" |
| 2023 | + |
| 2024 | + # corner case when character % really needs to be |
| 2025 | + # encoded (when not representing url encoded char) |
| 2026 | + # except in cases when tampering scripts are used |
| 2027 | + if all(map(lambda x: '%' in x, [safe, value])) and not kb.tamperFunctions: |
| 2028 | + value = re.sub("%(?![0-9a-fA-F]{2})", "%25", value) |
| 2029 | + |
| 2030 | + while True: |
| 2031 | + result = urllib.quote(utf8encode(value), safe) |
| 2032 | + |
| 2033 | + if limit and len(result) > URLENCODE_CHAR_LIMIT: |
| 2034 | + if count >= len(URLENCODE_FAILSAFE_CHARS): |
| 2035 | + break |
| 2036 | + |
| 2037 | + while count < len(URLENCODE_FAILSAFE_CHARS): |
| 2038 | + safe += URLENCODE_FAILSAFE_CHARS[count] |
| 2039 | + count += 1 |
| 2040 | + if safe[-1] in value: |
| 2041 | + break |
| 2042 | + else: |
| 2043 | + break |
| 2044 | + |
| 2045 | + return result |
| 2046 | + |
2013 | 2047 | def beep(): |
2014 | 2048 | """ |
2015 | 2049 | Does an audible beep sound |
@@ -2094,11 +2128,7 @@ def logHTTPTraffic(requestLogMsg, responseLogMsg): |
2094 | 2128 | dataToTrafficFile("%s%s" % (responseLogMsg, os.linesep)) |
2095 | 2129 | dataToTrafficFile("%s%s%s%s" % (os.linesep, 76 * '#', os.linesep, os.linesep)) |
2096 | 2130 |
|
2097 | | -def getPageTemplate(payload, place): |
2098 | | - """ |
2099 | | - Cross-linked method |
2100 | | - """ |
2101 | | - |
| 2131 | +def getPageTemplate(payload, place): # Cross-linked function |
2102 | 2132 | pass |
2103 | 2133 |
|
2104 | 2134 | def getPublicTypeMembers(type_, onlyValues=False): |
|
0 commit comments