@@ -161,9 +161,7 @@ def write(self, fp):
161161class Format :
162162 @staticmethod
163163 def humanize (values , chain = " or " ):
164- strJoin = "|" .join (v for v in values )
165-
166- return strJoin .replace ("|" , chain )
164+ return chain .join (values )
167165
168166 # Get methods
169167 @staticmethod
@@ -179,10 +177,7 @@ def getDbms(versions=None):
179177 if versions is None and Backend .getVersionList ():
180178 versions = Backend .getVersionList ()
181179
182- if versions is None :
183- return Backend .getDbms ()
184- else :
185- return "%s %s" % (Backend .getDbms (), " and " .join (v for v in versions ))
180+ return Backend .getDbms () if versions is None else "%s %s" % (Backend .getDbms (), " and " .join (v for v in versions ))
186181
187182 @staticmethod
188183 def getErrorParsedDBMSes ():
@@ -195,14 +190,14 @@ def getErrorParsedDBMSes():
195190 @rtype: C{str}
196191 """
197192
198- htmlParsed = ""
193+ htmlParsed = None
199194
200195 if len (kb .htmlFp ) == 0 or kb .heuristicTest is None :
201- return None
196+ pass
202197 elif len (kb .htmlFp ) == 1 :
203198 htmlParsed = kb .htmlFp [0 ]
204199 elif len (kb .htmlFp ) > 1 :
205- htmlParsed = " or " .join (htmlFp for htmlFp in kb .htmlFp )
200+ htmlParsed = " or " .join (kb .htmlFp )
206201
207202 return htmlParsed
208203
@@ -378,7 +373,6 @@ def setArch():
378373
379374 if isinstance (_ , basestring ) and _ .isdigit () and int (_ ) in (1 , 2 ):
380375 kb .arch = 32 if int (_ ) == 1 else 64
381-
382376 break
383377 else :
384378 warnMsg = "invalid value. Valid values are 1 and 2"
@@ -458,7 +452,6 @@ def getOsServicePack():
458452 def getArch ():
459453 if kb .arch is None :
460454 Backend .setArch ()
461-
462455 return kb .arch
463456
464457 # Comparison methods
@@ -773,36 +766,16 @@ def dataToOutFile(data):
773766
774767 return rFilePath
775768
776- def strToHex (inpStr ):
769+ def strToHex (value ):
777770 """
778- @param inpStr: inpStr to be converted into its hexadecimal value.
779- @type inpStr: C{str}
780-
781- @return: the hexadecimal converted inpStr.
782- @rtype: C{str}
771+ Converts string value to it's hexadecimal representation
783772 """
784773
785- hexStr = ""
786-
787- for character in inpStr :
788- if character == "\n " :
789- character = " "
790-
791- hexChar = "%2x" % ord (character )
792- hexChar = hexChar .replace (" " , "0" )
793- hexChar = hexChar .upper ()
794-
795- hexStr += hexChar
796-
797- return hexStr
774+ return (value if not isinstance (value , unicode ) else value .encode (UNICODE_ENCODING )).encode ("hex" ).upper ()
798775
799776def readInput (message , default = None , checkBatch = True ):
800777 """
801- @param message: message to display on terminal.
802- @type message: C{str}
803-
804- @return: a string read from keyboard as input.
805- @rtype: C{str}
778+ Reads input from terminal
806779 """
807780
808781 if "\n " in message :
@@ -839,36 +812,21 @@ def readInput(message, default=None, checkBatch=True):
839812
840813def randomRange (start = 0 , stop = 1000 ):
841814 """
842- @param start: starting number.
843- @type start: C{int}
844-
845- @param stop: last number.
846- @type stop: C{int}
847-
848- @return: a random number within the range.
849- @rtype: C{int}
815+ Returns random integer value in given range
850816 """
851817
852818 return int (random .randint (start , stop ))
853819
854820def randomInt (length = 4 ):
855821 """
856- @param length: length of the random string.
857- @type length: C{int}
858-
859- @return: a random string of digits.
860- @rtype: C{str}
822+ Returns random integer value with provided number of digits
861823 """
862824
863825 return int ("" .join (random .choice (string .digits if i != 0 else string .digits .replace ('0' , '' )) for i in xrange (0 , length )))
864826
865827def randomStr (length = 4 , lowercase = False , alphabet = None ):
866828 """
867- @param length: length of the random string.
868- @type length: C{int}
869-
870- @return: a random string of characters.
871- @rtype: C{str}
829+ Returns random string value with provided number of characters
872830 """
873831
874832 if alphabet :
@@ -882,20 +840,14 @@ def randomStr(length=4, lowercase=False, alphabet=None):
882840
883841def sanitizeStr (value ):
884842 """
885- @param value: value to sanitize: cast to str datatype and replace
886- newlines with one space and strip carriage returns.
887- @type value: C{str}
888-
889- @return: sanitized value
890- @rtype: C{str}
843+ Sanitizes string value in respect to newline and line-feed characters
891844 """
892845
893846 return getUnicode (value ).replace ("\n " , " " ).replace ("\r " , "" )
894847
895848def checkFile (filename ):
896849 """
897- @param filename: filename to check if it exists.
898- @type filename: C{str}
850+ Checks for file existence
899851 """
900852
901853 if not os .path .exists (filename ):
@@ -2997,6 +2949,7 @@ def geturl(self):
29972949 forms = None
29982950 retVal = set ()
29992951 response = _ (content , url )
2952+
30002953 try :
30012954 forms = ParseResponse (response , backwards_compat = False )
30022955 except ParseError :
0 commit comments