diff --git a/extra/keepalive/keepalive.py b/extra/keepalive/keepalive.py index bb032ebc1..66141389a 100644 --- a/extra/keepalive/keepalive.py +++ b/extra/keepalive/keepalive.py @@ -71,7 +71,7 @@ EXTRA ATTRIBUTES AND METHODS """ from httplib import _CS_REQ_STARTED, _CS_REQ_SENT, _CS_IDLE, CannotSendHeader -from lib.core.common import encodeUnicode +from lib.core.convert import unicodeencode from lib.core.data import kb import threading @@ -336,7 +336,7 @@ class HTTPConnection(httplib.HTTPConnection): self._send_output() def send(self, str): - httplib.HTTPConnection.send(self, encodeUnicode(str, kb.pageEncoding)) + httplib.HTTPConnection.send(self, unicodeencode(str, kb.pageEncoding)) ######################################################################### ##### TEST FUNCTIONS diff --git a/lib/core/common.py b/lib/core/common.py index 10f056325..937576031 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1799,22 +1799,6 @@ def getUnicode(value, encoding=None, system=False): except: return getUnicode(value, UNICODE_ENCODING) -def encodeUnicode(value, encoding=None): - """ - Return 8-bit string representation of the supplied unicode value: - - >>> encodeUnicode(u'test') - 'test' - """ - - retVal = value - if isinstance(value, unicode): - try: - retVal = value.encode(encoding or UNICODE_ENCODING) - except UnicodeEncodeError: - retVal = value.encode(UNICODE_ENCODING, errors="replace") - return retVal - # http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2 def longestCommonPrefix(*sequences): if len(sequences) == 1: diff --git a/lib/core/convert.py b/lib/core/convert.py index 5bede6455..7cb1b9204 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -124,8 +124,24 @@ def urlencode(value, safe="%&=", convall=False, limit=False): return result +def unicodeencode(value, encoding=None): + """ + Return 8-bit string representation of the supplied unicode value: + + >>> unicodeencode(u'test') + 'test' + """ + + retVal = value + if isinstance(value, unicode): + try: + retVal = value.encode(encoding or UNICODE_ENCODING) + except UnicodeEncodeError: + retVal = value.encode(UNICODE_ENCODING, errors="replace") + return retVal + def utf8encode(value): - return value.encode("utf-8") + return unicodeencode(value, "utf-8") def utf8decode(value): return value.decode("utf-8") diff --git a/lib/request/connect.py b/lib/request/connect.py index a7b7f3ca0..fd79b854e 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -21,7 +21,6 @@ from lib.core.common import average from lib.core.common import calculateDeltaSeconds from lib.core.common import clearConsoleLine from lib.core.common import cpuThrottle -from lib.core.common import encodeUnicode from lib.core.common import extractRegexResult from lib.core.common import getCurrentThreadData from lib.core.common import getFilteredPageContent @@ -31,9 +30,10 @@ from lib.core.common import parseTargetUrl from lib.core.common import readInput from lib.core.common import removeReflectiveValues from lib.core.common import stdev -from lib.core.common import wasLastRequestDelayed -from lib.core.convert import urlencode from lib.core.common import urlEncodeCookieValues +from lib.core.common import wasLastRequestDelayed +from lib.core.convert import unicodeencode +from lib.core.convert import urlencode from lib.core.data import conf from lib.core.data import kb from lib.core.data import logger @@ -176,9 +176,9 @@ class Connect: for key, item in headers.items(): del headers[key] - headers[encodeUnicode(key, kb.pageEncoding)] = encodeUnicode(item, kb.pageEncoding) + headers[unicodeencode(key, kb.pageEncoding)] = unicodeencode(item, kb.pageEncoding) - post = encodeUnicode(post, kb.pageEncoding) + post = unicodeencode(post, kb.pageEncoding) if method: req = MethodRequest(url, post, headers)