Show
Ignore:
Timestamp:
11/20/07 00:04:09 (17 years ago)
Author:
jerome
Message:

Major code cleaning. Now clearer, although probably a bit slower since
a file can be opened several times.
Now universal line opening mode is only used when needed (PS, PDF and plain
text), and binary opening mode is used for the other formats.
This mean we will be able to remove mmap calls wherever possible, finally.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/plain.py

    r463 r491  
    2323"""This modules implements a page counter for plain text documents.""" 
    2424 
    25 import sys 
    26 import os 
    27  
    2825import pdlparser 
    2926import version 
    30  
    3127 
    3228class Parser(pdlparser.PDLParser) : 
     
    3531                       'a2ps --borders 0 --quiet --portrait --no-header --columns 1 --output - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -', 
    3632                     ]   
     33    openmode = "rU"                  
    3734    def isValid(self) :     
    3835        """Returns True if data is plain text, else False. 
     
    5754        linecount = 0 
    5855        for line in self.infile : 
    59             if line.endswith("\n") or line.endswith("\r") : 
     56            if line.endswith("\n") : 
    6057                linecount += 1     
    6158                if (linecount > pagesize) : 
     
    7067                raise pdlparser.PDLParserError, "Unsupported file format. Please send the file to %s" % version.__authoremail__ 
    7168        return pagecount + 1    # NB : empty files are catched in isValid() 
    72          
    73 if __name__ == "__main__" :     
    74     pdlparser.test(Parser)