@@ -1635,7 +1635,7 @@ def expandAsteriskForColumns(expression):
16351635 if expression != conf .sqlQuery :
16361636 conf .db = db
16371637 else :
1638- expression = re .sub (r"([^\w])%s" % re .escape (conf .tbl ), "\g<1>%s.%s" % (conf .db , conf .tbl ), expression )
1638+ expression = re .sub (r"([^\w])%s" % re .escape (conf .tbl ), r "\g<1>%s.%s" % (conf .db , conf .tbl ), expression )
16391639 else :
16401640 conf .db = db
16411641
@@ -1795,12 +1795,24 @@ def getFileType(filePath):
17951795
17961796 >>> getFileType(__file__)
17971797 'text'
1798+ >>> getFileType(sys.executable)
1799+ 'binary'
17981800 """
17991801
18001802 try :
18011803 desc = getUnicode (magic .from_file (filePath ) or "" )
18021804 except :
1803- return "unknown"
1805+ desc = magic .MAGIC_UNKNOWN_FILETYPE
1806+
1807+ if desc == magic .MAGIC_UNKNOWN_FILETYPE :
1808+ content = openFile (filePath , "rb" , encoding = None ).read ()
1809+
1810+ try :
1811+ content .decode ()
1812+ except :
1813+ pass
1814+ else :
1815+ desc = "ascii"
18041816
18051817 return "text" if any (_ in desc .lower () for _ in ("ascii" , "text" )) else "binary"
18061818
@@ -2053,8 +2065,8 @@ def isWindowsDriveLetterPath(filepath):
20532065
20542066def posixToNtSlashes (filepath ):
20552067 """
2056- Replaces all occurrences of Posix slashes (/) in provided
2057- filepath with NT ones (\)
2068+ Replaces all occurrences of Posix slashes in provided
2069+ filepath with NT backslashes
20582070
20592071 >>> posixToNtSlashes('C:/Windows')
20602072 'C:\\ \\ Windows'
@@ -2064,8 +2076,8 @@ def posixToNtSlashes(filepath):
20642076
20652077def ntToPosixSlashes (filepath ):
20662078 """
2067- Replaces all occurrences of NT slashes (\) in provided
2068- filepath with Posix ones (/)
2079+ Replaces all occurrences of NT backslashes in provided
2080+ filepath with Posix slashes
20692081
20702082 >>> ntToPosixSlashes('C:\\ Windows')
20712083 'C:/Windows'
@@ -2954,7 +2966,7 @@ def findDynamicContent(firstPage, secondPage):
29542966 infoMsg = "searching for dynamic content"
29552967 singleTimeLogMessage (infoMsg )
29562968
2957- blocks = SequenceMatcher (None , firstPage , secondPage ).get_matching_blocks ()
2969+ blocks = list ( SequenceMatcher (None , firstPage , secondPage ).get_matching_blocks () )
29582970 kb .dynamicMarkings = []
29592971
29602972 # Removing too small matching blocks
@@ -4654,8 +4666,8 @@ def decloakToTemp(filename):
46544666
46554667 content = decloak (filename )
46564668
4657- parts = getBytes ( os .path .split (filename [:- 1 ])[- 1 ]) .split (b '.' )
4658- prefix , suffix = parts [0 ], b".%s" % parts [- 1 ]
4669+ parts = os .path .split (filename [:- 1 ])[- 1 ].split ('.' )
4670+ prefix , suffix = parts [0 ], '.' + parts [- 1 ]
46594671 handle , filename = tempfile .mkstemp (prefix = prefix , suffix = suffix )
46604672 os .close (handle )
46614673
@@ -4692,7 +4704,7 @@ def getRequestHeader(request, name):
46924704
46934705 if request and request .headers and name :
46944706 _ = name .upper ()
4695- retVal = max (value if _ == key .upper () else type ( value )( ) for key , value in request .header_items ()) or None
4707+ retVal = max (getBytes ( value if _ == key .upper () else "" ) for key , value in request .header_items ()) or None
46964708
46974709 return retVal
46984710
0 commit comments