Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8625763

Browse files
committed
Minor code refactoring
1 parent abc3c24 commit 8625763

1 file changed

Lines changed: 4 additions & 31 deletions

File tree

lib/core/common.py

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ def goGoodSamaritan(prevValue, originalCharset):
12671267
# outputs defined
12681268
if kb.partRun in kb.commonOutputs:
12691269
commonPartOutputs = kb.commonOutputs[kb.partRun]
1270-
commonPattern = common_finder_only(prevValue, commonPartOutputs)
1270+
commonPattern = commonFinderOnly(prevValue, commonPartOutputs)
12711271

12721272
# If the longest common prefix is the same as previous value then
12731273
# do not consider it
@@ -1351,33 +1351,6 @@ def getPartRun():
13511351
# Return the INI tag to consider for common outputs (e.g. 'Databases')
13521352
return commonPartsDict[retVal][1] if retVal in commonPartsDict else retVal
13531353

1354-
def getCommonStart(strings=[]):
1355-
"""
1356-
Returns common start of given strings
1357-
"""
1358-
if not strings or not isinstance(strings, list):
1359-
return None
1360-
1361-
if len(strings) == 1:
1362-
return strings[0]
1363-
1364-
retVal = unicode()
1365-
maxCount = min(len(string) for string in strings)
1366-
1367-
count = 0
1368-
while count < maxCount:
1369-
char = strings[0][count]
1370-
for i in xrange(1, len(strings)):
1371-
if char != strings[i][count]:
1372-
char = None
1373-
break
1374-
if char is None:
1375-
break
1376-
retVal += char
1377-
count += 1
1378-
1379-
return retVal
1380-
13811354
def getUnicode(value):
13821355
if isinstance(value, basestring):
13831356
return value if isinstance(value, unicode) else unicode(value, conf.dataEncoding if 'dataEncoding' in conf else "utf-8")
@@ -1417,7 +1390,7 @@ def write(self, fp):
14171390
fp.write("\n")
14181391

14191392
# http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2
1420-
def longest_common_prefix(*sequences):
1393+
def longestCommonPrefix(*sequences):
14211394
if len(sequences) == 1:
14221395
return sequences[0]
14231396

@@ -1435,5 +1408,5 @@ def longest_common_prefix(*sequences):
14351408

14361409
return sequences[0]
14371410

1438-
def common_finder_only(initial, sequence):
1439-
return longest_common_prefix(*filter(lambda x: x.startswith(initial), sequence))
1411+
def commonFinderOnly(initial, sequence):
1412+
return longestCommonPrefix(*filter(lambda x: x.startswith(initial), sequence))

0 commit comments

Comments
 (0)