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

Skip to content

Commit 2cd8f31

Browse files
committed
some doc test samples included
1 parent 4edf6eb commit 2cd8f31

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

lib/core/common.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,15 +1106,41 @@ def isWindowsDriveLetterPath(filepath):
11061106
return re.search("\A[\w]\:", filepath) is not None
11071107

11081108
def posixToNtSlashes(filepath):
1109+
"""
1110+
Replaces all occurances of Posix slashes (/) in provided
1111+
filepath with NT ones (/)
1112+
>>> posixToNtSlashes('C:/Windows')
1113+
'C:\\\\Windows'
1114+
"""
11091115
return filepath.replace('/', '\\')
11101116

11111117
def ntToPosixSlashes(filepath):
1118+
"""
1119+
Replaces all occurances of NT slashes (\) in provided
1120+
filepath with Posix ones (/)
1121+
>>> ntToPosixSlashes('C:\\Windows')
1122+
'C:/Windows'
1123+
"""
11121124
return filepath.replace('\\', '/')
11131125

11141126
def isBase64EncodedString(subject):
1127+
"""
1128+
Checks if the provided string is Base64 encoded
1129+
>>> isBase64EncodedString('dGVzdA==')
1130+
True
1131+
>>> isBase64EncodedString('123456')
1132+
False
1133+
"""
11151134
return re.match(r"\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\Z", subject) is not None
11161135

11171136
def isHexEncodedString(subject):
1137+
"""
1138+
Checks if the provided string is hex encoded
1139+
>>> isHexEncodedString('DEADBEEF')
1140+
True
1141+
>>> isHexEncodedString('test')
1142+
False
1143+
"""
11181144
return re.match(r"\A[0-9a-fA-F]+\Z", subject) is not None
11191145

11201146
def profile(profileOutputFile=None, dotOutputFile=None, imageOutputFile=None):
@@ -1217,6 +1243,10 @@ def parseXmlFile(xmlFile, handler):
12171243
xfile.close()
12181244

12191245
def calculateDeltaSeconds(start, epsilon=0.05):
1246+
"""
1247+
Returns elapsed time from start till now (including expected
1248+
error set by epsilon parameter)
1249+
"""
12201250
return int(time.time() - start + epsilon)
12211251

12221252
def initCommonOutputs():
@@ -1316,6 +1346,8 @@ def getCompiledRegex(regex, *args):
13161346
"""
13171347
Returns compiled regular expression and stores it in cache for further
13181348
usage
1349+
>>> getCompiledRegex('test') # doctest: +ELLIPSIS
1350+
<_sre.SRE_Pattern object at...
13191351
"""
13201352

13211353
if (regex, args) in kb.cache.regex:

0 commit comments

Comments
 (0)