Index: /pkpgcounter/trunk/pkpgpdls/pdlparser.py
===================================================================
--- /pkpgcounter/trunk/pkpgpdls/pdlparser.py (revision 492)
+++ /pkpgcounter/trunk/pkpgpdls/pdlparser.py (revision 493)
@@ -43,11 +43,10 @@
     totiffcommands = None        # Default command to convert to TIFF
     openmode = "rb"              # Default file opening mode
-    def __init__(self, filename, debug=0) :
+    def __init__(self, filename, firstblock, lastblock, debug=0) :
         """Initialize the generic parser."""
         self.filename = filename
         self.debug = debug
         self.infile = None
-        (self.firstblock, self.lastblock) = self.readBlocks()
-        self.infile = open(self.filename, self.openmode)
+        (self.firstblock, self.lastblock) = (firstblock, lastblock)
         if not self.isValid() :
             raise PDLParserError, "Invalid file format !"
@@ -61,4 +60,6 @@
             # parsing will greatly benefit from this.
             psyco.bind(self.getJobSize)
+        self.infile = open(self.filename, self.openmode)
+        # self.logdebug("Opened %s in '%s' mode." % (self.filename, self.openmode))
             
     def __del__(self) :
@@ -66,18 +67,4 @@
         if self.infile :
             self.infile.close()
-            
-    def readBlocks(self) :        
-        """Reads first and last block of the input file."""
-        infile = open(self.filename, "rb")
-        try :
-            firstblock = infile.read(FIRSTBLOCKSIZE)
-            try :
-                infile.seek(-LASTBLOCKSIZE, 2)
-                lastblock = infile.read(LASTBLOCKSIZE)
-            except IOError :    
-                lastblock = ""
-        finally :        
-            infile.close()
-        return (firstblock, lastblock)    
             
     def logdebug(self, message) :       
Index: /pkpgcounter/trunk/pkpgpdls/plain.py
===================================================================
--- /pkpgcounter/trunk/pkpgpdls/plain.py (revision 492)
+++ /pkpgcounter/trunk/pkpgpdls/plain.py (revision 493)
@@ -38,4 +38,6 @@
            read the first line, and if it doesn't end in CR or LF
            we consider it's not plain text.
+           
+           TODO : use first and last block's content instead of readline().
         """   
         line = self.infile.readline()
Index: /pkpgcounter/trunk/pkpgpdls/spl1.py
===================================================================
--- /pkpgcounter/trunk/pkpgpdls/spl1.py (revision 491)
+++ /pkpgcounter/trunk/pkpgpdls/spl1.py (revision 493)
@@ -100,5 +100,5 @@
         self.escapedStuff = {}   # For escaped datas, mostly PJL commands
         self.bigEndian()
-        
+        codesop = chr(0x06) + chr(0x00) + chr(0x00) + chr(0x80) + chr(0x13) + chr(0x40)
         self.isbitmap = False
         pos = 0
@@ -114,6 +114,5 @@
                         offset = unpack(self.unpackLong, minfile[pos:pos+4])[0]
                         sequencenum = unpack(self.unpackShort, minfile[pos+4:pos+6])[0]
-                        codesop = " ".join([ "%02x" % ord(v) for v in minfile[pos+6:pos+12]])
-                        if codesop != "06 00 00 80 13 40" :
+                        if minfile[pos+6:pos+12] != codesop :
                             raise pdlparser.PDLParserError, "Unfortunately SPL1 is incompletely recognized. Parsing aborted. Please report the problem to %s" % version.__authoremail__
                         if not sequencenum :
Index: /pkpgcounter/trunk/pkpgpdls/analyzer.py
===================================================================
--- /pkpgcounter/trunk/pkpgpdls/analyzer.py (revision 492)
+++ /pkpgcounter/trunk/pkpgpdls/analyzer.py (revision 493)
@@ -136,4 +136,14 @@
         if not os.stat(self.filename).st_size :
             raise pdlparser.PDLParserError, "input file %s is empty !" % str(self.filename)
+        
+        # Now read first and last block of the input file
+        # to be able to detect the real file format and the parser to use.
+        firstblock = self.workfile.read(pdlparser.FIRSTBLOCKSIZE)
+        try :
+            self.workfile.seek(-pdlparser.LASTBLOCKSIZE, 2)
+            lastblock = self.workfile.read(pdlparser.LASTBLOCKSIZE)
+        except IOError :    
+            lastblock = ""
+            
         # IMPORTANT : the order is important below. FIXME.
         for module in (postscript, \
@@ -153,5 +163,7 @@
                        plain) :     # IMPORTANT : don't move this one up !
             try :               
-                return module.Parser(self.filename, self.options.debug)
+                return module.Parser(self.filename, firstblock,
+                                                    lastblock,
+                                                    self.options.debug)
             except pdlparser.PDLParserError :
                 pass # try next parser
