dont use 0-sized doc to mean eof now

This commit is contained in:
dockes
2009-11-13 08:15:19 +00:00
parent 451041e7db
commit ebd10680f8
6 changed files with 60 additions and 33 deletions
+8 -5
View File
@@ -91,17 +91,20 @@ class rclCHM:
"""Extract one path-named internal file from the chm file"""
#self.em.rclog("extractone: [%s]"%(path))
eof = (self.currentindex >= len(self.tp.contents) -1)
iseof = rclexecm.RclExecM.noteof
if self.currentindex >= len(self.tp.contents) -1:
iseof = rclexecm.RclExecM.eofnext
res, ui = self.chm.ResolveObject(path)
#self.em.rclog("extract: ResolveO: %d [%s]" % (res, ui))
if res != chmlib.CHM_RESOLVE_SUCCESS:
return (False, "", path, eof)
return (False, "", path, iseof)
# RetrieveObject() returns len,value
res, doc = self.chm.RetrieveObject(ui)
#self.em.rclog("extract: RetrieveObject: %d [%s]" % (res, doc))
if res > 0:
return (True, doc, path, eof)
return (False, "", path, eof)
return (True, doc, path, iseof)
return (False, "", path, iseof)
def openfile(self, params):
"""Open the chm file and build the contents list by extracting and
@@ -128,7 +131,7 @@ class rclCHM:
def getnext(self, params):
if self.currentindex >= len(self.tp.contents):
return (False, "", "", 1)
return (False, "", "", rclexecm.RclExecM.eofnow)
else:
ret= self.extractone(self.tp.contents[self.currentindex])
self.currentindex += 1
+10 -3
View File
@@ -6,6 +6,10 @@ import sys
import os
class RclExecM:
noteof = 0
eofnext = 1
eofnow = 2
def __init__(self):
self.myname = os.path.basename(sys.argv[0])
self.mimetype = ""
@@ -45,7 +49,7 @@ class RclExecM:
return (paramname, paramdata)
# Send answer: document, ipath, possible eof.
def answer(self, docdata, ipath, iseof):
def answer(self, docdata, ipath, iseof = noteof):
print "Document:", len(docdata)
sys.stdout.write(docdata)
@@ -59,8 +63,11 @@ class RclExecM:
sys.stdout.write(self.mimetype)
# If we're at the end of the contents, say so
if iseof:
print "Eof: 0"
if iseof == self.eofnow:
print "Eofnow: 0"
elif iseof == self.eofnext:
print "Eofnext: 0"
# End of message
print
sys.stdout.flush()
+6 -3
View File
@@ -15,8 +15,11 @@ class IcalExtractor:
return(False, "", "", True)
docdata = self.contents[index].as_string()
#self.em.rclog(docdata)
eof = (self.currentindex >= len(self.contents) -1)
return (True, docdata, str(index), eof)
iseof = rclexecm.RclExecM.noteof
if self.currentindex >= len(self.contents) -1:
iseof = rclexecm.RclExecM.eofnext
return (True, docdata, str(index), iseof)
###### File type handler api, used by rclexecm ---------->
def openfile(self, params):
@@ -40,7 +43,7 @@ class IcalExtractor:
def getnext(self, params):
if self.currentindex >= len(self.contents):
#em.rclog("getnext: EOF hit")
return (False, "", "", 1)
return (False, "", "", rclexecm.RclExecM.eofnow)
else:
ret= self.extractone(self.currentindex)
self.currentindex += 1
+6 -6
View File
@@ -95,7 +95,7 @@ sub imgTagsToHtml {
return $output;
}
# Get one line from stdin, exit on eof
# Get one line from stdin (from recollindex), exit on eof
sub readlineorexit {
my $s = <STDIN>;
unless ($s) {
@@ -131,7 +131,7 @@ sub readparam {
}
#
# Main program starts here
# Main program starts here. Talks the rclexecm protocol
#
# JFD: replaced the "use" call with a runtime load with error checking,
@@ -159,9 +159,9 @@ while (1) {
}
unless (defined $params{"filename:"}) {
print STDERR "RCLIMG: no filename ??\n";
# Recoll is requesting next subdocument, but we have none, just say
# so:
print "Document: 0\n\n";
# Recoll is requesting next subdocument (it shouldn't cause we
# returned eofnext last time), but we have none, just say so:
print "Eofnow:0\nDocument: 0\n\n";
next;
}
@@ -172,7 +172,7 @@ while (1) {
# print STDERR "RCLIMG: writing $l bytes of data\n";
print $data;
# Say we have no further documents for this file
print "Eof: 0\n";
print "Eofnext: 0\n";
# End of output parameters: print empty line
print "\n";
# print STDERR "RCLIMG: done writing data\n";
+5 -3
View File
@@ -22,8 +22,10 @@ class ZipExtractor:
except error, err:
self.em.rclog("extractone: failed: [%s]" % err)
ok = False
eof = (self.currentindex >= len(self.zip.namelist()) -1)
return (ok, docdata, ipath, eof)
iseof = rclexecm.RclExecM.noteof
if self.currentindex >= len(self.zip.namelist()) -1:
iseof = rclexecm.RclExecM.eofnext
return (ok, docdata, ipath, iseof)
###### File type handler api, used by rclexecm ---------->
def openfile(self, params):
@@ -40,7 +42,7 @@ class ZipExtractor:
def getnext(self, params):
if self.currentindex >= len(self.zip.namelist()):
#self.em.rclog("getnext: EOF hit")
return (False, "", "", 1)
return (False, "", "", rclexecm.RclExecM.eofnow)
else:
ret= self.extractone(self.zip.namelist()[self.currentindex])
self.currentindex += 1