@@ -1402,6 +1402,7 @@ def posixToNtSlashes(filepath):
1402
1402
"""
1403
1403
Replaces all occurances of Posix slashes (/) in provided
1404
1404
filepath with NT ones (/)
1405
+
1405
1406
>>> posixToNtSlashes('C:/Windows')
1406
1407
'C:\\ \\ Windows'
1407
1408
"""
@@ -1412,6 +1413,7 @@ def ntToPosixSlashes(filepath):
1412
1413
"""
1413
1414
Replaces all occurances of NT slashes (\) in provided
1414
1415
filepath with Posix ones (/)
1416
+
1415
1417
>>> ntToPosixSlashes('C:\\ Windows')
1416
1418
'C:/Windows'
1417
1419
"""
@@ -1421,6 +1423,7 @@ def ntToPosixSlashes(filepath):
1421
1423
def isBase64EncodedString (subject ):
1422
1424
"""
1423
1425
Checks if the provided string is Base64 encoded
1426
+
1424
1427
>>> isBase64EncodedString('dGVzdA==')
1425
1428
True
1426
1429
>>> isBase64EncodedString('123456')
@@ -1432,6 +1435,7 @@ def isBase64EncodedString(subject):
1432
1435
def isHexEncodedString (subject ):
1433
1436
"""
1434
1437
Checks if the provided string is hex encoded
1438
+
1435
1439
>>> isHexEncodedString('DEADBEEF')
1436
1440
True
1437
1441
>>> isHexEncodedString('test')
@@ -1667,6 +1671,7 @@ def getCompiledRegex(regex, flags=0):
1667
1671
"""
1668
1672
Returns compiled regular expression and stores it in cache for further
1669
1673
usage
1674
+
1670
1675
>>> getCompiledRegex('test') # doctest: +ELLIPSIS
1671
1676
<_sre.SRE_Pattern object at...
1672
1677
"""
@@ -2374,6 +2379,7 @@ def maskSensitiveData(msg):
2374
2379
def listToStrValue (value ):
2375
2380
"""
2376
2381
Flattens list to a string value
2382
+
2377
2383
>>> listToStrValue([1,2,3])
2378
2384
'1, 2, 3'
2379
2385
"""
@@ -2408,6 +2414,7 @@ def intersect(valueA, valueB):
2408
2414
"""
2409
2415
Returns intersection of the array-ized values
2410
2416
"""
2417
+
2411
2418
retVal = None
2412
2419
2413
2420
if valueA and valueB :
@@ -2419,6 +2426,7 @@ def cpuThrottle(value):
2419
2426
"""
2420
2427
Does a CPU throttling for a lesser CPU consumption
2421
2428
"""
2429
+
2422
2430
delay = 0.00001 * (value ** 2 )
2423
2431
time .sleep (delay )
2424
2432
@@ -2451,6 +2459,7 @@ def normalizeUnicode(value):
2451
2459
Does an ASCII normalization of unicode strings
2452
2460
Reference: http://www.peterbe.com/plog/unicode-to-ascii
2453
2461
"""
2462
+
2454
2463
retVal = value
2455
2464
if isinstance (value , unicode ):
2456
2465
retVal = unicodedata .normalize ('NFKD' , value ).encode ('ascii' ,'ignore' )
@@ -2460,6 +2469,7 @@ def safeSQLIdentificatorNaming(name, isTable=False):
2460
2469
"""
2461
2470
Returns a safe representation of SQL identificator name
2462
2471
"""
2472
+
2463
2473
retVal = name
2464
2474
if isinstance (name , basestring ):
2465
2475
if isTable and Backend .getIdentifiedDbms () in (DBMS .MSSQL , DBMS .SYBASE ) and '.' not in name :
@@ -2480,6 +2490,7 @@ def unsafeSQLIdentificatorNaming(name):
2480
2490
"""
2481
2491
Extracts identificator's name from it's safe SQL representation
2482
2492
"""
2493
+
2483
2494
retVal = name
2484
2495
if isinstance (name , basestring ):
2485
2496
if Backend .getIdentifiedDbms () in (DBMS .MYSQL , DBMS .ACCESS ):
@@ -2489,3 +2500,28 @@ def unsafeSQLIdentificatorNaming(name):
2489
2500
if Backend .getIdentifiedDbms () in (DBMS .MSSQL , DBMS .SYBASE ):
2490
2501
retVal = retVal .lstrip ("%s." % DEFAULT_MSSQL_SCHEMA )
2491
2502
return retVal
2503
+
2504
+ def isBinaryData (value ):
2505
+ """
2506
+ Tests given value for binary content
2507
+ """
2508
+
2509
+ retVal = False
2510
+ if isinstance (value , basestring ):
2511
+ retVal = reduce (lambda x , y : x or not (y in string .printable or ord (y ) > 255 ), value , False )
2512
+ return retVal
2513
+
2514
+ def getSafeHexEncodedBinaryData (value ):
2515
+ """
2516
+ Returns safe representation of given basestring value
2517
+
2518
+ >>> getSafeEncodedBinaryData(u'test123')
2519
+ u'test123'
2520
+ >>> getSafeEncodedBinaryData(u'test\01 \02 \03 ')
2521
+ u'test\\ 1\\ 2\\ 3'
2522
+ """
2523
+
2524
+ retVal = value
2525
+ if isinstance (value , basestring ):
2526
+ retVal = reduce (lambda x , y : x + (y if (y in string .printable or ord (y ) > 255 ) else '\%x' % ord (y )), value , unicode ())
2527
+ return retVal
0 commit comments