rcldoc.py: port to python3. We by default exec antiword directly anyway
This commit is contained in:
parent
b8fa3005dd
commit
7f49de5d97
@ -85,28 +85,28 @@ class WordFilter:
|
|||||||
self.em = em
|
self.em = em
|
||||||
self.ntry = 0
|
self.ntry = 0
|
||||||
self.execdir = td
|
self.execdir = td
|
||||||
|
self.rtfprolog = b'{\\rtf1'
|
||||||
|
self.docprolog = b'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1'
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.ntry = 0
|
self.ntry = 0
|
||||||
|
|
||||||
def hasControlChars(self, data):
|
def hasControlChars(self, data):
|
||||||
for c in data:
|
for c in data:
|
||||||
if c < chr(32) and c != '\n' and c != '\t' and \
|
if c < b' '[0] and c != b'\n'[0] and c != b'\t'[0] and \
|
||||||
c != '\f' and c != '\r':
|
c != b'\f'[0] and c != b'\r'[0]:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def mimetype(self, fn):
|
def mimetype(self, fn):
|
||||||
rtfprolog = b'{\\rtf1'
|
|
||||||
docprolog = b'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1'
|
|
||||||
try:
|
try:
|
||||||
f = open(fn, "rb")
|
f = open(fn, "rb")
|
||||||
except:
|
except:
|
||||||
return ""
|
return ""
|
||||||
data = f.read(100)
|
data = f.read(100)
|
||||||
if data[0:6] == rtfprolog:
|
if data[0:6] == self.rtfprolog:
|
||||||
return "text/rtf"
|
return "text/rtf"
|
||||||
elif data[0:8] == docprolog:
|
elif data[0:8] == self.docprolog:
|
||||||
return "application/msword"
|
return "application/msword"
|
||||||
elif self.hasControlChars(data):
|
elif self.hasControlChars(data):
|
||||||
return "application/octet-stream"
|
return "application/octet-stream"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user