minor refactoring

This commit is contained in:
Miroslav Stampar 2011-04-29 15:22:32 +00:00
parent a2bb0d72e8
commit 6bb4dce3aa
4 changed files with 24 additions and 24 deletions

View File

@ -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

View File

@ -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:

View File

@ -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")

View File

@ -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)